]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Read local time immediately after select()
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 30 Nov 2009 12:19:55 +0000 (13:19 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 30 Nov 2009 12:27:34 +0000 (13:27 +0100)
This removes a small inaccuracy caused by delay between select() and
file handler calls.

acquire.c
ntp_io.c
rtc_linux.c
sched.c
sched.h

index 048f0a53bf46f7fea7c557f3bb02bd34307fb447..87df3534e0a4c626690225b13bdc183da6fdca61 100644 (file)
--- a/acquire.c
+++ b/acquire.c
@@ -436,7 +436,6 @@ read_from_socket(void *anything)
   IPAddr remote_ip;
   int i, ok;
   struct timeval now;
-  double local_time_err;
   SourceRecord *src;
 
   flags = 0;
@@ -444,7 +443,7 @@ read_from_socket(void *anything)
   his_addr_len = sizeof(his_addr);
 
   /* Get timestamp */
-  LCL_ReadCookedTime(&now, &local_time_err);
+  SCH_GetFileReadyTime(&now);
 
   sock_fd = (long)anything;
   status = recvfrom (sock_fd, (char *)&msg, message_length, flags,
index 98edc69595b2ae7c338089c1fab875a9faa2cdaf..1c897bb2a1632c674525cbef10accf03f806e183 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -275,7 +275,6 @@ read_from_socket(void *anything)
   unsigned int flags = 0;
   struct timeval now;
   NTP_Remote_Address remote_addr;
-  double local_clock_err;
   char cmsgbuf[256];
   struct msghdr msg;
   struct iovec iov;
@@ -283,7 +282,7 @@ read_from_socket(void *anything)
 
   assert(initialised);
 
-  LCL_ReadCookedTime(&now, &local_clock_err);
+  SCH_GetFileReadyTime(&now);
 
   iov.iov_base = message.arbitrary;
   iov.iov_len = sizeof(message);
index 0009817cf9003677557159224a85a13b4c317a99..dfdad99c4b3aec838d45ab9dc52511eac276c4da 100644 (file)
@@ -872,7 +872,6 @@ read_from_device(void *any)
   struct rtc_time rtc_raw;
   struct tm rtc_tm;
   time_t rtc_t;
-  double read_err;
   int error = 0;
 
   status = read(fd, &data, sizeof(data));
@@ -905,7 +904,7 @@ read_from_device(void *any)
     /* Read RTC time, sandwiched between two polls of the system clock
        so we can bound any error. */
 
-    LCL_ReadCookedTime(&sys_time, &read_err);
+    SCH_GetFileReadyTime(&sys_time);
 
     status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
     if (status < 0) {
diff --git a/sched.c b/sched.c
index 3e44a8da00a9e161065587fe2c1f57130f335265..e20054a2b18270a0a09fb5961ceb886dc8dd63ec 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -71,6 +71,9 @@ typedef struct {
 
 static FileHandlerEntry file_handlers[FD_SET_SIZE];
 
+/* Last timestamp when a file descriptor became readable */
+static struct timeval last_fdready;
+
 /* ================================================== */
 
 /* Variables to handler the timer queue */
@@ -225,6 +228,14 @@ SCH_RemoveInputFileHandler(int fd)
 
 /* ================================================== */
 
+void
+SCH_GetFileReadyTime(struct timeval *tv)
+{
+  *tv = last_fdready;
+}
+
+/* ================================================== */
+
 #define TQE_ALLOC_QUANTUM 32
 
 static TimerQueueEntry *
@@ -514,6 +525,7 @@ SCH_MainLoop(void)
   int status;
   struct timeval tv, *ptv;
   struct timeval now;
+  double err;
 
   if (!initialised) {
     CROAK("Should be initialised");
@@ -551,6 +563,7 @@ SCH_MainLoop(void)
     }
 
     status = select(one_highest_fd, &rd, NULL, NULL, ptv);
+    LCL_ReadCookedTime(&last_fdready, &err);
 
     if (status < 0) {
       if (!need_to_exit)
diff --git a/sched.h b/sched.h
index 4e4d98d4732c42cfed9c15364570b6918da4b3ce..0aea7ff9112cf7049597bf20462294dcc152d345 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -60,6 +60,10 @@ extern void SCH_AddInputFileHandler
 );
 extern void SCH_RemoveInputFileHandler(int fd);
 
+/* Get the time (cooked) when file descriptor became ready, intended for use
+   in file handlers */
+extern void SCH_GetFileReadyTime(struct timeval *tv);
+
 /* This queues a timeout to elapse at a given (raw) local time */
 extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);