Subject: port-i386/14100: i386 retrograde time
To: None <gnats-bugs@gnats.netbsd.org>
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
List: netbsd-bugs
Date: 09/29/2001 13:57:49
>Number: 14100
>Category: port-i386
>Synopsis: i386 retrograde time
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-i386-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Sep 29 13:58:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Wolfgang Rupprecht
>Release: NetBSD-current 2001-09-17
>Organization:
W S Rupprecht Computer Consulting, Fremont CA
>Environment:
System: NetBSD capsicum.wsrcc.com 1.5Y NetBSD 1.5Y (WSRCC_ATHLON) #38: Mon Sep 17 20:36:07 PDT 2001 wolfgang@capsicum.wsrcc.com:/v/src/netbsd/src/sys/arch/i386/compile/WSRCC_ATHLON i386
Architecture: i386
Machine: i386
>Description:
Time runs backwards occationally. Observed on an ASUS A7V w.
Athlon-1.1Ghz
>How-To-Repeat:
run two gettimeofday()'s back-to-back and compare the results.
On the above machine approx. 7 times out of 10,000 time will
go backwards by approx. 10ms.
The actual results depend seem to depend heavily on astrology
and the conjunction of the planets. During some times test
runs of 10,000 loops produce no errors, during other times
every 10k test run produces 5-10 errors.
Three such errors are copied here. The "retrotrograde" line
is the unix times of the first and send calls to gettimeofday.
The "tsc" line is the cycle count before the first call and
after the second call. The error line is the extimated total
error minus delta-gettimeofday-time minus
delta-cycle-counter-time .
retrograde: 1.00179575520528197289e+09 -> 1.00179575520283603668e+09 (-2.44593620300292968750e-03)
tsc: 14978154325409 -> 14978162715973 (8390564 tics, 7.55992766176267951689e-03 seconds)
error ~= -1.00058638647656100717e-02
retrograde: 1.00179575636530900002e+09 -> 1.00179575635532295704e+09 (-9.98604297637939453125e-03)
tsc: 14979441809123 -> 14979441832373 (23250 tics, 2.09483317374114903710e-05 seconds)
error ~= -1.00069913081168061775e-02
retrograde: 1.00179576617553603649e+09 -> 1.00179576616554796696e+09 (-9.98806953430175781250e-03)
tsc: 14990329925054 -> 14990329946810 (21756 tics, 1.96022324851236305089e-05 seconds)
error ~= -1.00076717667868814871e-02
>Fix:
The bug seems to be the kernel trusting a notoriously
unreliable clock chip in microtime.s . Ignoring this chip
whenever possible would seem to be a big win.
Grab the "rdtsc" code from openbsd's microtime.s or grab the
similar code from freebsd. Integrating the freebsd routines
requires much more work, but one gets nano-second time for
one's trouble.
>Release-Note:
>Audit-Trail:
>Unformatted: