tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[RFC][ARM32] Time running bug in the NetBSD time network



Hello.

I'm discovering very nice bug with the system time clock on TI OMAP
2420sdp (H4). I'm
using last current with __HAVE_FAST_SOFTINTS is enabled (although I
think the issue is
independ on this one).

Small test suite shows time running bug. The time counter is run so
fast like in 35-40 times more.

# for i in `seq 1 10`; do date; sleep 1; done
Tue May 13 10:08:50 UTC 2008
Tue May 13 10:09:39 UTC 2008
Tue May 13 10:10:21 UTC 2008
Tue May 13 10:11:13 UTC 2008
Tue May 13 10:11:52 UTC 2008
Tue May 13 10:12:40 UTC 2008
Tue May 13 10:13:15 UTC 2008
Tue May 13 10:14:01 UTC 2008
Tue May 13 10:14:43 UTC 2008
Tue May 13 10:15:21 UTC 2008

After apply bellow patch the same script outputs differ result
Tue May 13 10:34:19 UTC 2008
Tue May 13 10:34:20 UTC 2008
Tue May 13 10:34:21 UTC 2008
Tue May 13 10:34:22 UTC 2008
Tue May 13 10:34:23 UTC 2008
Tue May 13 10:34:24 UTC 2008
Tue May 13 10:34:25 UTC 2008
Tue May 13 10:34:26 UTC 2008
Tue May 13 10:34:27 UTC 2008
Tue May 13 10:34:28 UTC 2008

Following dump of the ntpdate commands shows the time fluctuation.

# ntpdate ntp.colocall.net
13 May 09:59:41 ntpdate[275]: step time server 62.149.2.1 offset -1.140264 sec
# ntpdate ntp.colocall.net
13 May 09:59:43 ntpdate[276]: adjust time server 62.149.2.1 offset -0.009921 sec
# ntpdate ntp.colocall.net
13 May 09:59:45 ntpdate[277]: adjust time server 62.149.2.1 offset 0.169885 sec
# ntpdate ntp.colocall.net
13 May 09:59:48 ntpdate[270]: step time server 62.149.2.1 offset 0.810970 sec
# ntpdate ntp.colocall.net
13 May 09:59:51 ntpdate[269]: adjust time server 62.149.2.1 offset -0.010731 sec
# ntpdate ntp.colocall.net
13 May 11:04:27 ntpdate[278]: step time server 62.149.2.1 offset -0.732343 sec
# ntpdate ntp.colocall.net
13 May 11:04:48 ntpdate[279]: adjust time server 62.149.2.1 offset -0.008991 sec
# ntpdate ntp.colocall.net
13 May 11:11:02 ntpdate[280]: adjust time server 62.149.2.1 offset 0.012668 sec
# ntpdate ntp.colocall.net
13 May 11:28:34 ntpdate[285]: adjust time server 62.149.2.1 offset 0.016605 sec

There is a patch to fix the issue (in other words it's workaround and
may be not applicable to
mainstream due to some reasons).

Index: sys/kern/kern_tc.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_tc.c,v
retrieving revision 1.36
diff -u -r1.36 kern_tc.c
--- sys/kern/kern_tc.c  11 May 2008 14:42:18 -0000      1.36
+++ sys/kern/kern_tc.c  13 May 2008 13:35:39 -0000
@@ -646,7 +646,15 @@
                ncount = 0;
        th->th_offset_count += delta;
        th->th_offset_count &= th->th_counter->tc_counter_mask;
-       bintime_addx(&th->th_offset, th->th_scale * delta);
+       /*
+        * The one timer tick should increment system clock by a 1/hz seconds
+        * and delta, where delta is fluctuation of frequency dependent to the
+        * run time of this code.
+        *
+        * FIXME: What about frequency great than 2^32Hz?
+        */
+       bintime_addx(&th->th_offset,
+                    th->th_scale * ((u_int) tc_getfrequency() / hz + delta));

        /*
         * Hardware latching timecounters may not generate interrupts on


-- 
With Best Regards,
Andy Shevchenko


Home | Main Index | Thread Index | Old Index