]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Cleanup from Dave
authorHarlan Stenn <stenn@ntp.org>
Sat, 4 Jan 2003 23:36:58 +0000 (18:36 -0500)
committerHarlan Stenn <stenn@ntp.org>
Sat, 4 Jan 2003 23:36:58 +0000 (18:36 -0500)
bk: 3e17701aU9vMLxP8SX_EJT7qovr3WA

libntp/systime.c
ntpd/ntp_loopfilter.c
ntpd/ntpsim.c

index db76b518ddfc846d358e573dbc1f28abcc921114..e1209ad17977c8d0be2c11222be72912b06e4038 100644 (file)
@@ -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);
index fea18a28bcab187353f707b6429fbf66ef04f649..0e4f03eae24c4fd067ff04181b672496c4ffa99d 100644 (file)
@@ -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
                /*
index bb9d17948b091129b380f2cc4c130cc1b67f1dc5..3fbae17c7c0dffe581e64e7f62de3aaa6d8b181d 100644 (file)
@@ -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
         */