[patch V2 18/26] timekeeping: Add minimal posix-timers support for auxiliary clocks
From: Thomas Gleixner <hidden>
Date: 2025-05-19 08:33:38
Also in:
lkml
Provide clock_getres(2) and clock_gettime(2) for auxiliary clocks. Signed-off-by: Thomas Gleixner <redacted> --- kernel/time/posix-timers.c | 3 +++ kernel/time/posix-timers.h | 1 + kernel/time/timekeeping.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) ---
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c@@ -1526,6 +1526,9 @@ static const struct k_clock * const posi [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) --- a/kernel/time/posix-timers.h +++ b/kernel/time/posix-timers.h
@@ -41,6 +41,7 @@ extern const struct k_clock clock_posix_ 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); --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c
@@ -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 */ static unsigned long aux_timekeepers;
@@ -2741,6 +2742,26 @@ bool ktime_get_aux_ts64(clockid_t id, st return true; } +static int aux_get_res(clockid_t id, struct timespec64 *tp) +{ + if (!aux_valid_clockid(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; i <= TIMEKEEPER_AUX_LAST; i++)