[Git][NTPsec/ntpsec][master] Turn ENABLE_LOCKCLOCK into a runtime ooption of the local-clock driver.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Jan 17 05:44:58 UTC 2019
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
9e39558f by Eric S. Raymond at 2019-01-17T05:43:49Z
Turn ENABLE_LOCKCLOCK into a runtime ooption of the local-clock driver.
- - - - -
10 changed files:
- NEWS
- devel/ifdex-ignores
- docs/driver_local.adoc
- docs/ntpsec.adoc
- include/ntpd.h
- ntpd/ntp_loopfilter.c
- ntpd/ntp_proto.c
- ntpd/refclock_local.c
- wafhelpers/options.py
- wscript
Changes:
=====================================
NEWS
=====================================
@@ -10,6 +10,11 @@ Much of the traditional function of a news file is now better addressed
by browsing the comments in the revision history. This file will focus
on user-visible changes.
+== Repository head ==
+
+NIST lockclock mode is now a runtime option set by the (previously unused)
+flag1 mode bit of the local-clock driver.
+
== 2019-01-13: 1.1.3 ==
Lots of typo fixes, documentation cleanups, test targets.
=====================================
devel/ifdex-ignores
=====================================
@@ -64,7 +64,6 @@ LIBRESSL_VERSION_NUMBER
# Things WAF sets that don't get #undefs if they're not set
ENABLE_EARLY_DROPROOT
ENABLE_LEAP_SMEAR
-ENABLE_LOCKCLOCK
ENABLE_MSSNTP
ENABLE_LEAP_TESTING
HAVE_LINUX_CAPABILITY
=====================================
docs/driver_local.adoc
=====================================
@@ -52,7 +52,8 @@ No +filegen clockstats+ monitor data are produced by this driver.
Specifies the driver reference identifier, an ASCII string from one to
four characters, with default +LOCL+.
+flag1 {0 | 1}+::
- Not used by this driver.
+ If flag1 is 1, set NIST lockclock mode. In this mode, ntpd assumes
+ the system clock is externally disctplined and disables frequency adjustment.
+flag2 {0 | 1}+::
Not used by this driver.
+flag3 {0 | 1}+::
=====================================
docs/ntpsec.adoc
=====================================
@@ -278,6 +278,10 @@ codebase has been outright removed, with less than 5% new code added.
default device path, the default PPS device path (if any) and the
serial baud rate.
+* NIST lockclock mode is now a runtime option set by the (previously unused)
+ flag1 mode bit of the local-clock driver, rather than a compile-time
+ option.
+
[[other]]
== Other user-visible changes ==
=====================================
include/ntpd.h
=====================================
@@ -247,6 +247,7 @@ extern endpt * loopback_interface; /* IPv4 loopback for refclocks */
extern endpt * ep_list; /* linked list */
/* ntp_loopfilter.c */
+extern bool lockclock; /* lock to the system clock? */
extern double drift_comp; /* clock frequency (s/s) */
extern double clock_stability; /* clock stability (s/s) */
extern double clock_max_back; /* max backward offset before step (s) */
=====================================
ntpd/ntp_loopfilter.c
=====================================
@@ -109,25 +109,23 @@ static double clock_minstep = CLOCK_MINSTEP; /* stepout threshold */
static double clock_panic = CLOCK_PANIC; /* panic threshold */
double clock_phi = CLOCK_PHI; /* dispersion rate (s/s) */
uint8_t allan_xpt = CLOCK_ALLAN; /* Allan intercept (log2 s) */
+bool lockclock; /* hardware clock is externally disciplined? */
/*
* Program variables
*/
-#ifndef ENABLE_LOCKCLOCK
-static double clock_offset; /* offset */
-static uptime_t clock_epoch; /* last update */
-#endif /* ENABLE_LOCKCLOCK */
+static double clock_offset; /* offset (lockclock case only) */
+static uptime_t clock_epoch; /* last update (lockclock case only) */
double clock_jitter; /* offset jitter */
double drift_comp; /* frequency (s/s) */
static double init_drift_comp; /* initial frequency (PPM) */
double clock_stability; /* frequency stability (wander) (s/s) */
unsigned int sys_tai; /* TAI offset from UTC */
-#ifndef ENABLE_LOCKCLOCK
+/* following variables are non-lockclock case only */
static bool loop_started; /* true after LOOP_DRIFTINIT */
static void rstclock (int, double); /* transition function */
static double direct_freq(double); /* direct set frequency */
static void set_freq(double); /* set frequency */
-#endif /* ENABLE_LOCKCLOCK */
#ifndef PATH_MAX
# define PATH_MAX MAX_PATH
@@ -137,11 +135,9 @@ static char *this_file = NULL;
static struct timex ntv; /* ntp_adjtime() parameters */
static int pll_status; /* last kernel status bits */
-#ifndef ENABLE_LOCKCLOCK
#if defined(STA_NANO) && defined(NTP_API) && NTP_API == 4
-static unsigned int loop_tai; /* last TAI offset */
+static unsigned int loop_tai; /* last TAI offset (non-lockclock case only) */
#endif /* STA_NANO */
-#endif /* ENABLE_LOCKCLOCK */
static void start_kern_loop(void);
static void stop_kern_loop(void);
@@ -165,9 +161,7 @@ static bool ext_enable; /* external clock enabled */
/*
* Clock state machine variables
*/
-#ifndef ENABLE_LOCKCLOCK
-static int state = 0; /* clock discipline state */
-#endif /* ENABLE_LOCKCLOCK */
+static int state = 0; /* clock discipline state (non-lockclock only) */
uint8_t sys_poll; /* time constant/poll (log2 s) */
int tc_counter; /* jiggle counter */
double last_offset; /* last offset (s) */
@@ -190,17 +184,16 @@ static struct sigaction newsigsys; /* new sigaction status */
static sigjmp_buf env; /* environment var. for pll_trap() */
#endif /* SIGSYS */
-#ifndef ENABLE_LOCKCLOCK
static void
sync_status(const char *what, int ostatus, int nstatus)
{
+ /* only used in non-lockclock case */
char obuf[256], nbuf[256], tbuf[1024];
snprintf(obuf, sizeof(obuf), "%04x", (unsigned)ostatus);
snprintf(nbuf, sizeof(nbuf), "%04x", (unsigned)nstatus);
snprintf(tbuf, sizeof(tbuf), "%s status: %s -> %s", what, obuf, nbuf);
report_event(EVNT_KERN, NULL, tbuf);
}
-#endif /* ENABLE_LOCKCLOCK */
/*
* file_name - return pointer to non-relative portion of this C file pathname
@@ -438,7 +431,7 @@ or, from ntp_adjtime():
* 1 clock was slewed
* 2 clock was stepped
*
- * ENABLE_LOCKCLOCK: The only thing this routine does is set the
+ * If lockclock is on, the only thing this routine does is set the
* sys_rootdisp variable equal to the peer dispersion.
*/
int
@@ -447,35 +440,25 @@ local_clock(
double fp_offset /* clock offset (s) */
)
{
-#ifdef ENABLE_LOCKCLOCK
- UNUSED_ARG(peer);
- UNUSED_ARG(fp_offset);
-#else
- int rval; /* return code */
- int osys_poll; /* old system poll */
- int ntp_adj_ret; /* returned by ntp_adjtime */
- double mu; /* interval since last update */
- double clock_frequency; /* clock frequency */
- double dtemp, etemp; /* double temps */
- char tbuf[80]; /* report buffer */
-#endif /* ENABLE_LOCKCLOCK */
-
/*
* If the loop is opened or the NIST lockclock scheme is in use,
* monitor and record the offsets anyway in order to determine
* the open-loop response and then go home.
*/
-#ifdef ENABLE_LOCKCLOCK
- {
-#else
- if (!clock_ctl.ntp_enable) {
-#endif /* ENABLE_LOCKCLOCK */
+ if (lockclock || !clock_ctl.ntp_enable) {
record_loop_stats(fp_offset, drift_comp, clock_jitter,
clock_stability, sys_poll);
return (0);
}
-#ifndef ENABLE_LOCKCLOCK
+ int rval; /* return code */
+ int osys_poll; /* old system poll */
+ int ntp_adj_ret; /* returned by ntp_adjtime */
+ double mu; /* interval since last update */
+ double clock_frequency; /* clock frequency */
+ double dtemp, etemp; /* double temps */
+ char tbuf[80]; /* report buffer */
+
/*
* If the clock is way off, panic is declared. The clock_panic
* defaults to 1000 s; if set to zero, the panic will never
@@ -907,14 +890,13 @@ local_clock(
clock_offset, clock_jitter, drift_comp * US_PER_S,
clock_stability * US_PER_S, sys_poll));
return (rval);
-#endif /* ENABLE_LOCKCLOCK */
}
/*
* adj_host_clock - Called once every second to update the local clock.
*
- * ENABLE_LOCKCLOCK: The only thing this routine does is increment the
+ * If lockclock is on the only thing this routine does is increment the
* sys_rootdisp variable.
*/
void
@@ -922,10 +904,8 @@ adj_host_clock(
void
)
{
-#ifndef ENABLE_LOCKCLOCK
double offset_adj;
double freq_adj;
-#endif /* ENABLE_LOCKCLOCK */
/*
* Update the dispersion since the last update. In contrast to
@@ -936,8 +916,7 @@ adj_host_clock(
* time constant is clamped at 2.
*/
sys_vars.sys_rootdisp += clock_phi;
-#ifndef ENABLE_LOCKCLOCK
- if (!clock_ctl.ntp_enable || clock_ctl.mode_ntpdate)
+ if (lockclock || !clock_ctl.ntp_enable || clock_ctl.mode_ntpdate)
return;
/*
* Determine the phase adjustment. The gain factor (denominator)
@@ -987,11 +966,9 @@ adj_host_clock(
* has decayed to zero.
*/
adj_systime(offset_adj + freq_adj, adjtime);
-#endif /* ENABLE_LOCKCLOCK */
}
-#ifndef ENABLE_LOCKCLOCK
/*
* Clock state machine. Enter new state and set state variables.
*/
@@ -1032,9 +1009,7 @@ direct_freq(
return drift_comp;
}
-#endif /* ENABLE_LOCKCLOCK */
-#ifndef ENABLE_LOCKCLOCK
/*
* set_freq - set clock frequency correction
*
@@ -1071,7 +1046,6 @@ set_freq(
mprintf_event(EVNT_FSET, NULL, "%s %.6f PPM", loop_desc,
drift_comp * US_PER_S);
}
-#endif /* HAVE_LOCKCLOCK */
static void
start_kern_loop(void)
@@ -1164,10 +1138,8 @@ select_loop(
* call set_freq() to switch the frequency compensation to or
* from the kernel loop.
*/
-#if !defined(ENABLE_LOCKCLOCK)
- if (clock_ctl.pll_control && loop_started)
+ if (!lockclock && clock_ctl.pll_control && loop_started)
set_freq(drift_comp);
-#endif
}
@@ -1195,7 +1167,7 @@ huffpuff(void)
/*
* loop_config - configure the loop filter
*
- * ENABLE_LOCKCLOCK: The LOOP_DRIFTINIT and LOOP_DRIFTCOMP cases are no-ops.
+ * If lockclock is on, the LOOP_DRIFTINIT and LOOP_DRIFTCOMP cases are no-ops.
*/
void
loop_config(
@@ -1214,8 +1186,7 @@ loop_config(
* variables. Otherwise, continue leaving no harm behind.
*/
case LOOP_DRIFTINIT:
-#ifndef ENABLE_LOCKCLOCK
- if (clock_ctl.mode_ntpdate)
+ if (!lockclock || clock_ctl.mode_ntpdate)
break;
start_kern_loop();
@@ -1237,13 +1208,11 @@ loop_config(
else
rstclock(EVNT_NSET, 0);
loop_started = true;
-#endif /* !ENABLE_LOCKCLOCK */
break;
case LOOP_KERN_CLEAR:
#if 0 /* XXX: needs more review, and how can we get here? */
-#ifndef ENABLE_LOCKCLOCK
- if (clock_ctl.pll_control && clock_ctl.kern_enable) {
+ if (!lockclock && (clock_ctl.pll_control && clock_ctl.kern_enable)) {
memset((char *)&ntv, 0, sizeof(ntv));
ntv.modes = MOD_STATUS;
ntv.status = STA_UNSYNC;
@@ -1252,7 +1221,6 @@ loop_config(
pll_status,
ntv.status);
}
-#endif /* ENABLE_LOCKCLOCK */
#endif
break;
=====================================
ntpd/ntp_proto.c
=====================================
@@ -1443,11 +1443,11 @@ clock_filter(
/*
* clock_select - find the pick-of-the-litter clock
*
- * ENABLE_LOCKCLOCK: (1) If the local clock is the prefer peer, it will always
- * be enabled, even if declared falseticker, (2) only the prefer peer
- * can be selected as the system peer, (3) if the external source is
- * down, the system leap bits are set to 11 and the stratum set to
- * infinity.
+ * When lockclock is on: (1) If the local clock is the prefer peer, it
+ * will always be enabled, even if declared falseticker, (2) only the
+ * prefer peer can be selected as the system peer, (3) if the external
+ * source is down, the system leap bits are set to 11 and the stratum
+ * set to infinity.
*/
void
clock_select(void)
@@ -1485,11 +1485,11 @@ clock_select(void)
*/
osys_peer = sys_vars.sys_peer;
sys_survivors = 0;
-#ifdef ENABLE_LOCKCLOCK
- set_sys_leap(LEAP_NOTINSYNC);
- sys_vars.sys_stratum = STRATUM_UNSPEC;
- memcpy(&sys_vars.sys_refid, "DOWN", REFIDLEN);
-#endif /* ENABLE_LOCKCLOCK */
+ if (lockclock) {
+ set_sys_leap(LEAP_NOTINSYNC);
+ sys_vars.sys_stratum = STRATUM_UNSPEC;
+ memcpy(&sys_vars.sys_refid, "DOWN", REFIDLEN);
+ }
/*
* Allocate dynamic space depending on the number of
=====================================
ntpd/refclock_local.c
=====================================
@@ -109,6 +109,8 @@ local_start(
memcpy(&pp->refid, "LOCL", REFIDLEN);
peer->sstclktype = CTL_SST_TS_LOCAL;
poll_time = current_time;
+ if (pp->sloppyclockflag & CLK_FLAG1)
+ lockclock = true
return true;
}
@@ -116,7 +118,7 @@ local_start(
/*
* local_poll - called by the transmit procedure
*
- * ENABLE_LOCKCLOCK: If the kernel supports the nanokernel or microkernel
+ * If lockclock is on: If the kernel supports the nanokernel or microkernel
* system calls, the leap bits are extracted from the kernel. If there
* is a kernel error or the kernel leap bits are set to 11, the NTP leap
* bits are set to 11 and the stratum is set to infinity. Otherwise, the
@@ -156,36 +158,36 @@ local_poll(
* If another process is disciplining the system clock, we set
* the leap bits and quality indicators from the kernel.
*/
-#if defined(ENABLE_LOCKCLOCK)
- struct timex ntv;
- memset(&ntv, 0, sizeof ntv);
- switch (ntp_adjtime(&ntv)) {
- case TIME_OK:
+ if (lockclock) {
+ struct timex ntv;
+ memset(&ntv, 0, sizeof ntv);
+ switch (ntp_adjtime(&ntv)) {
+ case TIME_OK:
+ pp->leap = LEAP_NOWARNING;
+ peer->stratum = pp->stratum;
+ break;
+
+ case TIME_INS:
+ pp->leap = LEAP_ADDSECOND;
+ peer->stratum = pp->stratum;
+ break;
+
+ case TIME_DEL:
+ pp->leap = LEAP_DELSECOND;
+ peer->stratum = pp->stratum;
+ break;
+
+ default:
+ pp->leap = LEAP_NOTINSYNC;
+ peer->stratum = STRATUM_UNSPEC;
+ }
+ pp->disp = 0;
+ pp->jitter = 0;
+ } else {
pp->leap = LEAP_NOWARNING;
- peer->stratum = pp->stratum;
- break;
-
- case TIME_INS:
- pp->leap = LEAP_ADDSECOND;
- peer->stratum = pp->stratum;
- break;
-
- case TIME_DEL:
- pp->leap = LEAP_DELSECOND;
- peer->stratum = pp->stratum;
- break;
-
- default:
- pp->leap = LEAP_NOTINSYNC;
- peer->stratum = STRATUM_UNSPEC;
+ pp->disp = DISPERSION;
+ pp->jitter = 0;
}
- pp->disp = 0;
- pp->jitter = 0;
-#else /* ENABLE_LOCKCLOCK */
- pp->leap = LEAP_NOWARNING;
- pp->disp = DISPERSION;
- pp->jitter = 0;
-#endif /* ENABLE_LOCKCLOCK */
pp->lastref = pp->lastrec;
refclock_receive(peer);
}
=====================================
wafhelpers/options.py
=====================================
@@ -48,8 +48,6 @@ def options_cmd(ctx, config):
help="Enable leaps on other than 1st of month.")
grp.add_option('--enable-mssntp', action='store_true',
default=False, help="Enable Samba MS SNTP support.")
- grp.add_option('--enable-lockclock', action='store_true',
- default=False, help="Enable NIST lockclock scheme.")
grp = ctx.add_option_group("Refclock configure options")
grp.add_option(
=====================================
wscript
=====================================
@@ -741,15 +741,6 @@ int main(int argc, char **argv) {
comment="Enable MS-SNTP extensions "
" https://msdn.microsoft.com/en-us/library/cc212930.aspx")
- if ctx.options.enable_lockclock:
- if ctx.env.REFCLOCK_LOCAL:
- ctx.define("ENABLE_LOCKCLOCK", 1,
- comment="Enable NIST 'lockclock'")
- else:
- import waflib.Errors
- raise waflib.Errors.WafError(
- "NIST 'lockclock' requires refclock 'local'")
-
if not ctx.options.disable_droproot:
ctx.define("ENABLE_DROPROOT", 1,
comment="Drop root after initialising")
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9e39558fb8ab8ec438f3aac034cdda54cecf0fa3
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9e39558fb8ab8ec438f3aac034cdda54cecf0fa3
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190117/9c87f116/attachment-0001.html>
More information about the vc
mailing list