From 73c548ad01f6f4d633bcc52ff123b7e59d7263ee Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 24 May 2017 13:50:39 +0200 Subject: [PATCH] sourcestats: handle negative elapsed time in SST_GetSelectionData() Source selection uses the last event time as current time. If it was called from a refclock which generates a sample in its poll function (e.g. PHC), the sample time may be later than the event time. This gives a negative elapsed time in SST_GetSelectionData() and possibly also a negative root distance, which causes the source to be rejected as a falseticker. Use absolute value of the difference in order to always get a positive root distance. --- sourcestats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sourcestats.c b/sourcestats.c index d3dea69..d8d4246 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -624,7 +624,7 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now, *stratum = inst->strata[get_buf_index(inst, inst->n_samples - 1)]; *std_dev = inst->std_dev; - sample_elapsed = UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]); + sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i])); offset = inst->offsets[i] + sample_elapsed * inst->estimated_frequency; *root_distance = 0.5 * inst->root_delays[j] + inst->root_dispersions[j] + sample_elapsed * inst->skew;