Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/xntp/xntpd Correct precision estimate:



details:   https://anonhg.NetBSD.org/src/rev/567a920f33c3
branches:  trunk
changeset: 476120:567a920f33c3
user:      sommerfeld <sommerfeld%NetBSD.org@localhost>
date:      Mon Sep 06 22:27:44 1999 +0000

description:
Correct precision estimate:
we buzzloop calling gettimeofday() until we see a big jump.
old code would take the difference between the immediately previous return value.
Now, compute the difference based on the clock value as of right
after the previous big jump.

An alpha pc164 at 500MHz can do about 700 calls to gettimeofday() in
one clock tick, each of which increments tv_usec by 1 -- so the "big
jump" at the end is only ~270us rather than the real clock tick of
976us, which yields a precision value which is overoptimistic by a
factor of ~4.  The corrected code now yields the exact tick value
(which is correct since NetBSD/alpha doesn't have a precise
microtime).

diffstat:

 usr.sbin/xntp/xntpd/ntp_proto.c |  26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diffs (65 lines):

diff -r df8c883cb479 -r 567a920f33c3 usr.sbin/xntp/xntpd/ntp_proto.c
--- a/usr.sbin/xntp/xntpd/ntp_proto.c   Mon Sep 06 22:20:50 1999 +0000
+++ b/usr.sbin/xntp/xntpd/ntp_proto.c   Mon Sep 06 22:27:44 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_proto.c,v 1.5 1998/08/12 14:11:53 christos Exp $   */
+/*     $NetBSD: ntp_proto.c,v 1.6 1999/09/06 22:27:44 sommerfeld Exp $ */
 
 /*
  * ntp_proto.c - NTP version 3 protocol machinery
@@ -2269,11 +2269,16 @@
                int tz_dsttime;
        } tzp;
 #endif /* defined(VMS) || defined(_SEQUENT_) */
-       long last;
+       long last, last1;
        int i;
        long diff;
        long val;
        long usec;
+       long est[MINLOOPS];
+#ifdef DEBUG_PRECISION
+       int j;
+       long oldest[MINLOOPS];
+#endif
 #ifdef HAVE_GETCLOCK
         struct timespec ts;
 #endif
@@ -2287,7 +2292,7 @@
 #else /*  not HAVE_GETCLOCK */
        GETTIMEOFDAY(&tp, &tzp);
 #endif /* not HAVE_GETCLOCK */
-       last = tp.tv_usec;
+       last1 = last = tp.tv_usec;
        for (i = 0; i < MINLOOPS && usec < HUSECS;) {
 #ifdef HAVE_GETCLOCK
                 (void) getclock(TIMEOFDAY, &ts);
@@ -2302,13 +2307,28 @@
                        diff += DUSECS;
                usec += diff;
                if (diff > MINSTEP) {
+#ifdef DEBUG_PRECISION
+                       oldest[i] = diff;
+#endif
+                       diff = tp.tv_usec - last1;
+                       last1 = tp.tv_usec;
+                       if (diff < 0)
+                               diff += DUSECS;
+                       est[i] = diff;
                        i++;
                        if (diff < val)
                                val = diff;
                }
        }
+
        NLOG(NLOG_SYSINFO) /* conditional if clause for conditional syslog */
          msyslog(LOG_INFO, "precision = %d usec", val);
+#ifdef DEBUG_PRECISION
+       for (j=0; j<i; j++) {
+               msyslog(LOG_INFO, "est: %d %d", oldest[j], est[j]);
+       }
+#endif
+       
        if (usec >= HUSECS)
                val = MINSTEP;  /* val <= MINSTEP; fast machine */
        diff = HUSECS;



Home | Main Index | Thread Index | Old Index