]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 963] get_systime() is too noisy
authorHarlan Stenn <stenn@ntp.org>
Thu, 22 Nov 2007 07:34:27 +0000 (02:34 -0500)
committerHarlan Stenn <stenn@ntp.org>
Thu, 22 Nov 2007 07:34:27 +0000 (02:34 -0500)
bk: 47453103GGB6auwpRPfCTE_FHqxN1Q

ChangeLog
libntp/systime.c
ntpd/ntp_io.c

index 251e49dda86b172ac1dc1e876a3b57260b798d7b..d334d6adc0314bc8caee77448dbb2d9cbb4bdaae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 963] get_systime() is too noisy.
 * [Bug 960] spurious syslog:crypto_setup:spurious crypto command
 * [Bug 964] Change *-*-linux* to *-*-*linux* to allow for uclinux.
 * Changes from Dave Mills:
index 56337ee80915c7f45f31a83d957143906e3ec021..95acf50051a340cefd42b4ebd7295864b33ac02b 100644 (file)
 /*
  * These routines (get_systime, step_systime, adj_systime) implement an
  * interface between the system independent NTP clock and the Unix
- * system clock in various architectures and operating systems.
+ * system clock in various architectures and operating systems. Time is
+ * a precious quantity in these routines and every effort is made to
+ * minimize errors by unbiased rounding and amortizing adjustment
+ * residues.
  *
- * Time is a precious quantity in these routines and every effort is
- * made to minimize errors by always rounding toward zero and amortizing
- * adjustment residues. By default the adjustment quantum is 1 us for
- * the usual Unix tickadj() system call, but this can be increased if
- * necessary by the tick configuration command. For instance, when the
- * adjtime() quantum is a clock tick for a 100-Hz clock, the quantum
- * should be 10 ms.
+ * In order to improve the apparent resolution, provide unbiased
+ * rounding and insure that the readings cannot be predicted, the low-
+ * order unused portion of the time below the resolution limit is filled
+ * with an unbiased random fuzz.
+ *
+ * The sys_tick variable secifies the system clock tick interval in
+ * seconds and fraction. For systems that can interpolate between timer
+ * interrupts, the assumed tick interval and resolution is 1 us
+ * consistent with the timeval format used by the Unix getimeofday() abd
+ * adjtime() routines. With routines that use the timespec format, the
+ * resolution is 1 ns. For systems that cannot interpolate, such as
+ * Reliant and SCO, the resolution is as specified by the sys_tick
+ * variable, which defaults to 10 ms. The default can be changed by the
+ * tick configuration command. 
  */
 #if defined RELIANTUNIX_CLOCK || defined SCO5_CLOCK
-double sys_tick = 10e-3;       /* 10 ms tickadj() */
+double sys_tick = .01;         /* 10 ms resolution */
 #else
-double sys_tick = 1e-6;        /* 1 us tickadj() */
+double sys_tick = 1e-6;        /* 1 us resolution */
 #endif
 double sys_residual = 0;       /* adjustment residue (s) */
 
@@ -67,7 +77,9 @@ get_systime(
        getclock(TIMEOFDAY, &ts);
 # endif
        now->l_i = ts.tv_sec + JAN_1970;
-       dtemp = sys_residual + (ts.tv_nsec + ntp_random() / 0.5e9) / 1e9;
+       dtemp = ts.tv_nsec + (ntp_random() * 2. / FRAC) * sys_tick *
+           1e6;
+       dtemp = dtemp / 1e9 + sys_residual;
        if (dtemp >= 1.) {
                dtemp -= 1.;
                now->l_i++;
@@ -86,7 +98,9 @@ get_systime(
         */
        GETTIMEOFDAY(&tv, NULL);
        now->l_i = tv.tv_sec + JAN_1970;
-       dtemp = sys_residual + (tv.tv_usec + ntp_random() / 0.5e6) / 1e6;
+       dtemp = ts.tv_usec + (ntp_random() * 2. / FRAC) * sys_tick *
+           1e6;
+       dtemp = dtemp / 1e6 + sys_residual;
        if (dtemp >= 1.) {
                dtemp -= 1.;
                now->l_i++;
index 4edd4c4287f9ed5cc80104799698c9fe31c1ce08..02d53a7f2b913ea76c55ad25826dbd726dcc1c04 100644 (file)
@@ -3005,7 +3005,8 @@ static l_fp
                        l_fp nts;
                        DPRINTF(4, ("fetch_timestamp: system network time stamp: %ld.%06ld\n", tvp->tv_sec, tvp->tv_usec));
                        nts.l_i = tvp->tv_sec + JAN_1970;
-                       dtemp = (tvp->tv_usec + ntp_random() / 0.5e6) / 1e6;
+                       dtemp = (tvp->tv_usec + (ntp_random() * 2. / FRAC) /
+                           1e6;
                        nts.l_uf = (u_int32)(dtemp * FRAC);
 #ifdef DEBUG_TIMING
                        {