From f31f68ae8e79ac1dc91da83edade13f916eda7c3 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 11 May 2017 13:58:17 +0200 Subject: [PATCH] refclock: add option to treat non-PPS refclocks as PPS Add pps option to the refclock directive to force chronyd to treat any refclock as a PPS refclock. This is intended for refclocks that may provide time off by a whole number of seconds due to missing or wrong TAI/GPS->UTC conversion. --- conf.c | 7 ++++++- refclock.c | 5 +++++ refclock.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/conf.c b/conf.c index d400ee0..aafdba3 100644 --- a/conf.c +++ b/conf.c @@ -674,7 +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; + int max_lock_age, pps_forced; uint32_t ref_id, lock_ref_id; double offset, delay, precision, max_dispersion; char *p, *cmd, *name, *param; @@ -684,6 +684,7 @@ parse_refclock(char *line) poll = 4; dpoll = 0; filter_length = 64; + pps_forced = 0; pps_rate = 0; min_samples = SRC_DEFAULT_MINSAMPLES; max_samples = SRC_DEFAULT_MAXSAMPLES; @@ -756,6 +757,9 @@ parse_refclock(char *line) } else if (!strcasecmp(cmd, "delay")) { if (sscanf(line, "%lf%n", &delay, &n) != 1) break; + } else if (!strcasecmp(cmd, "pps")) { + n = 0; + pps_forced = 1; } else if (!strcasecmp(cmd, "precision")) { if (sscanf(line, "%lf%n", &precision, &n) != 1) break; @@ -791,6 +795,7 @@ parse_refclock(char *line) refclock->driver_poll = dpoll; refclock->poll = poll; refclock->filter_length = filter_length; + refclock->pps_forced = pps_forced; refclock->pps_rate = pps_rate; refclock->min_samples = min_samples; refclock->max_samples = max_samples; diff --git a/refclock.c b/refclock.c index 82643ae..706e2ba 100644 --- a/refclock.c +++ b/refclock.c @@ -75,6 +75,7 @@ struct RCL_Instance_Record { int driver_polled; int poll; int leap_status; + int pps_forced; int pps_rate; int pps_active; int max_lock_age; @@ -198,6 +199,7 @@ RCL_AddRefclock(RefclockParameters *params) inst->poll = params->poll; inst->driver_polled = 0; inst->leap_status = LEAP_Normal; + inst->pps_forced = params->pps_forced; inst->pps_rate = params->pps_rate; inst->pps_active = 0; inst->max_lock_age = params->max_lock_age; @@ -362,6 +364,9 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset double correction, dispersion; struct timespec cooked_time; + if (instance->pps_forced) + return RCL_AddPulse(instance, sample_time, -offset); + LCL_GetOffsetCorrection(sample_time, &correction, &dispersion); UTI_AddDoubleToTimespec(sample_time, correction, &cooked_time); dispersion += instance->precision; diff --git a/refclock.h b/refclock.h index 1fc5f92..a4201c2 100644 --- a/refclock.h +++ b/refclock.h @@ -37,6 +37,7 @@ typedef struct { int driver_poll; int poll; int filter_length; + int pps_forced; int pps_rate; int min_samples; int max_samples;