mirror of
https://gitlab.com/chrony/chrony.git
synced 2026-01-21 05:10:19 -05:00
Add test for ratio of increase in delay to stddev
Require that the ratio of the increase in delay from the minimum one in the stats data register to the standard deviation of the offsets in the register is less than maxdelaydevratio or the difference between measured offset and predicted offset is larger than the increase in delay. In the allowed delay increase is included also skew and maximum clock frequency error. maxdelaydevratio is 10.0 by default.
This commit is contained in:
@@ -693,6 +693,45 @@ SST_MinRoundTripDelay(SST_Stats inst)
|
||||
return inst->peer_delays[inst->min_delay_sample];
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
SST_IsGoodSample(SST_Stats inst, double offset, double delay,
|
||||
double max_delay_dev_ratio, double clock_error, struct timeval *when)
|
||||
{
|
||||
double elapsed, allowed_increase, delay_increase;
|
||||
|
||||
if (inst->n_samples < 3)
|
||||
return 1;
|
||||
|
||||
UTI_DiffTimevalsToDouble(&elapsed, when, &inst->offset_time);
|
||||
|
||||
/* Require that the ratio of the increase in delay from the minimum to the
|
||||
standard deviation is less than max_delay_dev_ratio. In the allowed
|
||||
increase in delay include also skew and clock_error. */
|
||||
|
||||
allowed_increase = sqrt(inst->variance) * max_delay_dev_ratio +
|
||||
elapsed * (inst->skew + clock_error);
|
||||
delay_increase = (delay - SST_MinRoundTripDelay(inst)) / 2.0;
|
||||
|
||||
if (delay_increase < allowed_increase)
|
||||
return 1;
|
||||
|
||||
offset -= inst->estimated_offset + elapsed * inst->estimated_frequency;
|
||||
|
||||
/* Before we decide to drop the sample, make sure the difference between
|
||||
measured offset and predicted offset is not significantly larger than
|
||||
the increase in delay */
|
||||
if (fabs(offset) - delay_increase > allowed_increase)
|
||||
return 1;
|
||||
|
||||
#if 0
|
||||
LOG(LOGS_INFO, LOGF_SourceStats, "bad sample: offset=%f delay=%f incr_delay=%f allowed=%f", offset, delay, allowed_increase, delay_increase);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
/* This is used to save the register to a file, so that we can reload
|
||||
it after restarting the daemon */
|
||||
|
||||
Reference in New Issue
Block a user