From owner-freebsd-current@FreeBSD.ORG Sat Jul 24 22:38:53 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 700BE16A4F1; Sat, 24 Jul 2004 22:38:53 +0000 (GMT) Received: from harmony.village.org (rover.village.org [168.103.84.182]) by mx1.FreeBSD.org (Postfix) with ESMTP id CB88643D4C; Sat, 24 Jul 2004 22:38:52 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.11/8.12.11) with ESMTP id i6OMablP030219; Sat, 24 Jul 2004 16:36:37 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Sat, 24 Jul 2004 16:36:48 -0600 (MDT) Message-Id: <20040724.163648.23387896.imp@bsdimp.com> To: green@freebsd.org From: "M. Warner Losh" In-Reply-To: <20040721102620.GF1009@green.homeunix.org> References: <20040721081310.GJ22160@freebsd3.cimlogic.com.au> <20040721102620.GF1009@green.homeunix.org> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: current@freebsd.org Subject: Re: nanosleep returning early X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jul 2004 22:38:54 -0000 In message: <20040721102620.GF1009@green.homeunix.org> Brian Fundakowski Feldman writes: : On Wed, Jul 21, 2004 at 06:13:10PM +1000, John Birrell wrote: : > : > Today I increased HZ in a current kernel to 1000 when adding dummynet. : > Now I find that nanosleep regularly comes back a little early. : > Can anyone explain why? : > : > I would have expected that the *overrun* beyond the required time to vary, : > but never that it would come back early. : : Is this a difference from clock_gettime(CLOCK_MONOTONIC)? You really : shouldn't be using gettimeofday() foor internal timing since the : system clock can be adjusted by NTP. But the ntp adjustments tend to be in frequency only, and never in phase. ntp will step the clock on startup (usually several minutes after the system starts once it gets a good bead on the phase and frequency of its reference system/clock). Once it has stepped, however, it only steers the frequency of the system clock, which is then monotonic. settimeofday does also jump system time. Also, using CLOCK_MONOTONIC returns the uptime of the system. It can be hard to correlate this to a wall time. CLOCK_MONOTONIC is impacted by the frequency (but not phase) adjustements of ntp, but that's likely what you want. How early are things returning? If it is < 1us, then maybe you are running into resolution issues wrt gettimeofday. Warner