From ff89d9c4a0c1a5198eb4fc34da895c2598516bdc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 2 Jun 2025 23:10:35 +0200 Subject: [PATCH] lsclocks: add auxiliary clocks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add support for the auxiliary posix clocks introduced in Linux 6.17. When auxiliary clocks are not supported, no output line is generated. When an auxiliary clock is not enabled an output line without TIME columns is generated. Signed-off-by: Thomas Weißschuh --- misc-utils/lsclocks.1.adoc | 1 + misc-utils/lsclocks.c | 35 ++++++++++++++++++++++++++++++++++- tests/ts/misc/lsclocks | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/misc-utils/lsclocks.1.adoc b/misc-utils/lsclocks.1.adoc index ffd3c40499..fd9ca96df8 100644 --- a/misc-utils/lsclocks.1.adoc +++ b/misc-utils/lsclocks.1.adoc @@ -25,6 +25,7 @@ Different kinds of clocks are supported. * CPU clocks: *clock_getcpuclockid()*. * PTP clocks: */dev/ptp0*. * RTC clocks: */dev/rtc0*. +* Auxiliary clocks: *CLOCK_AUX0*, *CLOCK_AUX1*, etc. == OPTIONS diff --git a/misc-utils/lsclocks.c b/misc-utils/lsclocks.c index 3fdec7ef2c..946b88be19 100644 --- a/misc-utils/lsclocks.c +++ b/misc-utils/lsclocks.c @@ -83,8 +83,27 @@ static inline clockid_t FD_TO_CLOCKID(int fd) #define CLOCK_TAI 11 #endif +#ifndef CLOCK_AUX +#define CLOCK_AUX 16 +#endif + +#define CLOCK_AUX0 (CLOCK_AUX + 0) +#define CLOCK_AUX1 (CLOCK_AUX + 1) +#define CLOCK_AUX2 (CLOCK_AUX + 2) +#define CLOCK_AUX3 (CLOCK_AUX + 3) +#define CLOCK_AUX4 (CLOCK_AUX + 4) +#define CLOCK_AUX5 (CLOCK_AUX + 5) +#define CLOCK_AUX6 (CLOCK_AUX + 6) +#define CLOCK_AUX7 (CLOCK_AUX + 7) + +static inline bool is_aux_clock(clockid_t clockid) +{ + return clockid >= CLOCK_AUX0 && clockid <= CLOCK_AUX7; +} + enum CLOCK_TYPE { CT_SYS, + CT_AUX, CT_PTP, CT_CPU, CT_RTC, @@ -95,6 +114,8 @@ static const char *clock_type_name(enum CLOCK_TYPE type) switch (type) { case CT_SYS: return "sys"; + case CT_AUX: + return "aux"; case CT_PTP: return "ptp"; case CT_CPU: @@ -126,6 +147,14 @@ static const struct clockinfo clocks[] = { { CT_SYS, CLOCK_REALTIME_ALARM, "CLOCK_REALTIME_ALARM", "realtime-alarm" }, { CT_SYS, CLOCK_BOOTTIME_ALARM, "CLOCK_BOOTTIME_ALARM", "boottime-alarm" }, { CT_SYS, CLOCK_TAI, "CLOCK_TAI", "tai" }, + { CT_AUX, CLOCK_AUX0, "CLOCK_AUX0", "auxiliary-0" }, + { CT_AUX, CLOCK_AUX1, "CLOCK_AUX1", "auxiliary-1" }, + { CT_AUX, CLOCK_AUX2, "CLOCK_AUX2", "auxiliary-2" }, + { CT_AUX, CLOCK_AUX3, "CLOCK_AUX3", "auxiliary-3" }, + { CT_AUX, CLOCK_AUX4, "CLOCK_AUX4", "auxiliary-4" }, + { CT_AUX, CLOCK_AUX5, "CLOCK_AUX5", "auxiliary-5" }, + { CT_AUX, CLOCK_AUX6, "CLOCK_AUX6", "auxiliary-6" }, + { CT_AUX, CLOCK_AUX7, "CLOCK_AUX7", "auxiliary-7" }, }; /* column IDs */ @@ -358,8 +387,12 @@ static void add_posix_clock_line(struct libscols_table *tb, const int *columns, int rc; rc = clock_gettime(clockinfo->id, &now); - if (rc) + if (rc) { + if (is_aux_clock(clockinfo->id) && errno == EINVAL) + return; /* auxclocks are not supported */ + now.tv_nsec = -1; + } rc = clock_getres(clockinfo->id, &resolution); if (rc) diff --git a/tests/ts/misc/lsclocks b/tests/ts/misc/lsclocks index 71fefaa52b..a3bb51f670 100755 --- a/tests/ts/misc/lsclocks +++ b/tests/ts/misc/lsclocks @@ -31,7 +31,8 @@ NO_DISCOVER="--no-discover-dynamic --no-discover-rtc" ts_init_subtest basic -"$TS_CMD_LSCLOCKS" $NO_DISCOVER -o TYPE,ID,CLOCK,NAME > "$TS_OUTPUT" 2>> "$TS_ERRLOG" +"$TS_CMD_LSCLOCKS" $NO_DISCOVER -o TYPE,ID,CLOCK,NAME | grep -v CLOCK_AUX \ + > "$TS_OUTPUT" 2>> "$TS_ERRLOG" ts_finalize_subtest -- 2.47.3