hwclock: make minimum sampling separation configurable

This commit is contained in:
Miroslav Lichvar 2017-01-19 12:45:44 +01:00
parent 1436d9961f
commit 9800e397fb
4 changed files with 11 additions and 10 deletions

View file

@ -39,9 +39,6 @@
/* Maximum number of samples per clock */
#define MAX_SAMPLES 16
/* Minimum interval between samples (in seconds) */
#define MIN_SAMPLE_SEPARATION 1.0
struct HCL_Instance_Record {
/* HW and local reference timestamp */
struct timespec hw_ref;
@ -58,6 +55,9 @@ struct HCL_Instance_Record {
/* Maximum error of the last sample */
double last_err;
/* Minimum interval between samples */
double min_separation;
/* Flag indicating the offset and frequency values are valid */
int valid_coefs;
@ -86,7 +86,7 @@ handle_slew(struct timespec *raw, struct timespec *cooked, double dfreq,
/* ================================================== */
HCL_Instance
HCL_CreateInstance(void)
HCL_CreateInstance(double min_separation)
{
HCL_Instance clock;
@ -95,6 +95,7 @@ HCL_CreateInstance(void)
clock->y_data[MAX_SAMPLES - 1] = 0.0;
clock->n_samples = 0;
clock->valid_coefs = 0;
clock->min_separation = min_separation;
LCL_AddParameterChangeHandler(handle_slew, clock);
@ -115,7 +116,7 @@ int
HCL_NeedsNewSample(HCL_Instance clock, struct timespec *now)
{
if (!clock->n_samples ||
fabs(UTI_DiffTimespecsToDouble(now, &clock->local_ref)) >= MIN_SAMPLE_SEPARATION)
fabs(UTI_DiffTimespecsToDouble(now, &clock->local_ref)) >= clock->min_separation)
return 1;
return 0;
@ -140,7 +141,7 @@ HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
hw_delta = UTI_DiffTimespecsToDouble(hw_ts, &clock->hw_ref);
local_delta = UTI_DiffTimespecsToDouble(local_ts, &clock->local_ref) / local_freq;
if (hw_delta <= 0.0 || local_delta < MIN_SAMPLE_SEPARATION / 2.0) {
if (hw_delta <= 0.0 || local_delta < clock->min_separation / 2.0) {
clock->n_samples = 0;
DEBUG_LOG(LOGF_HwClocks, "HW clock reset interval=%f", local_delta);
}

View file

@ -29,7 +29,7 @@
typedef struct HCL_Instance_Record *HCL_Instance;
/* Create a new HW clock instance */
extern HCL_Instance HCL_CreateInstance(void);
extern HCL_Instance HCL_CreateInstance(double min_separation);
/* Destroy a HW clock instance */
extern void HCL_DestroyInstance(HCL_Instance clock);

View file

@ -179,7 +179,7 @@ add_interface(CNF_HwTsInterface *conf_iface)
iface->tx_comp = conf_iface->tx_comp;
iface->rx_comp = conf_iface->rx_comp;
iface->clock = HCL_CreateInstance();
iface->clock = HCL_CreateInstance(1.0);
DEBUG_LOG(LOGF_NtpIOLinux, "Enabled HW timestamping on %s", iface->name);

View file

@ -31,7 +31,7 @@ test_unit(void)
LCL_Initialise();
clock = HCL_CreateInstance();
clock = HCL_CreateInstance(1.0);
for (i = 0; i < 2000; i++) {
UTI_ZeroTimespec(&start_hw_ts);
@ -43,7 +43,7 @@ test_unit(void)
freq = TST_GetRandomDouble(0.9, 1.1);
jitter = TST_GetRandomDouble(10.0e-9, 1000.0e-9);
interval = TST_GetRandomDouble(MIN_SAMPLE_SEPARATION / 10, MIN_SAMPLE_SEPARATION * 10.0);
interval = TST_GetRandomDouble(0.1, 10.0);
clock->n_samples = 0;
clock->valid_coefs = 0;