From: Harlan Stenn Date: Thu, 9 Jan 2003 01:38:12 +0000 (-0500) Subject: Cleanup and improvements from Dave Mills. X-Git-Tag: NTP_4_1_73~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3683ade08c3bf4316918ecbf81b8963c02ddac20;p=thirdparty%2Fntp.git Cleanup and improvements from Dave Mills. bk: 3e1cd2846HlLwpCE7ROEz92VWx1zMg --- diff --git a/include/ntp.h b/include/ntp.h index e8be8036f8..ae648d2705 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -122,7 +122,7 @@ typedef char s_char; #define NTP_MINCLOCK 3 /* minimum survivors */ #define NTP_MAXCLOCK 10 /* maximum candidates */ #define MAXDISTANCE 1. /* max root distance */ -#define CLOCK_SGATE 4. /* popcorn spike gate */ +#define CLOCK_SGATE 3. /* popcorn spike gate */ #define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */ #define HYST .5 /* anti-clockhop hysteresis */ #define HYST_TC .875 /* anti-clockhop hysteresis decay */ diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index 0e4f03eae2..bb2d07c745 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -40,7 +40,7 @@ #define CLOCK_AVG 4. /* parameter averaging constant */ #define CLOCK_MINSEC 256. /* min FLL update interval (s) */ #define CLOCK_MINSTEP 900. /* step-change timeout (s) */ -#define CLOCK_ALLAN 3000. /* compromise Allan intercept (s) */ +#define CLOCK_ALLAN 1500. /* compromise Allan intercept (s) */ #define CLOCK_DAY 86400. /* one day in seconds (s) */ #define CLOCK_LIMIT 30 /* poll-adjust threshold */ #define CLOCK_PGATE 4. /* poll-adjust gate */ @@ -429,24 +429,22 @@ local_clock( /* * We come here in the normal case for linear phase and - * frequency adjustments. If the offset exceeds the - * previous time error estimate by CLOCK_SGATE and the - * interval since the last update is less than twice the - * poll interval, consider the update a popcorn spike - * and ignore it. + * frequency adjustments. If the difference between the + * last offset and the current one exceeds the jitter by + * CLOCK_SGATE (4) and the interval since the last + * update is less than twice the system poll interval, + * consider the update a popcorn spike and ignore it.. */ default: allow_panic = FALSE; - if (fabs(fp_offset - last_offset) > - CLOCK_SGATE * oerror && mu < + dtemp = fabs(fp_offset - last_offset); + if (dtemp > CLOCK_SGATE * oerror && mu < ULOGTOD(sys_poll + 1)) { #ifdef DEBUG if (debug) printf( "local_clock: popcorn %.6f %.6f\n", - fabs(fp_offset - - last_offset), CLOCK_SGATE * - oerror); + dtemp, oerror); #endif last_offset = fp_offset; return (0); @@ -457,22 +455,21 @@ local_clock( * which depend on the poll interval, update * interval and Allan intercept. For the FLL, * the averaging interval is clamped not less - * than the Allan intercept. For the PLL, the - * averaging interval is clamped not greater + * than the Allan intercept and the weight + * proportional to the poll interval from zero + * to unity at the Allan intercept. For the PLL, + * the averaging interval is clamped not greater * than the poll interval. Particularly for the * PLL, these measures allow oversampling, but * not undersampling and insure stability even * when the rules of fair engagement are broken. */ + etemp = min(1, sqrt(mu) / allan_xpt); dtemp = max(mu, allan_xpt); - flladj = (fp_offset - clock_offset) / + flladj = (fp_offset - clock_offset) * etemp / (CLOCK_FLL * dtemp); - -printf("xxx diff %f d %f\n", (fp_offset - clock_offset) * 1e6, - CLOCK_FLL * dtemp); - - dtemp = 4 * CLOCK_PLL * ULOGTOD(sys_poll); etemp = min(mu, ULOGTOD(sys_poll)); + dtemp = 4 * CLOCK_PLL * ULOGTOD(sys_poll); plladj = fp_offset * etemp / (dtemp * dtemp); last_time = peer->epoch; last_offset = clock_offset = fp_offset; @@ -614,10 +611,6 @@ printf("xxx diff %f d %f\n", (fp_offset - clock_offset) * 1e6, */ etemp = clock_frequency + flladj + plladj; drift_comp += etemp; - -printf("ofs %f freq %f cf %f pll %f fll %f\n", fp_offset, drift_comp * - 1e6, clock_frequency * 1e6, plladj * 1e6, flladj * 1e6); - if (drift_comp > NTP_MAXFREQ) drift_comp = NTP_MAXFREQ; else if (drift_comp <= -NTP_MAXFREQ) diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 848c29d406..fa2cea6a35 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -1650,7 +1650,8 @@ clock_filter( */ if (m == 0) return; - etemp = peer->offset; + etemp = fabs(peer->offset - peer->filter_offset[k]); + dtemp = sqrt(peer->jitter); peer->offset = peer->filter_offset[k]; peer->delay = peer->filter_delay[k]; if (m > 1) @@ -1677,13 +1678,13 @@ clock_filter( * the last update is less than twice the system poll interval, * consider the update a popcorn spike and ignore it. */ - if (m > 1 && fabs(peer->offset - etemp) > SQRT(peer->jitter) * - CLOCK_SGATE && peer->filter_epoch[k] - peer->epoch < - (1 << (sys_poll + 1))) { + if (m > 1 && etemp > CLOCK_SGATE * dtemp && + peer->filter_epoch[k] - peer->epoch < (1 << (sys_poll + + 1))) { #ifdef DEBUG if (debug) - printf("clock_filter: n %d popcorn spike %.6f jitter %.6f\n", - m, peer->offset, SQRT(peer->jitter)); + printf("clock_filter: popcorn %.6f %.6f\n", + etemp, dtemp); #endif return; }