From aa519c0a64413adba86f8c917e1e59d66b60ebe8 Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Mon, 22 Nov 2010 09:13:25 +0000 Subject: [PATCH] In tc_windup, handle the case where the previous call to tc_windup was more than 1s earlier. Prior to this commit, the computation of th_scale * delta (which produces a 64-bit value equal to the time since the last tc_windup call in units of 2^(-64) seconds) would overflow and any complete seconds would be lost. We fix this by repeatedly converting tc_frequency units of timecounter to one seconds; this is not exactly correct, since it loses the NTP adjustment, but if we find ourselves going more than 1s at a time between clock interrupts, losing a few seconds worth of NTP adjustments is the least of our problems... --- sys/kern/kern_tc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 3e8d47067942..2487b6b5a9db 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -442,6 +442,16 @@ tc_windup(void) ncount = 0; th->th_offset_count += delta; th->th_offset_count &= th->th_counter->tc_counter_mask; + while (delta > th->th_counter->tc_frequency) { + /* Eat complete unadjusted seconds. */ + delta -= th->th_counter->tc_frequency; + th->th_offset.sec++; + } + if ((delta > th->th_counter->tc_frequency / 2) && + (th->th_scale * delta < (uint64_t)1 << 63)) { + /* The product th_scale * delta just barely overflows. */ + th->th_offset.sec++; + } bintime_addx(&th->th_offset, th->th_scale * delta); /*