From 24134c78e89b5c13c9a972dd6bfaf0c77083b368 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 5 Aug 2019 15:25:04 +0200 Subject: [PATCH] sourcestats: update offset estimate when regression fails If there are too few samples to make a regression, at least update the offset estimate from the last sample and keep the previous frequency offset unchanged. Also, reset the error estimates. --- sourcestats.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sourcestats.c b/sourcestats.c index 2c49272..a3f3c5f 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -54,6 +54,9 @@ /* The minimum standard deviation */ #define MIN_STDDEV 1.0e-9 +/* The worst case bound on an unknown standard deviation of the offset */ +#define WORST_CASE_STDDEV_BOUND 4.0 + /* The asymmetry of network jitter when all jitter is in one direction */ #define MAX_ASYMMETRY 0.5 @@ -249,9 +252,9 @@ SST_ResetInstance(SST_Stats inst) inst->estimated_frequency_sd = WORST_CASE_FREQ_BOUND; inst->skew = WORST_CASE_FREQ_BOUND; inst->estimated_offset = 0.0; - inst->estimated_offset_sd = 86400.0; /* Assume it's at least within a day! */ + inst->estimated_offset_sd = WORST_CASE_STDDEV_BOUND; UTI_ZeroTimespec(&inst->offset_time); - inst->std_dev = 4.0; + inst->std_dev = WORST_CASE_STDDEV_BOUND; inst->nruns = 0; inst->asymmetry_run = 0; inst->asymmetry = 0.0; @@ -603,9 +606,20 @@ SST_DoNewRegression(SST_Stats inst) times_back_start = inst->runs_samples + best_start; prune_register(inst, best_start); } else { - inst->estimated_frequency = 0.0; inst->estimated_frequency_sd = WORST_CASE_FREQ_BOUND; inst->skew = WORST_CASE_FREQ_BOUND; + inst->estimated_offset_sd = WORST_CASE_STDDEV_BOUND; + inst->std_dev = WORST_CASE_STDDEV_BOUND; + inst->nruns = 0; + + if (inst->n_samples > 0) { + inst->estimated_offset = inst->offsets[inst->last_sample]; + inst->offset_time = inst->sample_times[inst->last_sample]; + } else { + inst->estimated_offset = 0.0; + UTI_ZeroTimespec(&inst->offset_time); + } + times_back_start = 0; }