]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Remove unnecessary adjtimex calls
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Jun 2013 17:38:36 +0000 (19:38 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Jun 2013 17:38:36 +0000 (19:38 +0200)
ntp_core.c
ntp_io.c
reference.c
sources.c
util.c
util.h

index 73a877ad76d4f99e68e772edbe6ee8a025c91f74..4dca216cd1fecddb442f39dbe1bc1f73b934ef24 100644 (file)
@@ -570,7 +570,10 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
     version = NTP_VERSION;
   }
 
-  LCL_ReadCookedTime(&local_transmit, NULL);
+  /* This is accurate enough and cheaper than calling LCL_ReadCookedTime.
+     A more accurate time stamp will be taken later in this function. */
+  SCH_GetLastEventTime(&local_transmit, NULL, NULL);
+
   REF_GetReferenceParams(&local_transmit,
                          &are_we_synchronised, &leap_status,
                          &our_stratum,
index 3dc4ace93ddc8971f9a6216b9fe76f565625331e..803be915d9521037615151851040d9bcd2382653 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -296,7 +296,7 @@ read_from_socket(void *anything)
   ReceiveBuffer message;
   union sockaddr_in46 where_from;
   unsigned int flags = 0;
-  struct timeval now;
+  struct timeval now, now_raw;
   double now_err;
   NTP_Remote_Address remote_addr;
   char cmsgbuf[256];
@@ -306,7 +306,7 @@ read_from_socket(void *anything)
 
   assert(initialised);
 
-  SCH_GetLastEventTime(&now, &now_err, NULL);
+  SCH_GetLastEventTime(&now, &now_err, &now_raw);
 
   iov.iov_base = message.arbitrary;
   iov.iov_len = sizeof(message);
@@ -376,7 +376,9 @@ read_from_socket(void *anything)
         struct timeval tv;
 
         memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
-        LCL_CookTime(&tv, &now, &now_err);
+
+        /* This should be more accurate than LCL_CookTime(&now_raw,...) */
+        UTI_AddDiffToTimeval(&now, &now_raw, &tv, &now);
       }
 #endif
     }
index 615a70728faca0c2c7464d5f791c114fd0c2fb5c..5368bc5856dc2fa73750c8dbea631d89260bdc29 100644 (file)
@@ -684,7 +684,7 @@ REF_SetReference(int stratum,
   double update_interval;
   double elapsed;
   double correction_rate;
-  struct timeval now, raw_now;
+  struct timeval now, raw_now, ev_now, ev_raw_now;
 
   assert(initialised);
 
@@ -713,7 +713,10 @@ REF_SetReference(int stratum,
   }
     
   LCL_ReadRawTime(&raw_now);
-  LCL_CookTime(&raw_now, &now, NULL);
+
+  /* This is cheaper than calling LCL_CookTime */
+  SCH_GetLastEventTime(&ev_now, NULL, &ev_raw_now);
+  UTI_AddDiffToTimeval(&ev_now, &ev_raw_now, &raw_now, &now);
 
   UTI_DiffTimevalsToDouble(&elapsed, &now, ref_time);
   our_offset = offset + elapsed * frequency;
index 2c8aa1e81963929f9b2a3b8b3308dd7188ca94b0..6bbf319e9ec74a43da103f1b5898462c45ff4a4c 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -44,6 +44,7 @@
 #include "reports.h"
 #include "nameserv.h"
 #include "mkdirpp.h"
+#include "sched.h"
 
 /* ================================================== */
 /* Flag indicating that we are initialised */
@@ -448,7 +449,8 @@ SRC_SelectSource(uint32_t match_refid)
     return;
   }
 
-  LCL_ReadCookedTime(&now, NULL);
+  /* This is accurate enough and cheaper than calling LCL_ReadCookedTime */
+  SCH_GetLastEventTime(&now, NULL, NULL);
 
   /* Step 1 - build intervals about each source */
   n_endpoints = 0;
diff --git a/util.c b/util.c
index aedabebfa83508f42b4a119e6beadc0f8fdf4886..cb8c2a17863fb15898d573ea2fdb6211467a405b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -188,6 +188,18 @@ UTI_AverageDiffTimevals (struct timeval *earlier,
 
 /* ================================================== */
 
+void
+UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b,
+                     struct timeval *c, struct timeval *result)
+{
+  double diff;
+
+  UTI_DiffTimevalsToDouble(&diff, a, b);
+  UTI_AddDoubleToTimeval(c, diff, result);
+}
+
+/* ================================================== */
+
 #define POOL_ENTRIES 16
 #define BUFFER_LENGTH 64
 static char buffer_pool[POOL_ENTRIES][BUFFER_LENGTH];
diff --git a/util.h b/util.h
index 02fb6fbf0e5d0d04761fb8ecc25badb16d836a4b..774509c2d77a68b8b4de117eeecb926b73c79bc7 100644 (file)
--- a/util.h
+++ b/util.h
@@ -63,6 +63,9 @@ extern void UTI_AddDoubleToTimeval(struct timeval *start, double increment, stru
 /* Calculate the average and difference (as a double) of two timevals */
 extern void UTI_AverageDiffTimevals(struct timeval *earlier, struct timeval *later, struct timeval *average, double *diff);
 
+/* Calculate result = a - b + c */
+extern void UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b, struct timeval *c, struct timeval *result);
+
 /* Convert a timeval into a temporary string, largely for diagnostic
    display */
 extern char *UTI_TimevalToString(struct timeval *tv);