Re: nanosleep returning early

From: M. Warner Losh <imp_at_bsdimp.com>
Date: Sat, 24 Jul 2004 16:36:48 -0600 (MDT)
In message: <20040721102620.GF1009_at_green.homeunix.org>
            Brian Fundakowski Feldman <green_at_freebsd.org> 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
Received on Sat Jul 24 2004 - 20:38:53 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:03 UTC