mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 19:25:07 -05:00
reference: add wait options for local reference activation
Add "waitunsynced" option to specify how long chronyd needs to wait before it can activate the local reference when the clock is not synchronized to give the configured sources a chance to synchronize the local clock after start. The default is 300 seconds when the orphan option is enabled (same as the ntpd's default orphanwait), 0 otherwise. Add "waitsynced" option to specify how long it should wait when the clock is synchronized. It is an additional requirement to the distance and activate options.
This commit is contained in:
24
reference.c
24
reference.c
@@ -54,6 +54,8 @@ static int local_orphan;
|
||||
static double local_distance;
|
||||
static int local_activate_ok;
|
||||
static double local_activate;
|
||||
static double local_wait_synced;
|
||||
static double local_wait_unsynced;
|
||||
static struct timespec local_ref_time;
|
||||
static NTP_Leap our_leap_status;
|
||||
static int our_leap_sec;
|
||||
@@ -62,6 +64,7 @@ static int our_stratum;
|
||||
static uint32_t our_ref_id;
|
||||
static IPAddr our_ref_ip;
|
||||
static struct timespec our_ref_time;
|
||||
static double unsynchronised_since;
|
||||
static double our_skew;
|
||||
static double our_residual_freq;
|
||||
static double our_root_delay;
|
||||
@@ -248,8 +251,11 @@ REF_Initialise(void)
|
||||
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
||||
|
||||
enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_orphan,
|
||||
&local_distance, &local_activate);
|
||||
&local_distance, &local_activate,
|
||||
&local_wait_synced,
|
||||
&local_wait_unsynced);
|
||||
UTI_ZeroTimespec(&local_ref_time);
|
||||
unsynchronised_since = SCH_GetLastEventMonoTime();
|
||||
|
||||
leap_when = 0;
|
||||
leap_timeout_id = 0;
|
||||
@@ -1093,6 +1099,9 @@ REF_SetUnsynchronised(void)
|
||||
our_ref_ip.family = IPADDR_INET4;
|
||||
our_ref_ip.addr.in4 = 0;
|
||||
our_stratum = 0;
|
||||
|
||||
if (are_we_synchronised)
|
||||
unsynchronised_since = SCH_GetLastEventMonoTime();
|
||||
are_we_synchronised = 0;
|
||||
|
||||
LCL_SetSyncStatus(0, 0.0, 0.0);
|
||||
@@ -1136,13 +1145,16 @@ REF_GetReferenceParams
|
||||
)
|
||||
{
|
||||
double dispersion, delta, distance;
|
||||
int wait_local_ok;
|
||||
|
||||
assert(initialised);
|
||||
|
||||
if (are_we_synchronised) {
|
||||
dispersion = get_root_dispersion(local_time);
|
||||
wait_local_ok = UTI_DiffTimespecsToDouble(local_time, &our_ref_time) >= local_wait_synced;
|
||||
} else {
|
||||
dispersion = 0.0;
|
||||
wait_local_ok = SCH_GetLastEventMonoTime() - unsynchronised_since >= local_wait_unsynced;
|
||||
}
|
||||
|
||||
distance = our_root_delay / 2 + dispersion;
|
||||
@@ -1154,7 +1166,8 @@ REF_GetReferenceParams
|
||||
or the root distance exceeds the threshold */
|
||||
|
||||
if (are_we_synchronised &&
|
||||
!(enable_local_stratum && local_activate_ok && distance > local_distance)) {
|
||||
!(enable_local_stratum && local_activate_ok && wait_local_ok &&
|
||||
distance > local_distance)) {
|
||||
|
||||
*is_synchronised = 1;
|
||||
|
||||
@@ -1166,7 +1179,7 @@ REF_GetReferenceParams
|
||||
*root_delay = our_root_delay;
|
||||
*root_dispersion = dispersion;
|
||||
|
||||
} else if (enable_local_stratum && local_activate_ok) {
|
||||
} else if (enable_local_stratum && local_activate_ok && wait_local_ok) {
|
||||
|
||||
*is_synchronised = 0;
|
||||
|
||||
@@ -1266,13 +1279,16 @@ REF_ModifyMakestep(int limit, double threshold)
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
REF_EnableLocal(int stratum, double distance, int orphan, double activate)
|
||||
REF_EnableLocal(int stratum, double distance, int orphan, double activate,
|
||||
double wait_synced, double wait_unsynced)
|
||||
{
|
||||
enable_local_stratum = 1;
|
||||
local_stratum = CLAMP(1, stratum, NTP_MAX_STRATUM - 1);
|
||||
local_distance = distance;
|
||||
local_orphan = !!orphan;
|
||||
local_activate = activate;
|
||||
local_wait_synced = wait_synced;
|
||||
local_wait_unsynced = wait_unsynced;
|
||||
LOG(LOGS_INFO, "%s local reference mode", "Enabled");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user