summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2004-01-21 21:05:40 +0000
committerphk <phk@FreeBSD.org>2004-01-21 21:05:40 +0000
commit03ff7a46df1df3c490c904943043062d91cf06c2 (patch)
tree0679d11e95ab7ce6f3ff47926bd501c158204904 /sys/kern
parentfffc52fe7a3393e38603b6d028c721e38a1d1cc3 (diff)
downloadFreeBSD-src-03ff7a46df1df3c490c904943043062d91cf06c2.zip
FreeBSD-src-03ff7a46df1df3c490c904943043062d91cf06c2.tar.gz
Add a sysctl (default: off) which enables a log(LOG_INFO...) warning
if the clock is stepped.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_tc.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index accd372..15ad255 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,
+ &timestepwarnings, 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);
+ }
}
/*
OpenPOWER on IntegriCloud