From e0009f9f40c3efbe041d05b911a784cfca66e247 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 15 Apr 2010 15:48:31 +0200 Subject: [PATCH] Update drift file at most once per hour Instead of writing to the file on every reference update, update it on first update, on exit and otherwise only once per hour. --- reference.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/reference.c b/reference.c index df31420..19cb8ad 100644 --- a/reference.c +++ b/reference.c @@ -76,6 +76,7 @@ static char *mail_change_user; /* Filename of the drift file. */ static char *drift_file=NULL; +static double drift_file_age; static void update_drift_file(double, double); @@ -155,7 +156,7 @@ REF_Initialise(void) drift_file); } - update_drift_file(our_frequency_ppm,our_skew); + drift_file_age = 0.0; } LCL_SetAbsoluteFrequency(our_frequency_ppm); @@ -201,6 +202,10 @@ REF_Finalise(void) LCL_SetLeap(0); } + if (drift_file && drift_file_age > 0.0) { + update_drift_file(LCL_ReadAbsoluteFrequency(), our_skew); + } + Free(fb_drifts); initialised = 0; @@ -531,6 +536,8 @@ REF_SetReference(int stratum, double abs_freq_ppm; + double update_interval; + assert(initialised); /* Avoid getting NaNs */ @@ -630,21 +637,25 @@ REF_SetReference(int stratum, 1.0e6*our_skew, our_offset); + UTI_DiffTimevalsToDouble(&update_interval, ref_time, &last_ref_update); + if (drift_file) { - update_drift_file(abs_freq_ppm, our_skew); + /* Update drift file at most once per hour */ + drift_file_age += update_interval; + if (drift_file_age < 0.0 || drift_file_age > 3600.0) { + update_drift_file(abs_freq_ppm, our_skew); + drift_file_age = 0.0; + } } /* Update fallback drifts */ if (fb_drifts) { - double update_interval; - - UTI_DiffTimevalsToDouble(&update_interval, ref_time, &last_ref_update); - update_fb_drifts(abs_freq_ppm, update_interval); - last_ref_update = *ref_time; - last_ref_update_interval = update_interval; } + last_ref_update = *ref_time; + last_ref_update_interval = update_interval; + /* And now set the freq and offset to zero */ our_frequency = 0.0; our_offset = 0.0;