From: Harlan Stenn Date: Sat, 5 Aug 2006 06:10:36 +0000 (-0400) Subject: Fixes from Dave. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1857670711a1752f64cf1e9986a97ec3430252e1;p=thirdparty%2Fntp.git Fixes from Dave. bk: 44d4365ctT6F_sRaZmWiL4kU9JJzmA --- diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index 85dde2a20b..3dfafbe9c0 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -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; } diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index f4215bff66..62406ecac0 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -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",