[chrony-dev] [RFC PATCH v1 08/17] sys_timex: Add interface enabling platform initialization code to set an alternative clock ID

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


Calls to sys_timex.c assume the clock ID is default CLOCK_REALTIME. To use sys_timex code without changing
many of the APIs, add a call SYS_Timex_SetClockId() to set the clock ID that will be used for all calls
to sys_timex.c.
---
 sys_timex.c | 25 +++++++++++++++++++++++++
 sys_timex.h |  4 ++++
 2 files changed, 29 insertions(+)

diff --git a/sys_timex.c b/sys_timex.c
index 3c2eb52..119d1f1 100644
--- a/sys_timex.c
+++ b/sys_timex.c
@@ -47,10 +47,14 @@
 #define NTP_ADJTIME adjtimex
 #define NTP_ADJTIME_NAME "adjtimex"
 #else
+#ifdef HAVE_CLOCK_ADJTIME
+#define NTP_ADJTIME_NAME "clock_adjtime"
+#else
 #define NTP_ADJTIME ntp_adjtime
 #define NTP_ADJTIME_NAME "ntp_adjtime"
 #endif
 #endif
+#endif
 
 /* Maximum frequency offset accepted by the kernel (in ppm) */
 #define MAX_FREQ 500.0
@@ -70,6 +74,12 @@ static int sys_status;
 /* Saved TAI-UTC offset */
 static int sys_tai_offset;
 
+#ifdef HAVE_CLOCK_ADJTIME
+static const int realtime = CLOCK_REALTIME;
+/* Clock ID used for clock_adjtime */
+static const int *clock_id = &realtime;
+#endif
+
 /* ================================================== */
 
 static double
@@ -219,6 +229,17 @@ initialise_timex(void)
 
 /* ================================================== */
 
+#ifdef HAVE_CLOCK_ADJTIME
+void
+SYS_Timex_SetClockId(const int *clockid_arg)
+{
+  if (clockid_arg != NULL)
+    clock_id = clockid_arg;
+}
+#endif
+
+/* ================================================== */
+
 void
 SYS_Timex_Initialise(void)
 {
@@ -271,7 +292,11 @@ SYS_Timex_Adjust(struct timex *txc, int ignore_error)
     txc->constant = 10;
 #endif
 
+#ifndef HAVE_CLOCK_ADJTIME
   state = NTP_ADJTIME(txc);
+#else
+  state = clock_adjtime(*clock_id, txc);
+#endif
 
   if (state < 0) {
     LOG(ignore_error ? LOGS_DEBUG : LOGS_FATAL,
diff --git a/sys_timex.h b/sys_timex.h
index f3b3a80..830df1a 100644
--- a/sys_timex.h
+++ b/sys_timex.h
@@ -49,4 +49,8 @@ extern void SYS_Timex_Finalise(void);
 /* Wrapper for adjtimex()/ntp_adjtime() */
 extern int SYS_Timex_Adjust(struct timex *txc, int ignore_error);
 
+#ifdef HAVE_CLOCK_ADJTIME
+extern void SYS_Timex_SetClockId(const int *clockid_arg);
+#endif
+
 #endif  /* GOT_SYS_GENERIC_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/