hwclock: drop all samples on reset
On some HW it seems it's possible to get an occasional bad reading of the PHC (with normal delay), or in a worse case the clock can step due to a HW/driver bug, which triggers reset of the HW clock instance. To avoid having a bad estimate of the frequency when the next (good) sample is accumulated, drop also the last sample which triggered the reset.
This commit is contained in:
parent
27cbf20d23
commit
6dad2c24bf
2 changed files with 6 additions and 6 deletions
10
hwclock.c
10
hwclock.c
|
@ -174,12 +174,12 @@ HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
|
|||
/* Drop unneeded samples */
|
||||
clock->n_samples -= best_start;
|
||||
|
||||
/* If the fit doesn't cross the error interval of the last sample, throw away
|
||||
all previous samples and keep only the frequency estimate */
|
||||
/* If the fit doesn't cross the error interval of the last sample,
|
||||
throw away all samples and start again */
|
||||
if (fabs(clock->offset) > err) {
|
||||
DEBUG_LOG("HW clock reset offset=%e", clock->offset);
|
||||
clock->offset = 0.0;
|
||||
clock->n_samples = 1;
|
||||
DEBUG_LOG("HW clock reset");
|
||||
clock->n_samples = 0;
|
||||
clock->valid_coefs = 0;
|
||||
}
|
||||
|
||||
DEBUG_LOG("HW clock samples=%d offset=%e freq=%.9e raw_freq=%.9e err=%e ref_diff=%e",
|
||||
|
|
|
@ -65,7 +65,7 @@ test_unit(void)
|
|||
if (HCL_NeedsNewSample(clock, &local_ts))
|
||||
HCL_AccumulateSample(clock, &hw_ts, &local_ts, 2.0 * jitter);
|
||||
|
||||
TEST_CHECK(j < 20 || clock->valid_coefs);
|
||||
TEST_CHECK(clock->valid_coefs || clock->n_samples < 2);
|
||||
|
||||
if (!clock->valid_coefs)
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue