[chrony-dev] [RFC PATCH v1 11/17] sys_linux, configure: Add compile time check for updated ptp_sys_offset_extended struct

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


To support additional system clocks including auxiliary clocks, the Linux kernel added a clockid field
to struct ptp_sys_offset_extended. Add a compile time check to make sure this field is present and return
an error at runtime if it is not.

This is purposefully an independent compile time check from FEAT_AUXCLOCK because the PHC method is not
known until runtime.
---
 configure   | 13 +++++++++++++
 sys_linux.c |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/configure b/configure
index c1a7150..c6e3373 100755
--- a/configure
+++ b/configure
@@ -251,6 +251,8 @@ priv_ops=""
 feat_ipv6=1
 feat_phc=1
 try_phc=0
+feat_phcext_clockid=1
+try_phcext_clockid=0
 feat_pps=1
 try_setsched=0
 try_lockmem=0
@@ -443,6 +445,7 @@ case $OPERATINGSYSTEM in
         try_setsched=1
         try_lockmem=1
         try_phc=1
+	try_phcext_clockid=1
         try_arc4random=0
         try_clockadjtime=1
         try_auxclock=1
@@ -862,6 +865,16 @@ then
   add_def FEAT_PHC
 fi
 
+if [ $feat_phcext_clockid = "1" ] && [ $try_phcext_clockid = "1" ] && \
+     test_code 'PHC: PTP_SYS_OFFSET_EXTENDED accepts Clock ID' \
+     'linux/ptp_clock.h linux/time.h' '' '' \
+     'struct ptp_sys_offset_extended offset;
+      offset.clockid = CLOCK_REALTIME;
+      ioctl(1, PTP_SYS_OFFSET_EXTENDED, &offset);'
+then
+   add_def FEAT_PHCEXT_CLOCKID
+fi
+
 if [ $try_setsched = "1" ] && \
   test_code \
     'pthread_setschedparam()' \
diff --git a/sys_linux.c b/sys_linux.c
index bc34184..9258143 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -818,6 +818,13 @@ get_extended_phc_readings(int phc_fd, int max_samples, struct timespec ts[][3])
   memset(&sys_off, 0, sizeof (sys_off));
 
   sys_off.n_samples = max_samples;
+#ifdef FEAT_PHCEXT_CLOCKID
+  sys_off.clockid = *clock_id;
+#else
+  if (clock_id != &realtime)
+    LOG_FATAL("Extended PHC offset request for non-default clock id, but "
+	      "the kernel does not support it");
+#endif
 
   if (ioctl(phc_fd, PTP_SYS_OFFSET_EXTENDED, &sys_off)) {
     DEBUG_LOG("ioctl(%s) failed : %s", "PTP_SYS_OFFSET_EXTENDED", strerror(errno));
-- 
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/