Skip to content

Commit 606424b

Browse files
committed
timekeeping: Add minimal posix-timers support for auxiliary clocks
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
1 parent 05bc6e6 commit 606424b

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

kernel/time/posix-timers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,9 @@ static const struct k_clock * const posix_clocks[] = {
15261526
[CLOCK_REALTIME_ALARM] = &alarm_clock,
15271527
[CLOCK_BOOTTIME_ALARM] = &alarm_clock,
15281528
[CLOCK_TAI] = &clock_tai,
1529+
#ifdef CONFIG_POSIX_AUX_CLOCKS
1530+
[CLOCK_AUX ... CLOCK_AUX_LAST] = &clock_aux,
1531+
#endif
15291532
};
15301533

15311534
static const struct k_clock *clockid_to_kclock(const clockid_t id)

kernel/time/posix-timers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern const struct k_clock clock_posix_dynamic;
4141
extern const struct k_clock clock_process;
4242
extern const struct k_clock clock_thread;
4343
extern const struct k_clock alarm_clock;
44+
extern const struct k_clock clock_aux;
4445

4546
void posix_timer_queue_signal(struct k_itimer *timr);
4647

kernel/time/timekeeping.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,7 @@ EXPORT_SYMBOL(hardpps);
26552655
#endif /* CONFIG_NTP_PPS */
26562656

26572657
#ifdef CONFIG_POSIX_AUX_CLOCKS
2658+
#include "posix-timers.h"
26582659

26592660
/*
26602661
* 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)
27492750
}
27502751
EXPORT_SYMBOL_GPL(ktime_get_aux_ts64);
27512752

2753+
static int aux_get_res(clockid_t id, struct timespec64 *tp)
2754+
{
2755+
if (!clockid_aux_valid(id))
2756+
return -ENODEV;
2757+
2758+
tp->tv_sec = 0;
2759+
tp->tv_nsec = 1;
2760+
return 0;
2761+
}
2762+
2763+
static int aux_get_timespec(clockid_t id, struct timespec64 *tp)
2764+
{
2765+
return ktime_get_aux_ts64(id, tp) ? 0 : -ENODEV;
2766+
}
2767+
2768+
const struct k_clock clock_aux = {
2769+
.clock_getres = aux_get_res,
2770+
.clock_get_timespec = aux_get_timespec,
2771+
};
2772+
27522773
static __init void tk_aux_setup(void)
27532774
{
27542775
for (int i = TIMEKEEPER_AUX_FIRST; i <= TIMEKEEPER_AUX_LAST; i++)

0 commit comments

Comments
 (0)