static time_t last_tz_leap_check;
static NTP_Leap tz_leap;
-#define MAX_LOCAL_TIMEOUT (30 * 24 * 3600.0)
-
-/* Timer for local reference */
-static SCH_TimeoutID local_timeout_id;
-
/* ================================================== */
static LOG_FileID logfileid;
correction_time_ratio = CNF_GetCorrectionTimeRatio();
enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_orphan, &local_distance);
- local_timeout_id = 0;
leap_timeout_id = 0;
leap_in_progress = 0;
/* ================================================== */
-static void
-local_timeout(void *arg)
-{
- local_timeout_id = 0;
- REF_SetUnsynchronised();
-}
-
-/* ================================================== */
-
-static void
-update_local_timeout(void)
-{
- double delay;
-
- SCH_RemoveTimeout(local_timeout_id);
- local_timeout_id = 0;
-
- if (!enable_local_stratum || !are_we_synchronised)
- return;
-
- /* Add a timer that will activate the local reference approximately at the
- point when our root distance reaches the configured root distance */
- delay = (local_distance - (our_root_delay / 2.0 + our_root_dispersion)) /
- (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError());
- delay = CLAMP(0.0, delay, MAX_LOCAL_TIMEOUT);
- local_timeout_id = SCH_AddTimeoutByDelay(delay, local_timeout, NULL);
-
- DEBUG_LOG(LOGF_Reference, "Local reference timeout %f", delay);
-}
-
-/* ================================================== */
-
static void
write_log(struct timeval *ref_time, char *ref, int stratum, NTP_Leap leap,
double freq, double skew, double offset, int combined_sources,
}
}
- /* Update timer that activates the local reference */
- update_local_timeout();
-
/* Update fallback drifts */
if (fb_drifts) {
update_fb_drifts(abs_freq_ppm, update_interval);
update_leap_status(LEAP_Unsynchronised, 0, 0);
are_we_synchronised = 0;
- update_local_timeout();
LCL_SetSyncStatus(0, 0.0, 0.0);
double *root_dispersion
)
{
- double elapsed;
- double extra_dispersion;
+ double elapsed, dispersion;
assert(initialised);
if (are_we_synchronised) {
+ UTI_DiffTimevalsToDouble(&elapsed, local_time, &our_ref_time);
+ dispersion = our_root_dispersion +
+ (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
+ } else {
+ dispersion = 0.0;
+ }
+
+ /* Local reference is active when enabled and the clock is not synchronised
+ or the root distance exceeds the threshold */
+
+ if (are_we_synchronised &&
+ !(enable_local_stratum && our_root_delay / 2 + dispersion > local_distance)) {
*is_synchronised = 1;
*stratum = our_stratum;
- UTI_DiffTimevalsToDouble(&elapsed, local_time, &our_ref_time);
- extra_dispersion = (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
-
*leap_status = !leap_in_progress ? our_leap_status : LEAP_Unsynchronised;
*ref_id = our_ref_id;
*ref_time = our_ref_time;
*root_delay = our_root_delay;
- *root_dispersion = our_root_dispersion + extra_dispersion;
+ *root_dispersion = dispersion;
} else if (enable_local_stratum) {
int
REF_GetOurStratum(void)
{
- if (are_we_synchronised) {
- return our_stratum;
- } else if (enable_local_stratum) {
- return local_stratum;
- } else {
- return NTP_MAX_STRATUM;
- }
+ struct timeval now_cooked, ref_time;
+ int synchronised, stratum;
+ NTP_Leap leap_status;
+ uint32_t ref_id;
+ double root_delay, root_dispersion;
+
+ SCH_GetLastEventTime(&now_cooked, NULL, NULL);
+ REF_GetReferenceParams(&now_cooked, &synchronised, &leap_status, &stratum,
+ &ref_id, &ref_time, &root_delay, &root_dispersion);
+
+ return stratum;
}
/* ================================================== */
local_stratum = CLAMP(1, stratum, NTP_MAX_STRATUM - 1);
local_distance = distance;
local_orphan = !!orphan;
-
- update_local_timeout();
}
/* ================================================== */
rep->last_offset = last_offset;
rep->rms_offset = sqrt(avg2_offset);
- if (are_we_synchronised) {
+ if (synchronised) {
rep->ip_addr = our_ref_ip;
rep->resid_freq_ppm = 1.0e6 * our_residual_freq;
rep->skew_ppm = 1.0e6 * our_skew;