mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:25:07 -05:00
ntp: drop initstepslew NTP implementation
The initstepslew code has its own minimal NTP implementation. Drop the code, add a new initstepslew mode to the reference updating code and use regular NTP sources with iburst flag for initstepslew addresses instead. When an update is made or a source is found unreachable, log a message, remove the initstepslew sources and switch to normal mode. This reduces code duplication and makes initstepslew use features implemented only in the main code like source combining or SO_TIMESTAMP support.
This commit is contained in:
93
reference.c
93
reference.c
@@ -67,6 +67,9 @@ static double correction_time_ratio;
|
||||
/* Flag indicating that we are initialised */
|
||||
static int initialised = 0;
|
||||
|
||||
/* Current operating mode */
|
||||
static REF_Mode mode;
|
||||
|
||||
/* Threshold and update limit for stepping clock */
|
||||
static int make_step_limit;
|
||||
static double make_step_threshold;
|
||||
@@ -86,6 +89,9 @@ static int do_mail_change;
|
||||
static double mail_change_threshold;
|
||||
static char *mail_change_user;
|
||||
|
||||
/* Handler for mode ending */
|
||||
static REF_ModeEndHandler mode_end_handler = NULL;
|
||||
|
||||
/* Filename of the drift file. */
|
||||
static char *drift_file=NULL;
|
||||
static double drift_file_age;
|
||||
@@ -155,6 +161,7 @@ REF_Initialise(void)
|
||||
double file_freq_ppm, file_skew_ppm;
|
||||
double our_frequency_ppm;
|
||||
|
||||
mode = REF_ModeIgnore;
|
||||
are_we_synchronised = 0;
|
||||
our_leap_status = LEAP_Unsynchronised;
|
||||
our_leap_sec = 0;
|
||||
@@ -266,6 +273,29 @@ REF_Finalise(void)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void REF_SetMode(REF_Mode new_mode)
|
||||
{
|
||||
mode = new_mode;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
REF_Mode
|
||||
REF_GetMode(void)
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
REF_SetModeEndHandler(REF_ModeEndHandler handler)
|
||||
{
|
||||
mode_end_handler = handler;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static double
|
||||
Sqr(double x)
|
||||
{
|
||||
@@ -456,6 +486,18 @@ schedule_fb_drift(struct timeval *now)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static void
|
||||
end_ref_mode(int result)
|
||||
{
|
||||
mode = REF_ModeIgnore;
|
||||
|
||||
/* Dispatch the handler */
|
||||
if (mode_end_handler)
|
||||
(mode_end_handler)(result);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
#define BUFLEN 255
|
||||
#define S_MAX_USER_LEN "128"
|
||||
|
||||
@@ -664,6 +706,43 @@ write_log(struct timeval *ref_time, char *ref, int stratum, NTP_Leap leap,
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static void
|
||||
special_mode_sync(int valid, double offset)
|
||||
{
|
||||
int step;
|
||||
|
||||
switch (mode) {
|
||||
case REF_ModeInitStepSlew:
|
||||
if (!valid) {
|
||||
LOG(LOGS_WARN, LOGF_Reference, "No suitable source for initstepslew");
|
||||
end_ref_mode(0);
|
||||
break;
|
||||
}
|
||||
|
||||
step = fabs(offset) >= CNF_GetInitStepThreshold();
|
||||
|
||||
LOG(LOGS_INFO, LOGF_Reference,
|
||||
"System's initial offset : %.6f seconds %s of true (%s)",
|
||||
fabs(offset), offset >= 0 ? "fast" : "slow", step ? "step" : "slew");
|
||||
|
||||
if (step)
|
||||
LCL_ApplyStepOffset(offset);
|
||||
else
|
||||
LCL_AccumulateOffset(offset, 0.0);
|
||||
|
||||
end_ref_mode(1);
|
||||
|
||||
break;
|
||||
case REF_ModeIgnore:
|
||||
/* Do nothing until the mode is changed */
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
REF_SetReference(int stratum,
|
||||
NTP_Leap leap,
|
||||
@@ -695,6 +774,12 @@ REF_SetReference(int stratum,
|
||||
|
||||
assert(initialised);
|
||||
|
||||
/* Special modes are implemented elsewhere */
|
||||
if (mode != REF_ModeNormal) {
|
||||
special_mode_sync(1, offset);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Guard against dividing by zero */
|
||||
if (skew < MIN_SKEW)
|
||||
skew = MIN_SKEW;
|
||||
@@ -886,6 +971,12 @@ REF_SetUnsynchronised(void)
|
||||
|
||||
assert(initialised);
|
||||
|
||||
/* Special modes are implemented elsewhere */
|
||||
if (mode != REF_ModeNormal) {
|
||||
special_mode_sync(0, 0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* This is cheaper than calling LCL_CookTime */
|
||||
SCH_GetLastEventTime(&now, NULL, &now_raw);
|
||||
UTI_DiffTimevalsToDouble(&uncorrected_offset, &now, &now_raw);
|
||||
@@ -1086,5 +1177,3 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
Reference in New Issue
Block a user