]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
timekeeping: Add minimal posix-timers support for auxiliary clocks
authorThomas Gleixner <tglx@linutronix.de>
Wed, 25 Jun 2025 18:38:32 +0000 (20:38 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 27 Jun 2025 18:13:12 +0000 (20:13 +0200)
Provide clock_getres(2) and clock_gettime(2) for auxiliary clocks.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/all/20250625183757.932220594@linutronix.de
kernel/time/posix-timers.c
kernel/time/posix-timers.h
kernel/time/timekeeping.c

index 2053b1a4c9e4bfd792368035553b654593bc7b33..8b582174b1f9498a548fc1c214185577f994a647 100644 (file)
@@ -1526,6 +1526,9 @@ static const struct k_clock * const posix_clocks[] = {
        [CLOCK_REALTIME_ALARM]          = &alarm_clock,
        [CLOCK_BOOTTIME_ALARM]          = &alarm_clock,
        [CLOCK_TAI]                     = &clock_tai,
+#ifdef CONFIG_POSIX_AUX_CLOCKS
+       [CLOCK_AUX ... CLOCK_AUX_LAST]  = &clock_aux,
+#endif
 };
 
 static const struct k_clock *clockid_to_kclock(const clockid_t id)
index 61906f0688c1b83e7bbf7749eff7b03c11da39ba..7f259e845d240c139a3ae507fd388eeff9e857e1 100644 (file)
@@ -41,6 +41,7 @@ extern const struct k_clock clock_posix_dynamic;
 extern const struct k_clock clock_process;
 extern const struct k_clock clock_thread;
 extern const struct k_clock alarm_clock;
+extern const struct k_clock clock_aux;
 
 void posix_timer_queue_signal(struct k_itimer *timr);
 
index c7d2913e68c3bfc41d98acba615d2eec985e879f..10c6e37dc0dca3fb657f362ad0e93090dea5e8c2 100644 (file)
@@ -2655,6 +2655,7 @@ EXPORT_SYMBOL(hardpps);
 #endif /* CONFIG_NTP_PPS */
 
 #ifdef CONFIG_POSIX_AUX_CLOCKS
+#include "posix-timers.h"
 
 /*
  * Bitmap for the activated auxiliary timekeepers to allow lockless quick
@@ -2749,6 +2750,26 @@ bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *ts)
 }
 EXPORT_SYMBOL_GPL(ktime_get_aux_ts64);
 
+static int aux_get_res(clockid_t id, struct timespec64 *tp)
+{
+       if (!clockid_aux_valid(id))
+               return -ENODEV;
+
+       tp->tv_sec = 0;
+       tp->tv_nsec = 1;
+       return 0;
+}
+
+static int aux_get_timespec(clockid_t id, struct timespec64 *tp)
+{
+       return ktime_get_aux_ts64(id, tp) ? 0 : -ENODEV;
+}
+
+const struct k_clock clock_aux = {
+       .clock_getres           = aux_get_res,
+       .clock_get_timespec     = aux_get_timespec,
+};
+
 static __init void tk_aux_setup(void)
 {
        for (int i = TIMEKEEPER_AUX_FIRST; i <= TIMEKEEPER_AUX_LAST; i++)