]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Try to minimize adjtime error
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Jul 2009 13:49:05 +0000 (15:49 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Jul 2009 13:56:00 +0000 (15:56 +0200)
The offset is rounded before calling adjtime and the error below
microsecond is accumulated.

sys_linux.c

index 2da7ed517a403f4ec6ead55b613f1fd873efb718..c60a7d3c433d6daba8207b51928c11a37f1cbddb 100644 (file)
@@ -126,6 +126,17 @@ our_round(double x) {
   return y;
 }
 
+inline static long
+our_lround(double x) {
+  int y;
+
+  if (x > 0.0)
+         y = x + 0.5;
+  else
+         y = x - 0.5;
+  return y;
+}
+
 /* ================================================== */
 /* Amount of outstanding offset to process */
 static double offset_register;
@@ -255,14 +266,13 @@ initiate_slew(void)
 
   if (fabs(offset_register) < MAX_ADJUST_WITH_ADJTIME) {
     /* Use adjtime to do the shift */
-    offset = (long)(0.5 + 1.0e6*(-offset_register));
+    offset = our_lround(1.0e6 * -offset_register);
+
+    offset_register += offset * 1e-6;
 
     if (TMX_ApplyOffset(&offset) < 0) {
       CROAK("adjtimex() failed in initiate_slew");
     }
-
-    offset_register = 0.0;
-
   } else {
 
     /* If the system clock has a high drift rate, the combination of