From: Thomas Weißschuh Date: Mon, 2 Jun 2025 21:10:35 +0000 (+0200) Subject: lsclocks: add auxiliary clocks X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ff89d9c4a0c1a5198eb4fc34da895c2598516bdc;p=thirdparty%2Futil-linux.git lsclocks: add auxiliary clocks 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 --- diff --git a/misc-utils/lsclocks.1.adoc b/misc-utils/lsclocks.1.adoc index ffd3c4049..fd9ca96df 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 3fdec7ef2..946b88be1 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 71fefaa52..a3bb51f67 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