From: Harlan Stenn Date: Sat, 4 Jan 2003 23:36:58 +0000 (-0500) Subject: Cleanup from Dave X-Git-Tag: NTP_4_1_73~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a59ec4c3549e1c4d161068bfb00a5b1d84cd4ef;p=thirdparty%2Fntp.git Cleanup from Dave bk: 3e17701aU9vMLxP8SX_EJT7qovr3WA --- diff --git a/libntp/systime.c b/libntp/systime.c index db76b518dd..e1209ad179 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -420,7 +420,7 @@ step_systime( * written by other than amateurs. Good clock code is a black * art anyway. */ - ntp_node.ntp_time += now; + ntp_node.clk_time -= now; return (1); } @@ -444,7 +444,9 @@ node_clock( dtemp = t - n->ntp_time; n->time = t; n->ntp_time += dtemp; +/* n->ferr += gauss(0, dtemp * n->fnse * 1e-6); +*/ n->clk_time += dtemp * (1 + n->ferr * 1e-6); /* @@ -482,7 +484,8 @@ gauss( /* * Roll a sample from a Gaussian distribution with mean m and - * standard deviation s. + * standard deviation s. For m = 0, s = 1, mean(y) = 0, + * std(y) = 1. */ if (s == 0) return (m); @@ -505,7 +508,8 @@ poisson( /* * Roll a sample from a composite distribution with propagation - * delay m and exponential service time with parameter s. + * delay m and exponential distribution time with parameter s. + * For m = 0, s = 1, mean(y) = std(y) = 1. */ if (s == 0) return (m); diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index fea18a28bc..0e4f03eae2 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -40,6 +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_DAY 86400. /* one day in seconds (s) */ #define CLOCK_LIMIT 30 /* poll-adjust threshold */ #define CLOCK_PGATE 4. /* poll-adjust gate */ @@ -111,7 +112,7 @@ double clock_max = CLOCK_MAX; /* max offset before step (s) */ double clock_panic = CLOCK_PANIC; /* max offset before panic (s) */ double clock_phi = CLOCK_PHI; /* dispersion rate (s/s) */ double clock_minstep = CLOCK_MINSTEP; /* step timeout (s) */ -double allan_xpt = (1 << NTP_MINDPOLL); /* Allan intercept (s) */ +double allan_xpt = CLOCK_ALLAN; /* Allan intercept (s) */ /* * Program variables @@ -466,6 +467,10 @@ local_clock( dtemp = max(mu, allan_xpt); flladj = (fp_offset - clock_offset) / (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)); plladj = fp_offset * etemp / (dtemp * dtemp); @@ -609,6 +614,10 @@ local_clock( */ 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) @@ -862,17 +871,18 @@ loop_config( case LOOP_DRIFTCOMP: /* - * Initialize the kernel frequency and clamp to - * reasonable value. Also set the initial state to - * S_FSET to indicated the frequency has been - * initialized from the previously saved drift file. + * If the frequency value is reasonable, set the initial + * frequency to the given value and the state to S_FSET. + * Otherwise, the drift file may be missing or broken, + * so set the frequency to zero. This erases past + * history should somebody break something. */ - rstclock(S_FSET, current_time, 0); - drift_comp = freq; - if (drift_comp > NTP_MAXFREQ) - drift_comp = NTP_MAXFREQ; - if (drift_comp < -NTP_MAXFREQ) - drift_comp = -NTP_MAXFREQ; + if (freq <= NTP_MAXFREQ && freq >= -NTP_MAXFREQ) { + drift_comp = freq; + rstclock(S_FSET, current_time, 0); + } else { + drift_comp = 0; + } #ifdef KERNEL_PLL /* diff --git a/ntpd/ntpsim.c b/ntpd/ntpsim.c index bb9d17948b..3fbae17c7c 100644 --- a/ntpd/ntpsim.c +++ b/ntpd/ntpsim.c @@ -27,12 +27,13 @@ void (*funcPtr[]) (Node *, Event) = { */ int ntpsim( - int argc, - char *argv[] + int argc, + char *argv[] ) { - Event e; - double maxtime; + Event e; + double maxtime; + struct timeval seed; /* * Initialize the global node @@ -75,6 +76,12 @@ ntpsim( getconfig(argc, argv); initializing = 0; + /* + * Watch out here, we want the real time, not the silly stuff. + */ + gettimeofday(&seed, NULL); + srand48(seed.tv_usec); + /* * Push a beep and timer interrupt on the queue */