| [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
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [RFC PATCH v1 08/17] sys_timex: Add interface enabling platform initialization code to set an alternative clock ID
- From: Christopher S M Hall <christopher.s.hall@xxxxxxxxx>
- Date: Sat, 6 Dec 2025 06:10:54 +0000
- Cc: christopher.s.hall@xxxxxxxxx, david.zage@xxxxxxxxx, yoong.siang.song@xxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765002155; x=1796538155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LAKaJn6xc/bY9RHj7bBxftObDlR6adLZENAfsiUBSLk=; b=C0L3q/TstXhuVr9Vz9UZI5MkOH3QTmNMPJBwT6x4985Q/sR5alVaEuy4 SyqlgP/PaVRNXEI50BbfIA0GCm8iiJrBKTZaBmRQpSB9CRxjEBW2RGmIE RNETEF4JkDNrWLtm5Y4aJdrfE8LTUfcC2Ajy0FEF7UDKR8Lyp1f+WdCPt brh3QWkzKfnKPeXGgA+5Ia8/nrWfFjIcRdvg783LwBFB7TSy0dvH1SrN/ if1Es9SV0ab76i3OwsbXA6CTSP/brXU/glzq/KXxJHMMPOTFfANY9D7u8 OpLHmxekjpr6FaHOnrJslgDjDY2/IhZfxs0LDGqKxiaB9ByEYJMsTpyG0 A==;
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.