]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsclocks: add auxiliary clocks
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 2 Jun 2025 21:10:35 +0000 (23:10 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Aug 2025 09:12:35 +0000 (11:12 +0200)
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 <thomas@t-8ch.de>
misc-utils/lsclocks.1.adoc
misc-utils/lsclocks.c
tests/ts/misc/lsclocks

index ffd3c4049917c2fa43b97d87b29854a4f2ae858e..fd9ca96df8abea3eb11d3afc1addb5652c3b0533 100644 (file)
@@ -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
 
index 3fdec7ef2c9c116f720d3f40ea4fea864b9d1df3..946b88be19053ee14a58ff2e3f13c463aaf20aec 100644 (file)
@@ -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)
index 71fefaa52bf650db7f778e715235e44f203e54f8..a3bb51f670bec70e5a9aef10ef88c4e19d1962e4 100755 (executable)
@@ -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