]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Fixes from Dave.
authorHarlan Stenn <stenn@ntp.org>
Sat, 5 Aug 2006 06:10:36 +0000 (02:10 -0400)
committerHarlan Stenn <stenn@ntp.org>
Sat, 5 Aug 2006 06:10:36 +0000 (02:10 -0400)
bk: 44d4365ctT6F_sRaZmWiL4kU9JJzmA

ntpd/ntp_loopfilter.c
ntpd/ntp_proto.c

index 85dde2a20b6f02769dacb791ddf2c5aec9c759e7..3dfafbe9c09e9999d13ec14bdb21a85b8e3256ec 100644 (file)
@@ -158,7 +158,6 @@ int state;                  /* clock discipline state */
 u_char sys_poll = NTP_MINDPOLL; /* time constant/poll (log2 s) */
 int    tc_counter;             /* jiggle counter */
 double last_offset;            /* last offset (s) */
-double last_base;              /* last base offset (s) */
 
 /*
  * Huff-n'-puff filter variables
@@ -359,8 +358,8 @@ local_clock(
                        if (mu < clock_minstep)
                                return (0);
 
-                       clock_frequency = (fp_offset - last_base -
-                           clock_offset) / mu;
+                       clock_frequency = (fp_offset - clock_offset) /
+                           mu;
 
                        /* fall through to S_SPIK */
 
@@ -431,21 +430,22 @@ local_clock(
 
                /*
                 * In S_NSET state this is the first update received and
-                * the frequency has not been initialized. The first
-                * thing to do is directly measure the frequency offset.
+                * the frequency has not been initialized. Adjust the
+                * phase, but do not adjust the frequency until after
+                * the stepout threshold.
                 */
                case S_NSET:
-                       clock_offset = fp_offset;
                        rstclock(S_FREQ, peer->epoch, fp_offset);
-                       return (0);
+                       break;
 
                /*
-                * In S_FSET state this is the first update and the
-                * frequency has been initialized. Adjust the phase, but
-                * don't adjust the frequency until the next update.
+                * In S_FSET state this is the first update received and
+                * the frequency has been initialized. Adjust the phase,
+                * but do not adjust the frequency until the next
+                * update.
                 */
                case S_FSET:
-                       clock_offset = fp_offset;
+                       rstclock(S_SYNC, peer->epoch, fp_offset);
                        break;
 
                /*
@@ -457,8 +457,9 @@ local_clock(
                        if (mu < clock_minstep)
                                return (0);
 
-                       clock_frequency = (fp_offset - last_base -
-                           clock_offset) / mu;
+                       clock_frequency = (fp_offset - clock_offset) /
+                           mu;
+                       rstclock(S_SYNC, peer->epoch, fp_offset);
                        break;
 
                /*
@@ -493,9 +494,9 @@ local_clock(
                        etemp = min(mu, (u_long)ULOGTOD(sys_poll));
                        dtemp = 4 * CLOCK_PLL * ULOGTOD(sys_poll);
                        plladj = fp_offset * etemp / (dtemp * dtemp);
+                       rstclock(S_SYNC, peer->epoch, fp_offset);
                        break;
                }
-               rstclock(S_SYNC, peer->epoch, fp_offset);
        }
 
 #ifdef OPENSSL
@@ -545,7 +546,8 @@ local_clock(
         * the ntp discipline until the residual offset sinks beneath
         * the waves.
         */
-       if (pll_control && kern_enable && fabs(clock_offset) < .5) {
+       if (pll_control && kern_enable && fabs(clock_offset) < .5 &&
+           state != S_FREQ) {
 
                /*
                 * We initialize the structure for the ntp_adjtime()
@@ -838,16 +840,14 @@ rstclock(
        double  offset          /* new offset */
        )
 {
-       state = trans;
-       sys_clocktime = update;
-       last_base = offset - clock_offset;
-       last_offset = clock_offset = offset;
 #ifdef DEBUG
        if (debug)
-               printf("local_clock: time %lu base %.6f offset %.6f freq %.3f state %d\n",
-                   sys_clocktime, last_base, last_offset, drift_comp *
-                   1e6, trans);
+               printf("local_clock: time %lu offset %.6f freq %.3f state %d\n",
+                   update, offset, drift_comp * 1e6, trans);
 #endif
+       state = trans;
+       sys_clocktime = update;
+       last_offset = clock_offset = offset;
 }
 
 
index f4215bff666eea71eb87ce0cd1b81cd628d7e1e3..62406ecac093543255aae9e1ee53c00bd61c4970 100644 (file)
@@ -1661,19 +1661,23 @@ clock_filter(
        }
 
         /*
-        * Sort the samples in both lists by distance. Note, we do not
-        * displace a higher distance sample by a lower distance one
-        * unless lower by at least the precision.  
-        */
-       for (i = 1; i < NTP_SHIFT; i++) {
-               for (j = 0; j < i; j++) {
-                       if (dst[j] > dst[i] + LOGTOD(sys_precision)) {
-                               k = ord[j];
-                               ord[j] = ord[i];
-                               ord[i] = k;
-                               etemp = dst[j];
-                               dst[j] = dst[i];
-                               dst[i] = etemp;
+        * If the clock discipline has stabilized, sort the samples in
+        * both lists by distance. Note, we do not displace a higher
+        * distance sample by a lower distance one unless lower by at
+        * least the precision.  
+        */
+       if (state == 4) {
+               for (i = 1; i < NTP_SHIFT; i++) {
+                       for (j = 0; j < i; j++) {
+                               if (dst[j] > dst[i] +
+                                   LOGTOD(sys_precision)) {
+                                       k = ord[j];
+                                       ord[j] = ord[i];
+                                       ord[i] = k;
+                                       etemp = dst[j];
+                                       dst[j] = dst[i];
+                                       dst[i] = etemp;
+                               }
                        }
                }
        }
@@ -1730,10 +1734,10 @@ clock_filter(
 
        /*
         * A new sample is useful only if it is younger than the last
-        * one used, but only if the sucker has been synchronized.
+        * one used. Note the order is FIFO if the clock discipline has
+        * not stabilized.
         */
-       if (peer->filter_epoch[k] <= peer->epoch && sys_leap !=
-           LEAP_NOTINSYNC) {
+       if (peer->filter_epoch[k] <= peer->epoch) {
 #ifdef DEBUG
                if (debug)
                        printf("clock_filter: discard %lu\n",