From: Harlan Stenn Date: Tue, 26 Oct 2010 21:20:17 +0000 (-0400) Subject: ntp_loopfilter.c, ntpd.h, ChangeLog, ntp_proto.c: X-Git-Tag: NTP_4_2_7P73~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d366f8169642feb141dc91fc5ae8e53ba3e1b7a3;p=thirdparty%2Fntp.git ntp_loopfilter.c, ntpd.h, ChangeLog, ntp_proto.c: * [Bug 1680] Fix alignment of clock_select() arrays. * refinements to new startup behavior from David Mills. bk: 4cc74611bFENCivttV2cNDPTZOf0nA --- diff --git a/ChangeLog b/ChangeLog index fc430a2e8..831a3a54b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* [Bug 1680] Fix alignment of clock_select() arrays. +* refinements to new startup behavior from David Mills. * For the bootstrap script, touch .html files last. (4.2.7p72) 2010/10/26 Released by Harlan Stenn * [Bug 1679] Fix test for -lsocket. diff --git a/include/ntpd.h b/include/ntpd.h index 210d24bda..a33b3e69d 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -162,6 +162,7 @@ extern void loop_config(int, double); extern void huffpuff(void); extern u_long sys_clocktime; extern u_int sys_tai; +extern int freq_cnt; /* ntp_monitor.c */ #define MON_HASH_SIZE (1U << mon_hash_bits) diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index aac517707..461426fe8 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -185,6 +185,7 @@ init_loopfilter(void) */ sys_poll = ntp_minpoll; clock_jitter = LOGTOD(sys_precision); + freq_cnt = clock_minstep; } /* @@ -417,7 +418,6 @@ local_clock( * the stepout threshold. */ case EVNT_NSET: - freq_cnt = clock_minstep; rstclock(EVNT_FREQ, fp_offset); break; @@ -428,7 +428,6 @@ local_clock( * counter decrements to zero. */ case EVNT_FSET: - freq_cnt = clock_minstep; rstclock(EVNT_SYNC, fp_offset); break; @@ -443,7 +442,6 @@ local_clock( return (0); clock_frequency = direct_freq(fp_offset); - freq_cnt = clock_minstep; rstclock(EVNT_SYNC, 0); /* fall through to default */ @@ -706,11 +704,12 @@ adj_host_clock( * time constant is clamkped at 2. */ sys_rootdisp += clock_phi; - if (fabs(clock_offset) < CLOCK_FLOOR) - freq_cnt = 0; - else if (freq_cnt > 0 && sys_leap != LEAP_NOTINSYNC) - freq_cnt--; - + if (state == EVNT_SYNC) { + if (fabs(clock_offset) < CLOCK_FLOOR) + freq_cnt = 0; + else if (freq_cnt > 0) + freq_cnt--; + } #ifndef LOCKCLOCK /* * If clock discipline is disabled or if the kernel is enabled, @@ -727,7 +726,7 @@ adj_host_clock( * reduced time constant at startup. */ if (freq_cnt > 0) - adjustment = clock_offset / (CLOCK_PLL * 4); + adjustment = clock_offset / (CLOCK_PLL * ULOGTOD(1)); else adjustment = clock_offset / (CLOCK_PLL * ULOGTOD(sys_poll)); clock_offset -= adjustment; diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index b172da427..a0ba8ad73 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -2127,9 +2127,9 @@ clock_filter( } /* - * If the clock is synchronized,sort the samples by distance. + * If the clock has stabilized, sort the samples by distance. */ - if (sys_leap != LEAP_NOTINSYNC) { + if (freq_cnt == 0) { for (i = 1; i < NTP_SHIFT; i++) { for (j = 0; j < i; j++) { if (dst[j] > dst[i]) { @@ -2221,7 +2221,7 @@ clock_filter( */ if (peer->filter_epoch[k] <= peer->epoch) { #if DEBUG - if (debug) + if (debug > 1) printf("clock_filter: old sample %lu\n", current_time - peer->filter_epoch[k]); #endif @@ -2278,15 +2278,15 @@ clock_select(void) struct peer *typepps = NULL; #endif /* REFCLOCK */ static struct endpoint *endpoint = NULL; - static int *indx = NULL; - static struct peer **peers = NULL; static double *synch = NULL; static double *error = NULL; + static int *indx = NULL; + static struct peer **peers = NULL; static u_int endpoint_size = 0; - static u_int indx_size = 0; - static u_int peers_size = 0; static u_int synch_size = 0; static u_int error_size = 0; + static u_int peers_size = 0; + static u_int indx_size = 0; size_t octets; /* @@ -2310,17 +2310,17 @@ clock_select(void) for (peer = peer_list; peer != NULL; peer = peer->p_link) nlist++; endpoint_size = nlist * 2 * sizeof(struct endpoint); - indx_size = nlist * 2 * sizeof(int); - peers_size = nlist * sizeof(struct peer *); synch_size = nlist * sizeof(double); error_size = nlist * sizeof(double); + peers_size = nlist * sizeof(struct peer *); + indx_size = nlist * 2 * sizeof(int); octets = endpoint_size + indx_size + peers_size + synch_size + error_size; endpoint = erealloc(endpoint, octets); - indx = (int *)((char *)endpoint + endpoint_size); - peers = (struct peer **)((char *)indx + indx_size); - synch = (double *)((char *)peers + peers_size); + synch = (double *)((char *)endpoint + endpoint_size); error = (double *)((char *)synch + synch_size); + peers = (struct peer **)((char *)error + error_size); + indx = (int *)((char *)peers + peers_size); /* * Initially, we populate the island with all the rifraff peers