From: Harlan Stenn Date: Sun, 26 Aug 2001 04:14:37 +0000 (-0400) Subject: Anti-clockhop hysteresis stuff from Dave Mills. X-Git-Tag: NTP_4_1_71~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e724ffb5c2317d56217d382e6dc51defd4ccd910;p=thirdparty%2Fntp.git Anti-clockhop hysteresis stuff from Dave Mills. bk: 3b8877ad8jnfoFYcEID9V72sFaWcPA --- diff --git a/include/ntp.h b/include/ntp.h index 531d5e6d60..0a004e48e2 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -111,6 +111,8 @@ typedef char s_char; #define BURST_INTERVAL1 4 /* first interburst interval (log2) */ #define BURST_INTERVAL2 1 /* succeeding interburst intervals (log2) */ #define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */ +#define HYST .5 /* anti-clockhop hysteresis */ +#define HYST_TC .5 /* anti-clockhop hysteresis decay factor */ /* * Operations for jitter calculations (these use doubles). @@ -304,6 +306,7 @@ struct peer { double jitter; /* peer jitter (squares) */ double disp; /* peer dispersion */ double estbdelay; /* clock offset to broadcast server */ + double hyst; /* anti-clockhop hysteresis */ /* * Variables set by received packet diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 91c2a6286b..12b82001d3 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -163,6 +163,7 @@ transmit( peer->flags |= FLAG_CLUST; oreach = peer->reach; peer->reach <<= 1; + peer->hyst *= HYST_TC; if (peer->reach == 0) { /* @@ -1809,6 +1810,10 @@ clock_select(void) * drowned as well, but only if at at least eight poll intervals * have gone by. We must leave at least one peer to collect the * million bucks. + * + * Note the hysteresis gimmick that decreases the effective + * distance for those rascals that previously have made the + * final cut. This to discourage clockhopping. */ j = 0; for (i = 0; i < nlist; i++) { @@ -1821,7 +1826,8 @@ clock_select(void) continue; } peer->status = CTL_PST_SEL_DISTSYSPEER; - d = root_distance(peer) + peer->stratum * MAXDISPERSE; + d = (1. - peer->hyst) * root_distance(peer) + + peer->stratum * MAXDISPERSE; if (j >= NTP_MAXCLOCK) { if (d >= synch[j - 1]) continue; @@ -1955,6 +1961,7 @@ clock_select(void) peer = peer_list[i]; peer->status = CTL_PST_SEL_SYNCCAND; peer->flags |= FLAG_SYSPEER; + peer->hyst = HYST; poll_update(peer, peer->hpoll); if (peer->stratum == peer_list[0]->stratum) { leap_consensus |= peer->leap;