[chrony-dev] [RFC PATCH v1 10/17] sys_linux, conf: Linux specific implementation of auxiliary clocks

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Add Linux implementation of get_auxclockid_first(),get_auxclockid_last():
SYS_Linux_GetAuxClockFirst(), SYS_Linux_GetAuxClockLast()

Currently only the PTP_SYS_OFFSET_EXTENDED ioctl is supported by Linux for use with auxiliary clocks.
Add check for use of an auxiliary clock with the PTP_SYS_OFFSET and PTP_SYS_OFFSET_PRECISE ioctls and
generate a fatal error if attempted.
---
 conf.c      |  7 +++++++
 sys_linux.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 sys_linux.h |  4 ++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/conf.c b/conf.c
index c3e3a4b..7bbf1f5 100644
--- a/conf.c
+++ b/conf.c
@@ -43,6 +43,7 @@
 #include "memory.h"
 #include "cmdparse.h"
 #include "util.h"
+#include "sys_linux.h"
 
 /* ================================================== */
 
@@ -2992,6 +2993,9 @@ CNF_GetNoCertTimeCheck(void)
 static int
 get_auxclockid_first(int *clockid)
 {
+#ifdef LINUX
+  return SYS_Linux_GetAuxClockFirst(clockid);
+#endif
   return -1;
 }
 
@@ -3000,6 +3004,9 @@ get_auxclockid_first(int *clockid)
 static int
 get_auxclockid_last(int *clockid)
 {
+#ifdef LINUX
+  return SYS_Linux_GetAuxClockLast(clockid);
+#endif
   return -1;
 }
 
diff --git a/sys_linux.c b/sys_linux.c
index fec61bd..bc34184 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -102,6 +102,11 @@ static double sys_hz;
    updated in the kernel */
 static int tick_update_hz;
 
+static const int realtime = CLOCK_REALTIME;
+/* Clock ID used for clock_adjtime */
+static const int *clock_id = &realtime;
+
+
 /* ================================================== */
 /* Positive means currently fast of true time, i.e. jump backwards */
 
@@ -331,6 +336,15 @@ report_time_adjust_blockers(void)
 void
 SYS_Linux_Initialise(void)
 {
+#if FEAT_AUXCLOCK
+  const int *l_clockid;
+  /* This must be first before calls to sys_timex.c */
+  l_clockid = CNF_GetAuxClockId();
+  if (l_clockid)
+    clock_id = l_clockid;
+  SYS_Timex_SetClockId(clock_id);
+#endif
+
   get_version_specific_details();
 
   report_time_adjust_blockers();
@@ -766,6 +780,10 @@ get_phc_readings(int phc_fd, int max_samples, struct timespec ts[][3])
   /* Silence valgrind */
   memset(&sys_off, 0, sizeof (sys_off));
 
+  if (clock_id != &realtime)
+    LOG_FATAL("PHC offset request for non-default clock id, but "
+	      "the kernel does not support it");
+
   sys_off.n_samples = max_samples;
 
   if (ioctl(phc_fd, PTP_SYS_OFFSET, &sys_off)) {
@@ -835,6 +853,10 @@ get_precise_phc_readings(int phc_fd, int max_samples, struct timespec ts[][3])
   /* Silence valgrind */
   memset(&sys_off, 0, sizeof (sys_off));
 
+  if (clock_id != &realtime)
+    LOG_FATAL("Precise PHC offset request for non-default clock id, but "
+	      "the kernel does not support it");
+
   if (ioctl(phc_fd, PTP_SYS_OFFSET_PRECISE, &sys_off)) {
     DEBUG_LOG("ioctl(%s) failed : %s", "PTP_SYS_OFFSET_PRECISE",
               strerror(errno));
@@ -1049,4 +1071,22 @@ SYS_Linux_ReadPHCExtTimestamp(int fd, struct timespec *phc_ts, int *channel)
   return 1;
 }
 
-#endif
+#ifdef FEAT_AUXCLOCK
+
+int
+SYS_Linux_GetAuxClockFirst(int *clockid)
+{
+  *clockid = CLOCK_AUX;
+  return 0;
+}
+
+
+int
+SYS_Linux_GetAuxClockLast(int *clockid)
+{
+  *clockid = CLOCK_AUX_LAST;
+  return 0;
+}
+
+#endif /* FEAT_AUXCLOCK */
+#endif /* FEAT_PHC || HAVE_LINUX_TIMESTAMPING */
diff --git a/sys_linux.h b/sys_linux.h
index 9760281..e81ff51 100644
--- a/sys_linux.h
+++ b/sys_linux.h
@@ -51,4 +51,8 @@ extern int SYS_Linux_SetPHCExtTimestamping(int fd, int pin, int channel,
 
 extern int SYS_Linux_ReadPHCExtTimestamp(int fd, struct timespec *phc_ts, int *channel);
 
+extern int SYS_Linux_GetAuxClockFirst(int *clockid);
+
+extern int SYS_Linux_GetAuxClockLast(int *clockid);
+
 #endif  /* GOT_SYS_LINUX_H */
-- 
2.34.1


-- 
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/