double clock_minstep = CLOCK_MINSTEP; /* step timeout (s) */
u_char allan_xpt = CLOCK_ALLAN; /* minimum Allan intercept (log2 s) */
-/*
- * Hybrid PLL/FLL parameters. These were chosen by experiment using a
- * MatLab program. The parameters were fudged to match a pure PLL at
- * poll intervals of 64 s and lower and a pure FLL at poll intervals of
- * 4096 s and higher. Between these extremes the parameters were chosen
- * as a geometric series of intervals while holding the overshoot to
- * less than 5 percent.
- */
-static double fll[] = {0., 1./64, 1./32, 1./16, 1./8, 1./4, 1.};
-static double pll[] = {1., 1.4, 2., 2.8, 4.1, 7., 12.};
-
/*
* Program variables
*/
double clock_frequency; /* clock frequency adjustment (ppm) */
double dtemp, etemp; /* double temps */
int retval; /* return value */
- int i;
/*
* If the loop is opened, monitor and record the offsets
}
/*
- * Compute the FLL and PLL frequency adjustments
- * conditioned on intricate weighting factors.
- * The gain factors depend on the poll interval
- * and Allan intercept. For the FLL, the
- * averaging interval is clamped to a minimum of
- * 1024 s and the gain increased in stages from
- * zero for poll intervals below half the Allan
- * intercept to unity above twice the Allan
- * intercept. For the PLL, the averaging
- * interval is clamped not to exceed the poll
- * interval. No gain factor is necessary, since
- * the frequency steering above the Allan
- * intercept is negligible. Particularly for the
- * PLL, these measures allow oversampling, but
- * not undersampling and insure stability even
- * when the rules of fair engagement are broken.
+ * Compute the FLL and PLL frequency
+ * adjustments. The gain factors depend on the
+ * poll interval and Allan intercept. For the
+ * FLL, the averaging interval is clamped to a
+ * minimum equal to the Allan intercept. For the
+ * PLL, the averaging interval is clamped not to
+ * exceed 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.
*/
- i = sys_poll - allan_xpt + 4;
- if (i < 0)
- i = 0;
- else if (i > 6)
- i = 6;
- etemp = fll[i];
dtemp = max(mu, ULOGTOD(allan_xpt));
- flladj = (fp_offset - clock_offset) * etemp /
- (dtemp * CLOCK_FLL);
+ flladj = (fp_offset - clock_offset) / (dtemp *
+ CLOCK_FLL);
dtemp = ULOGTOD(SHIFT_PLL + 2 + sys_poll);
etemp = min(mu, ULOGTOD(sys_poll));
plladj = fp_offset * etemp / (dtemp * dtemp);
void
)
{
- double adjustment;
- int i;
+ double adjustment;
+ double dtemp;
/*
* Update the dispersion since the last update. In contrast to
/*
* This ugly bit of business is necessary in order to move the
- * pole frequency higher in FLL mode. This is necessary for loop
- * stability.
+ * pole frequency higher as the frequency gain in FLL mode is
+ * increased. This is necessary to keep the overshoot to less
+ * than a few percent.
*/
- i = sys_poll - allan_xpt + 4;
- if (i < 0)
- i = 0;
- else if (i > 6)
- i = 6;
- adjustment = clock_offset / (pll[i] * ULOGTOD(SHIFT_PLL +
- sys_poll));
+ dtemp = sys_poll;
+ if (sys_poll > allan_xpt - 4)
+ dtemp = sys_poll * 1.2;
+ dtemp = pow(2, dtemp);
+ adjustment = clock_offset / (dtemp * ULOGTOD(SHIFT_PLL));
clock_offset -= adjustment;
adj_systime(adjustment + drift_comp);
}
void
record_peer_stats(
struct sockaddr_storage *addr,
- int status,
- double offset,
- double delay,
- double dispersion,
- double skew
+ int status,
+ double offset,
+ double delay,
+ double dispersion,
+ double skew
)
{
- struct timeval tv;
-#ifdef HAVE_GETCLOCK
- struct timespec ts;
-#endif
- u_long day, sec, msec;
+ l_fp now;
+ u_long day;
if (!stats_control)
return;
-#ifdef HAVE_GETCLOCK
- (void) getclock(TIMEOFDAY, &ts);
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
-#else /* not HAVE_GETCLOCK */
- GETTIMEOFDAY(&tv, (struct timezone *)NULL);
-#endif /* not HAVE_GETCLOCK */
- day = tv.tv_sec / 86400 + MJD_1970;
- sec = tv.tv_sec % 86400;
- msec = tv.tv_usec / 1000;
-
- filegen_setup(&peerstats, (u_long)(tv.tv_sec + JAN_1970));
+ get_systime(&now);
+ filegen_setup(&peerstats, now.l_ui);
+ day = now.l_ui / 86400 + MJD_1970;
+ now.l_ui %= 86400;
if (peerstats.fp != NULL) {
fprintf(peerstats.fp,
- "%lu %lu.%03lu %s %x %.9f %.9f %.9f %.9f\n",
- day, sec, msec, stoa(addr), status, offset,
+ "%lu %s %s %x %.9f %.9f %.9f %.9f\n",
+ day, ulfptoa(&now, 3), stoa(addr), status, offset,
delay, dispersion, skew);
fflush(peerstats.fp);
}
*/
void
record_loop_stats(
- double offset,
- double freq,
- double jitter,
- double stability,
+ double offset,
+ double freq,
+ double jitter,
+ double stability,
int spoll
)
{
- struct timeval tv;
-#ifdef HAVE_GETCLOCK
- struct timespec ts;
-#endif
- u_long day, sec, msec;
+ l_fp now;
+ u_long day;
if (!stats_control)
return;
-#ifdef HAVE_GETCLOCK
- (void) getclock(TIMEOFDAY, &ts);
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
-#else /* not HAVE_GETCLOCK */
- GETTIMEOFDAY(&tv, (struct timezone *)NULL);
-#endif /* not HAVE_GETCLOCK */
- day = tv.tv_sec / 86400 + MJD_1970;
- sec = tv.tv_sec % 86400;
- msec = tv.tv_usec / 1000;
-
- filegen_setup(&loopstats, (u_long)(tv.tv_sec + JAN_1970));
+ get_systime(&now);
+ filegen_setup(&loopstats, now.l_ui);
+ day = now.l_ui / 86400 + MJD_1970;
+ now.l_ui %= 86400;
if (loopstats.fp != NULL) {
- fprintf(loopstats.fp, "%lu %lu.%03lu %.9f %.6f %.9f %.6f %d\n",
- day, sec, msec, offset, freq * 1e6, jitter,
+ fprintf(loopstats.fp, "%lu %s %.9f %.6f %.9f %.6f %d\n",
+ day, ulfptoa(&now, 3), offset, freq * 1e6, jitter,
stability * 1e6, spoll);
fflush(loopstats.fp);
}
const char *text
)
{
- struct timeval tv;
-#ifdef HAVE_GETCLOCK
- struct timespec ts;
-#endif
- u_long day, sec, msec;
+ l_fp now;
+ u_long day;
if (!stats_control)
return;
-#ifdef HAVE_GETCLOCK
- (void) getclock(TIMEOFDAY, &ts);
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
-#else /* not HAVE_GETCLOCK */
- GETTIMEOFDAY(&tv, (struct timezone *)NULL);
-#endif /* not HAVE_GETCLOCK */
- day = tv.tv_sec / 86400 + MJD_1970;
- sec = tv.tv_sec % 86400;
- msec = tv.tv_usec / 1000;
-
- filegen_setup(&clockstats, (u_long)(tv.tv_sec + JAN_1970));
+ get_systime(&now);
+ filegen_setup(&clockstats, now.l_ui);
+ day = now.l_ui / 86400 + MJD_1970;
+ now.l_ui %= 86400;
if (clockstats.fp != NULL) {
- fprintf(clockstats.fp, "%lu %lu.%03lu %s %s\n",
- day, sec, msec, stoa(addr), text);
+ fprintf(clockstats.fp, "%lu %s %s %s\n",
+ day, ulfptoa(&now, 3), stoa(addr), text);
fflush(clockstats.fp);
}
}
record_raw_stats(
struct sockaddr_storage *srcadr,
struct sockaddr_storage *dstadr,
- l_fp *t1,
- l_fp *t2,
- l_fp *t3,
- l_fp *t4
+ l_fp *t1,
+ l_fp *t2,
+ l_fp *t3,
+ l_fp *t4
)
{
- struct timeval tv;
-#ifdef HAVE_GETCLOCK
- struct timespec ts;
-#endif
- u_long day, sec, msec;
+ l_fp now;
+ u_long day;
if (!stats_control)
return;
-#ifdef HAVE_GETCLOCK
- (void) getclock(TIMEOFDAY, &ts);
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
-#else /* not HAVE_GETCLOCK */
- GETTIMEOFDAY(&tv, (struct timezone *)NULL);
-#endif /* not HAVE_GETCLOCK */
- day = tv.tv_sec / 86400 + MJD_1970;
- sec = tv.tv_sec % 86400;
- msec = tv.tv_usec / 1000;
-
- filegen_setup(&rawstats, (u_long)(tv.tv_sec + JAN_1970));
+ get_systime(&now);
+ filegen_setup(&rawstats, now.l_ui);
+ day = now.l_ui / 86400 + MJD_1970;
+ now.l_ui %= 86400;
if (rawstats.fp != NULL) {
- fprintf(rawstats.fp, "%lu %lu.%03lu %s %s %s %s %s %s\n",
- day, sec, msec, stoa(srcadr), stoa(dstadr),
+ fprintf(rawstats.fp, "%lu %s %s %s %s %s %s %s\n",
+ day, ulfptoa(&now, 3), stoa(srcadr), stoa(dstadr),
ulfptoa(t1, 9), ulfptoa(t2, 9), ulfptoa(t3, 9),
ulfptoa(t4, 9));
fflush(rawstats.fp);
const char *text
)
{
- struct timeval tv;
-#ifdef HAVE_GETCLOCK
- struct timespec ts;
-#endif
- u_long day, sec, msec;
+ l_fp now;
+ u_long day;
if (!stats_control)
return;
-#ifdef HAVE_GETCLOCK
- (void) getclock(TIMEOFDAY, &ts);
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
-#else /* not HAVE_GETCLOCK */
- GETTIMEOFDAY(&tv, (struct timezone *)NULL);
-#endif /* not HAVE_GETCLOCK */
- day = tv.tv_sec / 86400 + MJD_1970;
- sec = tv.tv_sec % 86400;
- msec = tv.tv_usec / 1000;
-
- filegen_setup(&cryptostats, (u_long)(tv.tv_sec + JAN_1970));
+ get_systime(&now);
+ filegen_setup(&cryptostats, now.l_ui);
+ day = now.l_ui / 86400 + MJD_1970;
+ now.l_ui %= 86400;
if (cryptostats.fp != NULL) {
if (addr == NULL)
- fprintf(cryptostats.fp, "%lu %lu.%03lu %s\n",
- day, sec, msec, text);
+ fprintf(cryptostats.fp, "%lu %s %s\n",
+ day, ulfptoa(&now, 3), text);
else
- fprintf(cryptostats.fp, "%lu %lu.%03lu %s %s\n",
- day, sec, msec, stoa(addr), text);
+ fprintf(cryptostats.fp, "%lu %s %s %s\n",
+ day, ulfptoa(&now, 3), stoa(addr), text);
fflush(cryptostats.fp);
}
}