From owner-svn-src-all@FreeBSD.ORG Mon Nov 22 09:13:25 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDF8A106567A; Mon, 22 Nov 2010 09:13:25 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BC7978FC0A; Mon, 22 Nov 2010 09:13:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAM9DPrV084459; Mon, 22 Nov 2010 09:13:25 GMT (envelope-from cperciva@svn.freebsd.org) Received: (from cperciva@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAM9DP3J084457; Mon, 22 Nov 2010 09:13:25 GMT (envelope-from cperciva@svn.freebsd.org) Message-Id: <201011220913.oAM9DP3J084457@svn.freebsd.org> From: Colin Percival Date: Mon, 22 Nov 2010 09:13:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r215665 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2010 09:13:25 -0000 Author: cperciva Date: Mon Nov 22 09:13:25 2010 New Revision: 215665 URL: http://svn.freebsd.org/changeset/base/215665 Log: 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... Modified: head/sys/kern/kern_tc.c Modified: head/sys/kern/kern_tc.c ============================================================================== --- head/sys/kern/kern_tc.c Mon Nov 22 09:06:59 2010 (r215664) +++ head/sys/kern/kern_tc.c Mon Nov 22 09:13:25 2010 (r215665) @@ -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); /*