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.
This commit is contained in:
Miroslav Lichvar 2017-05-24 13:50:39 +02:00
parent 82203e12c8
commit 73c548ad01

View file

@ -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;