diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-06-14 19:52:08 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-06-14 19:52:08 +0000 |
commit | d0439941de3042e452a7a5bc85abf11fe39f4a37 (patch) | |
tree | d8919d89c5c5df74f7e929ea3fe5567c6a4e9be0 /sys/kern/kern_clock.c | |
parent | 02e62fcc998cebf05845bafdcff0dd705942e5c0 (diff) |
Introducing adjfreq(2), to adjust the clock frequency.
Loosely based on dragonfly code. ok deraadt@
Diffstat (limited to 'sys/kern/kern_clock.c')
-rw-r--r-- | sys/kern/kern_clock.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 482b349be91..30140b0688d 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.58 2006/01/20 07:53:48 tedu Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.59 2006/06/14 19:52:07 otto Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -222,6 +222,8 @@ hardclock(struct clockframe *frame) int delta; extern int tickdelta; extern long timedelta; + extern int64_t ntp_tick_permanent; + extern int64_t ntp_tick_acc; #endif #ifdef __HAVE_CPUINFO struct cpu_info *ci = curcpu(); @@ -287,6 +289,25 @@ hardclock(struct clockframe *frame) timedelta -= tickdelta; } + /* + * ntp_tick_permanent accumulates the clock correction each + * tick. The unit is ns per tick shifted left 32 bits. If we have + * accumulated more than 1us, we bump delta in the right + * direction. Use a loop to avoid long long div; typicallly + * the loops will be executed 0 or 1 iteration. + */ + if (ntp_tick_permanent != 0) { + ntp_tick_acc += ntp_tick_permanent; + while (ntp_tick_acc >= (1000LL << 32)) { + delta++; + ntp_tick_acc -= (1000LL << 32); + } + while (ntp_tick_acc <= -(1000LL << 32)) { + delta--; + ntp_tick_acc += (1000LL << 32); + } + } + BUMPTIME(&time, delta); BUMPTIME(&mono_time, delta); time_second = time.tv_sec; |