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: Paul Herman <pherman@xxxxxxxxxxxxxxx>
Date: Sat, 4 Dec 2004 08:21:01 -0800 (PST)

On Sat, 4 Dec 2004, YONETANI Tomokazu wrote:

I wonder, if you revert kern_clock.c:1.19 (i.e. set boottime =
basetime) do you still see your problem from April 2003?  I can't
seem to reproduce it at all.

I've confirmed that it doesn't. At lease uptime, ntpdate and ps are working correctly. I'm not 100% sure that this change affects other parts of the system that depend on this twisted boottime though.

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;
}


-Paul.




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