diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 2004-01-21 21:05:40 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2004-01-21 21:05:40 +0000 |
commit | 4e74721cac2f18b5b3a2c348dd34960adb44b0b2 (patch) | |
tree | 0679d11e95ab7ce6f3ff47926bd501c158204904 /sys/kern/kern_tc.c | |
parent | fb6b710c39b8bbefd730af2d2b8704bd646e0456 (diff) |
Add a sysctl (default: off) which enables a log(LOG_INFO...) warning
if the clock is stepped.
Notes
Notes:
svn path=/head/; revision=124812
Diffstat (limited to 'sys/kern/kern_tc.c')
-rw-r--r-- | sys/kern/kern_tc.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index accd37240d18..15ad2556ee8c 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -15,6 +15,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/kernel.h> #include <sys/sysctl.h> +#include <sys/syslog.h> #include <sys/systm.h> #include <sys/timepps.h> #include <sys/timetc.h> @@ -96,6 +97,10 @@ SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime, CTLFLAG_RD, SYSCTL_NODE(_kern, OID_AUTO, timecounter, CTLFLAG_RW, 0, ""); +static int timestepwarnings; +SYSCTL_INT(_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW, + ×tepwarnings, 0, ""); + #define TC_STATS(foo) \ static u_int foo; \ SYSCTL_UINT(_kern_timecounter, OID_AUTO, foo, CTLFLAG_RD, &foo, 0, "");\ @@ -334,26 +339,30 @@ tc_getfrequency(void) /* * Step our concept of UTC. This is done by modifying our estimate of - * when we booted. XXX: needs further work. + * when we booted. + * XXX: not locked. */ void tc_setclock(struct timespec *ts) { struct timespec ts2; + struct bintime bt, bt2; nsetclock++; - nanouptime(&ts2); - boottime.tv_sec = ts->tv_sec - ts2.tv_sec; - /* XXX boottime should probably be a timespec. */ - boottime.tv_usec = (ts->tv_nsec - ts2.tv_nsec) / 1000; - if (boottime.tv_usec < 0) { - boottime.tv_usec += 1000000; - boottime.tv_sec--; - } - timeval2bintime(&boottime, &boottimebin); + binuptime(&bt2); + timespec2bintime(ts, &bt); + bintime_sub(&bt, &bt2); + bintime_add(&bt2, &boottimebin); + boottimebin = bt; + bintime2timeval(&bt, &boottime); /* XXX fiddle all the little crinkly bits around the fiords... */ tc_windup(); + if (timestepwarnings) { + bintime2timespec(&bt2, &ts2); + log(LOG_INFO, "Time stepped from %d.%09ld to %d.%09ld\n", + ts2.tv_sec, ts2.tv_nsec, ts->tv_sec, ts->tv_nsec); + } } /* |