diff --git a/conf.c b/conf.c index be3a189..7500fd9 100644 --- a/conf.c +++ b/conf.c @@ -674,6 +674,7 @@ static void parse_refclock(char *line) { int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options; + int max_lock_age; uint32_t ref_id, lock_ref_id; double offset, delay, precision, max_dispersion; char *p, *cmd, *name, *param; @@ -692,6 +693,7 @@ parse_refclock(char *line) precision = 0.0; max_dispersion = 0.0; ref_id = 0; + max_lock_age = 2; lock_ref_id = 0; if (!*line) { @@ -742,6 +744,9 @@ parse_refclock(char *line) } else if (!strcasecmp(cmd, "minsamples")) { if (sscanf(line, "%d%n", &min_samples, &n) != 1) break; + } else if (!strcasecmp(cmd, "maxlockage")) { + if (sscanf(line, "%d%n", &max_lock_age, &n) != 1) + break; } else if (!strcasecmp(cmd, "maxsamples")) { if (sscanf(line, "%d%n", &max_samples, &n) != 1) break; @@ -795,6 +800,7 @@ parse_refclock(char *line) refclock->precision = precision; refclock->max_dispersion = max_dispersion; refclock->ref_id = ref_id; + refclock->max_lock_age = max_lock_age; refclock->lock_ref_id = lock_ref_id; } diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 123666a..6e9ab90 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -434,6 +434,11 @@ This option sets the rate of the pulses in the PPS signal (in Hz). This option controls how the pulses will be completed with real time. To actually receive more than one pulse per second, a negative *dpoll* has to be specified (-3 for a 5Hz signal). The default is 1. +*maxlockage* _pulses_::: +This option specifies in number of pulses how old can be samples from the +refclock specified by the *lock* option to be paired with the pulses. +Increasing this value is useful when the samples are produced at a lower rate +than the pulses. The default is 2. *offset* _offset_::: This option can be used to compensate for a constant error. The specified offset (in seconds) is applied to all samples produced by the reference clock. diff --git a/refclock.c b/refclock.c index 1fceea4..4686af0 100644 --- a/refclock.c +++ b/refclock.c @@ -77,6 +77,7 @@ struct RCL_Instance_Record { int leap_status; int pps_rate; int pps_active; + int max_lock_age; struct MedianFilter filter; uint32_t ref_id; uint32_t lock_ref; @@ -202,6 +203,7 @@ RCL_AddRefclock(RefclockParameters *params) inst->leap_status = LEAP_Normal; inst->pps_rate = params->pps_rate; inst->pps_active = 0; + inst->max_lock_age = params->max_lock_age; inst->lock_ref = params->lock_ref_id; inst->offset = params->offset; inst->delay = params->delay; @@ -444,7 +446,7 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second) ref_dispersion += filter_get_avg_sample_dispersion(&lock_refclock->filter); sample_diff = UTI_DiffTimespecsToDouble(&cooked_time, &ref_sample_time); - if (fabs(sample_diff) >= 2.0 / rate) { + if (fabs(sample_diff) >= (double)instance->max_lock_age / rate) { DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored samplediff=%.9f", sample_diff); return 0; diff --git a/refclock.h b/refclock.h index e4781f0..7b76c23 100644 --- a/refclock.h +++ b/refclock.h @@ -41,6 +41,7 @@ typedef struct { int min_samples; int max_samples; int sel_options; + int max_lock_age; uint32_t ref_id; uint32_t lock_ref_id; double offset;