[Git][NTPsec/ntpsec][master] 2 commits: Structified ntp_loopfilter.c related globals.
Eric S. Raymond
gitlab at mg.gitlab.com
Sat Aug 17 04:28:06 UTC 2019
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
0339f4f7 by Ian Bruene at 2019-08-17T04:14:55Z
Structified ntp_loopfilter.c related globals.
- - - - -
831efb1a by Ian Bruene at 2019-08-17T04:14:55Z
Fixed missing loop_data change.
- - - - -
7 changed files:
- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_loopfilter.c
- ntpd/ntp_proto.c
- ntpd/ntp_timer.c
- ntpd/ntp_util.c
- ntpd/refclock_local.c
Changes:
=====================================
include/ntpd.h
=====================================
@@ -269,12 +269,15 @@ struct ntp_io_data {
extern struct ntp_io_data io_data;
/* 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) */
-extern double clock_max_fwd; /* max forward offset before step (s) */
-extern double clock_phi; /* dispersion rate (s/s) */
+struct ntp_loop_data {
+ bool lockclock; /* lock to system clock? (externally disciplined?) */
+ double drift_comp; /* clock frequency (s/s) */
+ double clock_stability; /* clock stability (wander) (s/s) */
+ double clock_max_back; /* max backward offset before step (s) */
+ double clock_max_fwd; /* max forward offset before step (s) */
+ double clock_phi; /* dispersion rate (s/s) */
+};
+extern struct ntp_loop_data loop_data;
/*
* Clock state machine control flags
=====================================
ntpd/ntp_control.c
=====================================
@@ -1446,7 +1446,7 @@ ctl_putsys(
case CS_DRIFT:
/* a.k.a frequency. (s/s), reported as us/s a.k.a. ppm */
- ctl_putdbl6(sys_var[CS_DRIFT].text, drift_comp * US_PER_S);
+ ctl_putdbl6(sys_var[CS_DRIFT].text, loop_data.drift_comp * US_PER_S);
break;
case CS_JITTER:
@@ -1482,7 +1482,7 @@ ctl_putsys(
case CS_STABIL:
/* a.k.a clk_wander (s/s), output as us/s */
ctl_putdbl6(sys_var[CS_STABIL].text,
- clock_stability * US_PER_S);
+ loop_data.clock_stability * US_PER_S);
break;
case CS_VARLIST:
@@ -1871,7 +1871,7 @@ ctl_putsys(
break;
case CS_K_LOCKCLOCK:
- ctl_putuint(sys_var[varid].text, lockclock);
+ ctl_putuint(sys_var[varid].text, loop_data.lockclock);
break;
case CS_IOSTATS_RESET:
=====================================
ntpd/ntp_loopfilter.c
=====================================
@@ -103,13 +103,15 @@
/*
* Program variables that can be tinkered.
*/
-double clock_max_back = CLOCK_MAX; /* step threshold */
-double clock_max_fwd = CLOCK_MAX; /* step threshold */
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? */
+struct ntp_loop_data loop_data = {
+ .clock_max_back = CLOCK_MAX, /* step threshold */
+ .clock_max_fwd = CLOCK_MAX, /* step threshold */
+ .clock_phi = CLOCK_PHI /* dispersion rate (s/s) */
+};
/*
* Program variables
@@ -117,9 +119,7 @@ bool lockclock; /* hardware clock is externally disciplined? */
static double clock_offset; /* offset (non-lockclock case only) */
static uptime_t clock_epoch; /* last update (non-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 */
/* following variables are non-lockclock case only */
static bool loop_started; /* true after LOOP_DRIFTINIT */
@@ -445,9 +445,9 @@ local_clock(
* monitor and record the offsets anyway in order to determine
* the open-loop response and then go home.
*/
- if (lockclock || !clock_ctl.ntp_enable) {
- record_loop_stats(fp_offset, drift_comp, clock_jitter,
- clock_stability, sys_poll);
+ if (loop_data.lockclock || !clock_ctl.ntp_enable) {
+ record_loop_stats(fp_offset, loop_data.drift_comp, clock_jitter,
+ loop_data.clock_stability, sys_poll);
return (0);
}
@@ -487,8 +487,8 @@ local_clock(
* directly to the terminal.
*/
if (clock_ctl.mode_ntpdate) {
- if ( ( fp_offset > clock_max_fwd && clock_max_fwd > 0)
- || (-fp_offset > clock_max_back && clock_max_back > 0)) {
+ if ( ( fp_offset > loop_data.clock_max_fwd && loop_data.clock_max_fwd > 0)
+ || (-fp_offset > loop_data.clock_max_back && loop_data.clock_max_back > 0)) {
step_systime(fp_offset, ntp_set_tod);
msyslog(LOG_NOTICE, "CLOCK: time set %+.6f s",
fp_offset);
@@ -499,8 +499,8 @@ local_clock(
fp_offset);
printf("ntpd: time slew %+.6fs\n", fp_offset);
}
- record_loop_stats(fp_offset, drift_comp, clock_jitter,
- clock_stability, sys_poll);
+ record_loop_stats(fp_offset, loop_data.drift_comp, clock_jitter,
+ loop_data.clock_stability, sys_poll);
exit(0);
}
@@ -544,10 +544,10 @@ local_clock(
if (sys_poll > peer->cfg.maxpoll)
sys_poll = peer->cfg.maxpoll;
mu = current_time - clock_epoch;
- clock_frequency = drift_comp;
+ clock_frequency = loop_data.drift_comp;
rval = 1;
- if ( ( fp_offset > clock_max_fwd && clock_max_fwd > 0)
- || (-fp_offset > clock_max_back && clock_max_back > 0)
+ if ( ( fp_offset > loop_data.clock_max_fwd && loop_data.clock_max_fwd > 0)
+ || (-fp_offset > loop_data.clock_max_back && loop_data.clock_max_back > 0)
|| clock_ctl.force_step_once ) {
if (clock_ctl.force_step_once) {
clock_ctl.force_step_once = false; /* we want this only once after startup */
@@ -829,21 +829,21 @@ local_clock(
msyslog(LOG_NOTICE,
"CLOCK: frequency error %.0f PPM exceeds tolerance %.0f PPM",
clock_frequency * US_PER_S, NTP_MAXFREQ * US_PER_S);
- dtemp = SQUARE(clock_frequency - drift_comp);
+ dtemp = SQUARE(clock_frequency - loop_data.drift_comp);
if (clock_frequency > NTP_MAXFREQ)
- drift_comp = NTP_MAXFREQ;
+ loop_data.drift_comp = NTP_MAXFREQ;
else if (clock_frequency < -NTP_MAXFREQ)
- drift_comp = -NTP_MAXFREQ;
+ loop_data.drift_comp = -NTP_MAXFREQ;
else
- drift_comp = clock_frequency;
+ loop_data.drift_comp = clock_frequency;
/*
* Calculate the wander as the exponentially weighted RMS
* frequency differences. Record the change for the frequency
* file update.
*/
- etemp = SQUARE(clock_stability);
- clock_stability = SQRT(etemp + (dtemp - etemp) / CLOCK_AVG);
+ etemp = SQUARE(loop_data.clock_stability);
+ loop_data.clock_stability = SQRT(etemp + (dtemp - etemp) / CLOCK_AVG);
/*
* Here we adjust the time constant by comparing the current
@@ -884,11 +884,11 @@ local_clock(
/*
* Yibbidy, yibbbidy, yibbidy; that'h all folks.
*/
- record_loop_stats(clock_offset, drift_comp, clock_jitter,
- clock_stability, sys_poll);
+ record_loop_stats(clock_offset, loop_data.drift_comp, clock_jitter,
+ loop_data.clock_stability, sys_poll);
DPRINT(1, ("local_clock: offset %.9f jit %.9f freq %.6f stab %.3f poll %d\n",
- clock_offset, clock_jitter, drift_comp * US_PER_S,
- clock_stability * US_PER_S, sys_poll));
+ clock_offset, clock_jitter, loop_data.drift_comp * US_PER_S,
+ loop_data.clock_stability * US_PER_S, sys_poll));
return (rval);
}
@@ -915,8 +915,8 @@ adj_host_clock(
* would be counterproductive. During the startup clamp period, the
* time constant is clamped at 2.
*/
- sys_vars.sys_rootdisp += clock_phi;
- if (lockclock || !clock_ctl.ntp_enable || clock_ctl.mode_ntpdate)
+ sys_vars.sys_rootdisp += loop_data.clock_phi;
+ if (loop_data.lockclock || !clock_ctl.ntp_enable || clock_ctl.mode_ntpdate)
return;
/*
* Determine the phase adjustment. The gain factor (denominator)
@@ -944,7 +944,7 @@ adj_host_clock(
if (clock_ctl.pll_control && clock_ctl.kern_enable)
freq_adj = 0.;
else
- freq_adj = drift_comp;
+ freq_adj = loop_data.drift_comp;
/* Bound absolute value of total adjustment to NTP_MAXFREQ. */
if (offset_adj + freq_adj > NTP_MAXFREQ)
@@ -1007,7 +1007,7 @@ direct_freq(
{
set_freq(fp_offset / (current_time - clock_epoch));
- return drift_comp;
+ return loop_data.drift_comp;
}
/*
@@ -1029,7 +1029,7 @@ set_freq(
{
const char * loop_desc;
- drift_comp = freq;
+ loop_data.drift_comp = freq;
loop_desc = "ntpd";
if (clock_ctl.pll_control) {
int ntp_adj_ret;
@@ -1037,14 +1037,14 @@ set_freq(
ntv.modes = MOD_FREQUENCY;
if (clock_ctl.kern_enable) {
loop_desc = "kernel";
- ntv.freq = DTOFREQ(drift_comp);
+ ntv.freq = DTOFREQ(loop_data.drift_comp);
}
if ((ntp_adj_ret = ntp_adjtime_ns(&ntv)) != 0) {
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, false, false, __LINE__ - 1);
}
}
mprintf_event(EVNT_FSET, NULL, "%s %.6f PPM", loop_desc,
- drift_comp * US_PER_S);
+ loop_data.drift_comp * US_PER_S);
}
static void
@@ -1138,8 +1138,8 @@ select_loop(
* call set_freq() to switch the frequency compensation to or
* from the kernel loop.
*/
- if (!lockclock && clock_ctl.pll_control && loop_started)
- set_freq(drift_comp);
+ if (!loop_data.lockclock && clock_ctl.pll_control && loop_started)
+ set_freq(loop_data.drift_comp);
}
@@ -1186,7 +1186,7 @@ loop_config(
* variables. Otherwise, continue leaving no harm behind.
*/
case LOOP_DRIFTINIT:
- if (lockclock || clock_ctl.mode_ntpdate)
+ if (loop_data.lockclock || clock_ctl.mode_ntpdate)
break;
start_kern_loop();
@@ -1212,7 +1212,7 @@ loop_config(
case LOOP_KERN_CLEAR:
#if 0 /* XXX: needs more review, and how can we get here? */
- if (!lockclock && (clock_ctl.pll_control && clock_ctl.kern_enable)) {
+ if (!loop_data.lockclock && (clock_ctl.pll_control && clock_ctl.kern_enable)) {
memset((char *)&ntv, 0, sizeof(ntv));
ntv.modes = MOD_STATUS;
ntv.status = STA_UNSYNC;
@@ -1232,7 +1232,7 @@ loop_config(
break;
case LOOP_PHI: /* dispersion threshold (dispersion) */
- clock_phi = freq / US_PER_S;
+ loop_data.clock_phi = freq / US_PER_S;
break;
case LOOP_FREQ: /* initial frequency (freq) */
@@ -1256,27 +1256,27 @@ loop_config(
break;
case LOOP_MAX: /* step threshold (step) */
- clock_max_fwd = clock_max_back = freq;
+ loop_data.clock_max_fwd = loop_data.clock_max_back = freq;
if ( D_ISZERO_NS(freq) || freq > 0.5)
select_loop(false);
break;
case LOOP_MAX_BACK: /* step threshold (step) */
- clock_max_back = freq;
+ loop_data.clock_max_back = freq;
/*
* Leave using the kernel discipline code unless both
* limits are massive. This assumes the reason to stop
* using it is that it's pointless, not that it goes wrong.
*/
- if ( D_ISZERO_NS(clock_max_back) || (clock_max_back > 0.5)
- || D_ISZERO_NS(clock_max_fwd) || (clock_max_fwd > 0.5))
+ if ( D_ISZERO_NS(loop_data.clock_max_back) || (loop_data.clock_max_back > 0.5)
+ || D_ISZERO_NS(loop_data.clock_max_fwd) || (loop_data.clock_max_fwd > 0.5))
select_loop(false);
break;
case LOOP_MAX_FWD: /* step threshold (step) */
- clock_max_fwd = freq;
- if ( D_ISZERO_NS(clock_max_back) || (clock_max_back > 0.5)
- || D_ISZERO_NS(clock_max_fwd) || (clock_max_fwd > 0.5))
+ loop_data.clock_max_fwd = freq;
+ if ( D_ISZERO_NS(loop_data.clock_max_back) || (loop_data.clock_max_back > 0.5)
+ || D_ISZERO_NS(loop_data.clock_max_fwd) || (loop_data.clock_max_fwd > 0.5))
select_loop(false);
break;
=====================================
ntpd/ntp_proto.c
=====================================
@@ -504,7 +504,7 @@ handle_procpkt(
const double delta = fabs(t21 - t34);
const double epsilon = LOGTOD(sys_vars.sys_precision) +
LOGTOD(peer->precision) +
- clock_phi * delta;
+ loop_data.clock_phi * delta;
/* One final test before we touch any variables that could
affect the clock: don't accept any packets with a round
@@ -943,7 +943,7 @@ clock_update(
dtemp = peer->rootdisp
+ peer->disp
+ sys_jitter
- + clock_phi * (current_time - peer->update)
+ + loop_data.clock_phi * (current_time - peer->update)
+ fabs(sys_offset);
if (dtemp > sys_mindisp)
@@ -1268,7 +1268,7 @@ clock_filter(
* less than the Allan intercept use the delay; otherwise, use
* the sum of the delay and dispersion.
*/
- dtemp = clock_phi * (current_time - peer->update);
+ dtemp = loop_data.clock_phi * (current_time - peer->update);
peer->update = current_time;
for (i = NTP_SHIFT - 1; i >= 0; i--) {
if (i != 0)
@@ -1447,7 +1447,7 @@ clock_select(void)
*/
osys_peer = sys_vars.sys_peer;
sys_survivors = 0;
- if (lockclock) {
+ if (loop_data.lockclock) {
set_sys_leap(LEAP_NOTINSYNC);
sys_vars.sys_stratum = STRATUM_UNSPEC;
memcpy(&sys_vars.sys_refid, "DOWN", REFIDLEN);
@@ -1994,7 +1994,7 @@ root_distance(
dtemp = (peer->delay + peer->rootdelay) / 2
+ LOGTOD(peer->precision)
+ LOGTOD(sys_vars.sys_precision)
- + clock_phi * (current_time - peer->update)
+ + loop_data.clock_phi * (current_time - peer->update)
+ peer->rootdisp
+ peer->jitter;
/*
@@ -2504,14 +2504,14 @@ peer_unfit(
* plus the increment due to one host poll interval.
*/
if (!(peer->cfg.flags & FLAG_REFCLOCK) && root_distance(peer) >=
- sys_maxdist + clock_phi * ULOGTOD(peer->hpoll))
+ sys_maxdist + loop_data.clock_phi * ULOGTOD(peer->hpoll))
rval |= BOGON11; /* distance exceeded */
/* Startup bug, https://gitlab.com/NTPsec/ntpsec/issues/68
* introduced with ntp-dev-4.2.7p385
* [2085] Fix root distance and root dispersion calculations.
*/
if (!(peer->cfg.flags & FLAG_REFCLOCK) && peer->disp >=
- sys_maxdist + clock_phi * ULOGTOD(peer->hpoll))
+ sys_maxdist + loop_data.clock_phi * ULOGTOD(peer->hpoll))
rval |= BOGON11; /* Initialization */
/*
=====================================
ntpd/ntp_timer.c
=====================================
@@ -459,16 +459,16 @@ check_leapsec(
if (fired) {
const char *leapmsg = NULL;
if (lsdata.warped < 0) {
- if (clock_max_back > 0.0 &&
- clock_max_back < abs(lsdata.warped)) {
+ if (loop_data.clock_max_back > 0.0 &&
+ loop_data.clock_max_back < abs(lsdata.warped)) {
step_systime(lsdata.warped, ntp_set_tod);
leapmsg = leapmsg_p_step;
} else {
leapmsg = leapmsg_p_slew;
}
} else if (lsdata.warped > 0) {
- if (clock_max_fwd > 0.0 &&
- clock_max_fwd < abs(lsdata.warped)) {
+ if (loop_data.clock_max_fwd > 0.0 &&
+ loop_data.clock_max_fwd < abs(lsdata.warped)) {
step_systime(lsdata.warped, ntp_set_tod);
leapmsg = leapmsg_n_step;
} else {
=====================================
ntpd/ntp_util.c
=====================================
@@ -192,15 +192,15 @@ write_stats(void)
* nonvolaile storage.
*/
DPRINT(1, ("write_stats: frequency %.6lf thresh %.6lf, freq %.6lf\n",
- (prev_drift_comp - drift_comp) * US_PER_S,
- wander_resid * US_PER_S, drift_comp * US_PER_S));
- if (fabs(prev_drift_comp - drift_comp) < wander_resid) {
+ (prev_drift_comp - loop_data.drift_comp) * US_PER_S,
+ wander_resid * US_PER_S, loop_data.drift_comp * US_PER_S));
+ if (fabs(prev_drift_comp - loop_data.drift_comp) < wander_resid) {
wander_resid *= 0.5;
return;
}
- prev_drift_comp = drift_comp;
+ prev_drift_comp = loop_data.drift_comp;
wander_resid = wander_threshold;
- drift_write(stats_drift_file, drift_comp * US_PER_S);
+ drift_write(stats_drift_file, loop_data.drift_comp * US_PER_S);
}
}
@@ -257,7 +257,7 @@ stats_config(
*/
if (drift_read(stats_drift_file, &new_drift)) {
loop_config(LOOP_FREQ, new_drift);
- prev_drift_comp = drift_comp;
+ prev_drift_comp = loop_data.drift_comp;
}
break;
=====================================
ntpd/refclock_local.c
=====================================
@@ -110,7 +110,7 @@ local_start(
peer->sstclktype = CTL_SST_TS_LOCAL;
poll_time = current_time;
if (pp->sloppyclockflag & CLK_FLAG1)
- lockclock = true;
+ loop_data.lockclock = true;
return true;
}
@@ -158,7 +158,7 @@ local_poll(
* If another process is disciplining the system clock, we set
* the leap bits and quality indicators from the kernel.
*/
- if (lockclock) {
+ if (loop_data.lockclock) {
struct timex ntv;
memset(&ntv, 0, sizeof ntv);
switch (ntp_adjtime(&ntv)) {
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/774dc083044faa2a7ecce1eb660386d7dba8c2f8...831efb1a0d9544b8f1648d37b1688e0de9e387d2
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/774dc083044faa2a7ecce1eb660386d7dba8c2f8...831efb1a0d9544b8f1648d37b1688e0de9e387d2
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/20190817/0bf08ac8/attachment-0001.htm>
More information about the vc
mailing list