]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
rtc: optionally return raw time from RTC_Linux_ReadTime*
authorAhmad Fatoum <a.fatoum@pengutronix.de>
Mon, 22 Jul 2024 15:41:47 +0000 (17:41 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Dec 2024 14:24:52 +0000 (15:24 +0100)
For use with RCL_AddSample in the incoming RTC reference clock driver,
we'll want access not to the cooked timestamps, but to the raw ones.

Otherwise, the core reference clock code complains:

  (valid_sample_time) RTC0 refclock sample time 1721242673.092211891
    not valid age=-3.092007

Support both use cases by have the RTC_Linux_ReadTime_* functions take
two nullable pointers, one for cooked and the other for raw time.

rtc_linux.c
rtc_linux.h

index 849bca053706270c0e9f21d16010a6541cfdfb8a..31f495b3d9d94a944fbc447be4172cd17a570f56 100644 (file)
@@ -786,7 +786,9 @@ RTC_Linux_CheckInterrupt(int fd)
 }
 
 time_t
-RTC_Linux_ReadTimeAfterInterrupt(int fd, int utc, struct timespec *sys_time_cooked)
+RTC_Linux_ReadTimeAfterInterrupt(int fd, int utc,
+                                 struct timespec *sys_time_cooked,
+                                 struct timespec *sys_time_raw)
 {
   int status;
   struct rtc_time rtc_raw;
@@ -794,7 +796,7 @@ RTC_Linux_ReadTimeAfterInterrupt(int fd, int utc, struct timespec *sys_time_cook
   /* Read RTC time, sandwiched between two polls of the system clock
      so we can bound any error */
 
-  SCH_GetLastEventTime(sys_time_cooked, NULL, NULL);
+  SCH_GetLastEventTime(sys_time_cooked, NULL, sys_time_raw);
 
   status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
   if (status < 0) {
@@ -825,7 +827,7 @@ read_from_device(int fd_, int event, void *any)
     return;
   }
 
-  rtc_t = RTC_Linux_ReadTimeAfterInterrupt(fd, rtc_on_utc, &sys_time);
+  rtc_t = RTC_Linux_ReadTimeAfterInterrupt(fd, rtc_on_utc, &sys_time, NULL);
   if (rtc_t == (time_t)-1) {
     error = 1;
     goto turn_off_interrupt;
@@ -930,7 +932,9 @@ RTC_Linux_WriteParameters(void)
 }
 
 time_t
-RTC_Linux_ReadTimeNow(int fd, int utc, struct timespec *old_sys_time)
+RTC_Linux_ReadTimeNow(int fd, int utc,
+                      struct timespec *old_sys_cooked,
+                      struct timespec *old_sys_raw)
 {
   struct rtc_time rtc_raw, rtc_raw_retry;
   int status;
@@ -946,7 +950,10 @@ RTC_Linux_ReadTimeNow(int fd, int utc, struct timespec *old_sys_time)
   } while (status >= 0 && rtc_raw.tm_sec != rtc_raw_retry.tm_sec);
 
   /* Read system clock */
-  LCL_ReadCookedTime(old_sys_time, NULL);
+  if (old_sys_raw)
+    LCL_ReadRawTime(old_sys_raw);
+  if (old_sys_cooked)
+    LCL_ReadCookedTime(old_sys_cooked, NULL);
 
   return status >= 0 ? t_from_rtc(&rtc_raw, utc) : -1;
 }
@@ -976,7 +983,7 @@ RTC_Linux_TimePreInit(time_t driftfile_time)
     return 0; /* Can't open it, and won't be able to later */
   }
 
-  rtc_t = RTC_Linux_ReadTimeNow(fd, rtc_on_utc, &old_sys_time);
+  rtc_t = RTC_Linux_ReadTimeNow(fd, rtc_on_utc, &old_sys_time, NULL);
 
   close(fd);
 
index c48b294d8547182740e5f8b6334c9e4ccd69bc53..831c4e9de122c59608ac60a305a113bc5bf435ff 100644 (file)
@@ -45,8 +45,10 @@ extern void RTC_Linux_CycleLogFile(void);
 extern int RTC_Linux_SwitchInterrupt(int fd, int on_off);
 extern int RTC_Linux_CheckInterrupt(int fd);
 extern time_t RTC_Linux_ReadTimeAfterInterrupt(int fd, int utc,
-                                               struct timespec *sys_time_cooked);
+                                               struct timespec *sys_time_cooked,
+                                               struct timespec *sys_time_raw);
 extern time_t RTC_Linux_ReadTimeNow(int fd, int utc,
-                                    struct timespec *sys_time_cooked);
+                                    struct timespec *sys_time_cooked,
+                                    struct timespec *sys_time_raw);
 
 #endif /* _GOT_RTC_LINUX_H */