mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
refclock: rework update of reachability again
The recent rework of refclock reachability to better work with
driver-specific filtering (PHC driver dropping samples with unexpected
delay) introduced an issue that a PPS refclock is indicated as reachable
even when its "lock" refclock is permanently unreachable, or its samples
constistently fail in other sample checks, and no actual samples can be
accumulated. This breaks the new maxunreach option.
Rework the refclock code to provide samples from drivers together with
their quality level (all drivers except PHC provide samples with
constant quality of 1) and drop samples with quality 0 after passing
all checks, right before the actual accumulation in the median sample
filter. Increment the reachability counter only for samples that would
be accumulated.
This fixes the problem with refclocks indicated as reachable when their
samples would be dropped for other reasons than the PHC-specific delay
filter, and the maxunreach option can work as expected.
Fixes: b9b338a8df ("refclock: rework update of reachability")
This commit is contained in:
33
refclock.c
33
refclock.c
@@ -427,10 +427,21 @@ convert_tai_offset(struct timespec *sample_time, double *offset)
|
||||
}
|
||||
|
||||
static int
|
||||
accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double offset, double dispersion)
|
||||
accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double offset, double dispersion,
|
||||
int quality)
|
||||
{
|
||||
NTP_Sample sample;
|
||||
|
||||
instance->reached++;
|
||||
|
||||
/* Don't accumulate the sample if the driver is suggesting it should be
|
||||
dropped due to low quality. The only reason it went so far was to update
|
||||
the reachability. */
|
||||
if (quality < 1) {
|
||||
DEBUG_LOG("refclock sample ignored quality=%d", quality);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sample.time = *sample_time;
|
||||
sample.offset = offset;
|
||||
sample.peer_delay = instance->delay;
|
||||
@@ -443,14 +454,14 @@ accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double of
|
||||
|
||||
int
|
||||
RCL_AddSample(RCL_Instance instance, struct timespec *sample_time,
|
||||
struct timespec *ref_time, int leap)
|
||||
struct timespec *ref_time, int leap, int quality)
|
||||
{
|
||||
double correction, dispersion, raw_offset, offset;
|
||||
struct timespec cooked_time;
|
||||
|
||||
if (instance->pps_forced)
|
||||
return RCL_AddPulse(instance, sample_time,
|
||||
1.0e-9 * (sample_time->tv_nsec - ref_time->tv_nsec));
|
||||
1.0e-9 * (sample_time->tv_nsec - ref_time->tv_nsec), quality);
|
||||
|
||||
raw_offset = UTI_DiffTimespecsToDouble(ref_time, sample_time);
|
||||
|
||||
@@ -486,7 +497,7 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!accumulate_sample(instance, &cooked_time, offset, dispersion))
|
||||
if (!accumulate_sample(instance, &cooked_time, offset, dispersion, quality))
|
||||
return 0;
|
||||
|
||||
instance->pps_active = 0;
|
||||
@@ -501,7 +512,7 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time,
|
||||
}
|
||||
|
||||
int
|
||||
RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second)
|
||||
RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second, int quality)
|
||||
{
|
||||
double correction, dispersion;
|
||||
struct timespec cooked_time;
|
||||
@@ -513,7 +524,7 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second)
|
||||
if (!UTI_IsTimeOffsetSane(pulse_time, 0.0))
|
||||
return 0;
|
||||
|
||||
return RCL_AddCookedPulse(instance, &cooked_time, second, dispersion, correction);
|
||||
return RCL_AddCookedPulse(instance, &cooked_time, second, dispersion, correction, quality);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -539,7 +550,7 @@ check_pulse_edge(RCL_Instance instance, double offset, double distance)
|
||||
|
||||
int
|
||||
RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time,
|
||||
double second, double dispersion, double raw_correction)
|
||||
double second, double dispersion, double raw_correction, int quality)
|
||||
{
|
||||
double offset;
|
||||
int rate;
|
||||
@@ -641,7 +652,7 @@ RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!accumulate_sample(instance, cooked_time, offset, dispersion))
|
||||
if (!accumulate_sample(instance, cooked_time, offset, dispersion, quality))
|
||||
return 0;
|
||||
|
||||
instance->leap_status = leap;
|
||||
@@ -657,12 +668,6 @@ RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time,
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
RCL_UpdateReachability(RCL_Instance instance)
|
||||
{
|
||||
instance->reached++;
|
||||
}
|
||||
|
||||
double
|
||||
RCL_GetPrecision(RCL_Instance instance)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user