cvs commit: src/sys/kern

Paul Herman pherman at frenchfries.net
Sat Dec 4 17:23:20 PST 2004


On Sat, 4 Dec 2004, Matthew Dillon wrote:

 Log:
 Fix the boottime calculation when the time of day is set in absolute terms.
 We want boottime to be calculated based on the current real time minus our
 best uptime guess.  gd_time_seconds survives a lot of time issues and is our
 best uptime guess and since it is already used to calculate the new basetime,
 we can just assign boottime to basetime.
On an additional note -- and I suppose anything at this point is 
nitpicking -- would it be worthwhile to preserve the original 
drift?  Take an extreme example with the current code with a 
machine booted at 12:00:00 when the clock adds a second every 30 
seconds compared to a reference clock:

        basetime = 11:59:58
        boottime = 12:00:00
  reference time = 12:01:00
 gd_time_seconds = 62
    nanouptime() = 00:01:02
wallclock uptime = 00:01:00
     w(1) uptime = 00:01:00
Now, reset time on the reference clock (and machine) forward 1 
minute to 12:02:00

        basetime = 12:00:58
        boottime = 12:00:58
  reference time = 12:02:00
 gd_time_seconds = 62
    nanouptime() = 00:01:02
wallclock uptime = 00:01:00
     w(1) uptime = 00:01:02
So (if I got the logic all right) the w(1) uptime reported would be 
wrong.  If we could add the original 2 second difference between 
boottime & basetime back to boottime, I think things should be 
better.

Thoughts?  Am I getting too anal?  :-)
-Paul.
void
set_timeofday(struct timespec *ts)
{
        struct timespec ts2, drift;
        /*
         * XXX SMP / non-atomic basetime updates
         */
        crit_enter();
	drift.tv_sec = boottime.tv_sec - basetime.tv_sec;
	drift.tv_nsec = boottime.tv_nsec - basetime.tv_nsec;
        nanouptime(&ts2);
        basetime.tv_sec = ts->tv_sec - ts2.tv_sec;
        basetime.tv_nsec = ts->tv_nsec - ts2.tv_nsec;
        if (basetime.tv_nsec < 0) {
            basetime.tv_nsec += 1000000000;
            --basetime.tv_sec;
        }
        boottime.tv_sec = basetime.tv_sec + drift.tv_sec;
        boottime.tv_nsec = basetime.tv_nsec + drift.tv_nsec;
        timedelta = 0;
        crit_exit();
}






More information about the Commits mailing list