]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix frequency accumulation again
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 9 Jan 2014 15:34:59 +0000 (16:34 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 9 Jan 2014 17:30:14 +0000 (18:30 +0100)
This is a revert of commit 99d18abf updated for later changes. It seems
in that commit the calculation was changed to match the reversed dfreq
added in 1a7415a6, which itself was calculated incorrectly. Fix the
calculation of updated frequency and matching dfreq.

local.c
rtc_linux.c

diff --git a/local.c b/local.c
index 8de198edd0fca22f3efe1a0be5c2a910efb2b328..e4be12b6306872906b2c71f3324aae20c92f28b7 100644 (file)
--- a/local.c
+++ b/local.c
@@ -382,7 +382,7 @@ LCL_SetAbsoluteFrequency(double afreq_ppm)
   
   afreq_ppm = (*drv_set_freq)(afreq_ppm);
 
-  dfreq = (afreq_ppm - current_freq_ppm) / (1.0e6 + current_freq_ppm);
+  dfreq = (afreq_ppm - current_freq_ppm) / (1.0e6 - current_freq_ppm);
 
   LCL_ReadRawTime(&raw);
   LCL_CookTime(&raw, &cooked, NULL);
@@ -411,11 +411,11 @@ LCL_AccumulateDeltaFrequency(double dfreq)
    are handled in units of ppm, whereas the 'dfreq' argument is in
    terms of the gradient of the (offset) v (local time) function. */
 
-  current_freq_ppm = (1.0 + dfreq) * current_freq_ppm + 1.0e6 * dfreq;
+  current_freq_ppm = (1.0 - dfreq) * current_freq_ppm + 1.0e6 * dfreq;
 
   /* Call the system-specific driver for setting the frequency */
   current_freq_ppm = (*drv_set_freq)(current_freq_ppm);
-  dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 + old_freq_ppm);
+  dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 - old_freq_ppm);
 
   LCL_ReadRawTime(&raw);
   LCL_CookTime(&raw, &cooked, NULL);
@@ -508,14 +508,14 @@ LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
   /* Work out new absolute frequency.  Note that absolute frequencies
    are handled in units of ppm, whereas the 'dfreq' argument is in
    terms of the gradient of the (offset) v (local time) function. */
-  current_freq_ppm = (1.0 + dfreq) * old_freq_ppm + 1.0e6 * dfreq;
+  current_freq_ppm = (1.0 - dfreq) * old_freq_ppm + 1.0e6 * dfreq;
 
   DEBUG_LOG(LOGF_Local, "old_freq=%.3fppm new_freq=%.3fppm offset=%.6fsec",
       old_freq_ppm, current_freq_ppm, doffset);
 
   /* Call the system-specific driver for setting the frequency */
   current_freq_ppm = (*drv_set_freq)(current_freq_ppm);
-  dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 + old_freq_ppm);
+  dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 - old_freq_ppm);
 
   (*drv_accrue_offset)(doffset, corr_rate);
 
index fe52c336bdb71d443ac7e906fe9af71a5d5439e7..3fcf29765321bb5e7e94b017051f408c6277b4b9 100644 (file)
@@ -282,7 +282,7 @@ slew_samples
 
   if (coefs_valid) {
     coef_seconds_fast += doffset;
-    coef_gain_rate = (1.0 + dfreq) * (1.0 + coef_gain_rate) - 1.0;
+    coef_gain_rate = (1.0 - dfreq) * coef_gain_rate + dfreq;
   }
 
   DEBUG_LOG(LOGF_RtcLinux, "dfreq=%.8f doffset=%.6f old_fast=%.6f old_rate=%.3f new_fast=%.6f new_rate=%.3f",