DragonFly BSD
DragonFly bugs List (threaded) for 2004-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: wrong uptime

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Dec 2004 12:19:18 -0800 (PST)

    Ok, I looked at it.  You are correct, the boottime specification broke.

    However, we cannot remove boottime... it is in fact NOT the same as
    basetime because basetime is actually compensated for clock drift
    relative to gd_time_seconds.  That is, we adjust basetime rather then
    gd_time_seconds in order to guarentee that gd_time_seconds doesn't jump

    When compensating for clock drift basetime is thus no longer an
    accurate boottime.

    However, for set_timeofday you are absolutely correct... the boottime
    global was not being properly set.  In this one case we do in fact have
    to revert that commit and make boottime.tv_sec be exactly
    basetime.tv_sec because basetime.tv_sec.  I will make the change.

					Matthew Dillon 

:I doubt they do -- I'm sure the 2x uptime is unintentional.  Here 
:is a quick fix, could someone please commit something like this?
:Index: kern_clock.c
:RCS file: /u01/cvs-repositories/dcvs/src/sys/kern/kern_clock.c,v
:retrieving revision 1.27
:diff -u -r1.27 kern_clock.c
:--- kern_clock.c	20 Nov 2004 20:25:09 -0000	1.27
:+++ kern_clock.c	4 Dec 2004 15:48:59 -0000
:@@ -227,7 +227,7 @@
:  	    basetime.tv_nsec += 1000000000;
:  	    --basetime.tv_sec;
:  	}
:-	boottime.tv_sec = basetime.tv_sec - mycpu->gd_time_seconds;
:+	boottime = basetime;
:  	timedelta = 0;
:  	crit_exit();
:  }
:As far as I can tell, both boottime/basetime serve the same purpose 
:and one of the should be removed because as it stands now, boottime 
:is only adjusted by set_timeofday().  Finer clock adjustments ala 
:adjtime() do not currently adjust boottime (which they should) 
:...that is probably a patch for another day.
:To see first hand your real uptime sliping away from you, here's a 
:short test program.  Getting 0 and 0 for both differences is what 
:you should be getting (well, 99.99% of the time :-)
:su-2.05b# cc -o x x.c
:su-2.05b# ./x
:Real time diff: 0
:boottime diff:  -262
:su-2.05b# cat x.c
:#include <sys/time.h>
:#include <sys/sysctl.h>
:#include <stdio.h>
:int main() {
: 	struct timeval tv1, tv2, b1, b2;
: 	int l = sizeof(tv1);
: 	sysctlbyname("kern.boottime", &b1, &l, NULL, 0);
: 	gettimeofday(&tv1, NULL);
: 	settimeofday(&tv1, NULL);	// <--- This slides boottime back
: 	gettimeofday(&tv2, NULL);
: 	sysctlbyname("kern.boottime", &b2, &l, NULL, 0);
: 	printf("Real time diff: %ld\n", tv2.tv_sec - tv1.tv_sec);
: 	printf("boottime diff:  %ld\n", b2.tv_sec - b1.tv_sec);
: 	return 0;

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]