* [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups
@ 2026-08-03 10:04 Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
` (16 more replies)
0 siblings, 17 replies; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Various cleanups I stumbled over while working on the timekeeping code.
Based on tip/timers/core.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
Changes in v2:
- Pick up Acks from John.
- Extend the description of "Explicitly list the tested clocks" patches.
- Drop some more custom ?SEC_PER_?SEC definitions.
- Drop SKIPPED_CLOCK_COUNT from nsleep-lat.c.
- Explicitly handle timer_delete() failure in nanosleep.c.
- Link to v1: https://patch.msgid.link/20260730-auxclock-nanosleep-prep-v1-0-cd8b61229a7c@linutronix.de
---
Thomas Weißschuh (Schneider Electric) (17):
timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock()
timekeeping: Use u32 for clock_was_set_seq
hrtimer: Add a lockdep assertion to hrtimer_update_base()
timer_list: Use standard 'long long' format placeholders
timer_list: Use ktime_t over nanoseconds
selftests: add clock-helpers.h
selftests: timers: Use clock_name() and constants from clock-helpers.h
selftests: timers: nanosleep: Drop output alignment
selftests: timers: nanosleep: Explicitly list the tested clocks
selftests: timers: nanosleep: Reuse kselftest error numbers
selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
selftests: timers: nanosleep: Explicitly handle timer_delete() failure
selftests: timers: nanosleep: Report each test separately
selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency
selftests: timers: nsleep-lat: Explicitly list the tested clocks
selftests: timers: nsleep-lat: Reuse kselftest error numbers
selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()
include/linux/hrtimer_bases.h | 2 +-
include/linux/posix-timers.h | 2 +-
include/linux/timekeeper_internal.h | 2 +-
include/linux/timekeeping.h | 2 +-
kernel/time/hrtimer.c | 4 +-
kernel/time/timekeeping.c | 9 +-
kernel/time/timekeeping.h | 2 +-
kernel/time/timer_list.c | 65 +++++----
tools/testing/selftests/clock-helpers.h | 76 +++++++++++
tools/testing/selftests/timers/adjtick.c | 5 +-
.../testing/selftests/timers/alarmtimer-suspend.c | 38 +-----
.../testing/selftests/timers/inconsistency-check.c | 38 +-----
tools/testing/selftests/timers/leap-a-day.c | 3 +-
tools/testing/selftests/timers/mqueue-lat.c | 3 +-
tools/testing/selftests/timers/nanosleep.c | 145 ++++++++-------------
tools/testing/selftests/timers/nsleep-lat.c | 102 +++++----------
tools/testing/selftests/timers/posix_timers.c | 36 ++---
tools/testing/selftests/timers/raw_skew.c | 3 +-
tools/testing/selftests/timers/set-2038.c | 3 +-
tools/testing/selftests/timers/set-timer-lat.c | 41 +-----
tools/testing/selftests/timers/valid-adjtimex.c | 4 +-
21 files changed, 251 insertions(+), 334 deletions(-)
---
base-commit: ecc330e3096173f433659aa64ab3674d0d48440e
change-id: 20260730-auxclock-nanosleep-prep-0316e89e6ac2
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock()
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq Thomas Weißschuh (Schneider Electric)
` (15 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The current name is not clear about its behavior.
Rename it.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
include/linux/posix-timers.h | 2 +-
kernel/time/timekeeping.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 4117827efdb8..9a1a0c61361c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -37,7 +37,7 @@ static inline int clockid_to_fd(const clockid_t clk)
return ~(clk >> 3);
}
-static inline bool clockid_aux_valid(clockid_t id)
+static inline bool clockid_is_aux_clock(clockid_t id)
{
return IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) && id >= CLOCK_AUX && id <= CLOCK_AUX_LAST;
}
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 97db2e9393f9..d4cdbcdcb9df 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -3129,7 +3129,7 @@ static inline unsigned int clockid_to_tkid(unsigned int id)
static inline struct tk_data *aux_get_tk_data(clockid_t id)
{
- if (!clockid_aux_valid(id))
+ if (!clockid_is_aux_clock(id))
return NULL;
return &timekeeper_data[clockid_to_tkid(id)];
}
@@ -3224,7 +3224,7 @@ EXPORT_SYMBOL_GPL(ktime_get_aux_ts64);
static int aux_get_res(clockid_t id, struct timespec64 *tp)
{
- if (!clockid_aux_valid(id))
+ if (!clockid_is_aux_clock(id))
return -ENODEV;
tp->tv_sec = aux_clock_resolution_ns() / NSEC_PER_SEC;
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base() Thomas Weißschuh (Schneider Electric)
` (14 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Use an explicitly sized type to make the code a bit more consistent
with other fields of the datastructure and other sequence counters.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
include/linux/hrtimer_bases.h | 2 +-
include/linux/timekeeper_internal.h | 2 +-
include/linux/timekeeping.h | 2 +-
kernel/time/hrtimer.c | 2 +-
kernel/time/timekeeping.c | 5 +++--
kernel/time/timekeeping.h | 2 +-
6 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/include/linux/hrtimer_bases.h b/include/linux/hrtimer_bases.h
index 70b99e651168..d4c83ec5c0f8 100644
--- a/include/linux/hrtimer_bases.h
+++ b/include/linux/hrtimer_bases.h
@@ -84,7 +84,7 @@ struct hrtimer_cpu_base {
raw_spinlock_t lock;
unsigned int cpu;
unsigned int active_bases;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
bool hres_active;
bool deferred_rearm;
bool deferred_needs_update;
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 9c198f65621b..fe077d97b5f8 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -169,7 +169,7 @@ struct timekeeper {
u32 cs_ns_to_cyc_mult;
u32 cs_ns_to_cyc_shift;
u64 cs_ns_to_cyc_maxns;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
u8 cs_was_changed_seq;
u8 clock_valid;
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b4191a873c39..1345550d45b4 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -301,7 +301,7 @@ struct system_time_snapshot {
ktime_t monoraw;
enum clocksource_ids cs_id;
enum clocksource_ids hw_csid;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
u8 cs_was_changed_seq;
u8 valid;
};
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 01890b7a5f98..957c619e4271 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -903,8 +903,8 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram)
static bool update_needs_ipi(struct hrtimer_cpu_base *cpu_base, unsigned int active)
{
struct hrtimer_clock_base *base;
- unsigned int seq;
ktime_t expires;
+ u32 seq;
/*
* Update the base offsets unconditionally so the following
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index d4cdbcdcb9df..815861ce451b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1563,10 +1563,11 @@ int get_device_system_crosststamp(int (*get_time_fn)
struct system_device_crosststamp *xtstamp)
{
u64 syscnt_cycles, cycles, now, interval_start;
- unsigned int seq, clock_was_set_seq = 0;
ktime_t base_sys, base_raw, *offs;
+ u32 clock_was_set_seq = 0;
u64 nsec_sys, nsec_raw;
u8 cs_was_changed_seq;
+ unsigned int seq;
bool do_interp;
struct timekeeper *tk;
struct tk_data *tkd;
@@ -2873,7 +2874,7 @@ void do_timer(unsigned long ticks)
*
* Called from hrtimer_interrupt() or retrigger_next_event()
*/
-ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real,
+ktime_t ktime_get_update_offsets_now(u32 *cwsseq, ktime_t *offs_real,
ktime_t *offs_boot, ktime_t *offs_tai)
{
struct timekeeper *tk = &tk_core.timekeeper;
diff --git a/kernel/time/timekeeping.h b/kernel/time/timekeeping.h
index 198d0608db74..4201f9e90813 100644
--- a/kernel/time/timekeeping.h
+++ b/kernel/time/timekeeping.h
@@ -4,7 +4,7 @@
/*
* Internal interfaces for kernel/time/
*/
-extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq,
+extern ktime_t ktime_get_update_offsets_now(u32 *cwsseq,
ktime_t *offs_real,
ktime_t *offs_boot,
ktime_t *offs_tai);
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base()
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders Thomas Weißschuh (Schneider Electric)
` (13 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Document and verify that the base's lock is held at this point.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/hrtimer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 957c619e4271..91b2ea890730 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -677,6 +677,8 @@ static ktime_t hrtimer_update_next_event(struct hrtimer_cpu_base *cpu_base)
static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
{
+ lockdep_assert_held(&base->lock);
+
ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
ktime_t *offs_tai = &base->clock_base[HRTIMER_BASE_TAI].offset;
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (2 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base() Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds Thomas Weißschuh (Schneider Electric)
` (12 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
'%Ld' and '%Lu' are GNU extensions. While they do work for kernel code,
checkpatch complains about them all the time. Replace them with the
standard placeholders for 'long long' types, namely '%lld' and '%llu'.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timer_list.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 8823e7dcfce6..ccbbb2ad1517 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -49,7 +49,7 @@ print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
SEQ_printf(m, ", S:%02x", timer->is_queued);
SEQ_printf(m, "\n");
- SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
+ SEQ_printf(m, " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
(unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
(unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
(long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
@@ -101,7 +101,7 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
SEQ_printf(m, " .resolution: %u nsecs\n", hrtimer_resolution);
#ifdef CONFIG_HIGH_RES_TIMERS
- SEQ_printf(m, " .offset: %Ld nsecs\n",
+ SEQ_printf(m, " .offset: %lld nsecs\n",
(long long) base->offset);
#endif
SEQ_printf(m, "active timers:\n");
@@ -122,10 +122,10 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#define DIAG_READ(x) data_race(READ_ONCE(x))
#define P(x) \
- SEQ_printf(m, " .%-15s: %Lu\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(cpu_base->x))
#define P_ns(x) \
- SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
(unsigned long long)ktime_to_ns(DIAG_READ(cpu_base->x)))
#ifdef CONFIG_HIGH_RES_TIMERS
@@ -141,10 +141,10 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#ifdef CONFIG_TICK_ONESHOT
# define P(x) \
- SEQ_printf(m, " .%-15s: %Lu\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(ts->x))
# define P_ns(x) \
- SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
(unsigned long long)ktime_to_ns(DIAG_READ(ts->x)))
# define P_flag(x, f) \
SEQ_printf(m, " .%-15s: %d\n", #x, !!(DIAG_READ(ts->flags) & (f)))
@@ -162,7 +162,7 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
P(last_jiffies);
P(next_timer);
P_ns(idle_expires);
- SEQ_printf(m, "jiffies: %Lu\n",
+ SEQ_printf(m, "jiffies: %llu\n",
(unsigned long long)jiffies);
}
#endif
@@ -201,7 +201,7 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
SEQ_printf(m, " mult: %u\n", dev->mult);
SEQ_printf(m, " shift: %u\n", dev->shift);
SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
- SEQ_printf(m, " next_event: %Ld nsecs\n",
+ SEQ_printf(m, " next_event: %lld nsecs\n",
(unsigned long long) ktime_to_ns(dev->next_event));
SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
@@ -259,7 +259,7 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
{
SEQ_printf(m, "Timer List Version: v0.11\n");
SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
- SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
+ SEQ_printf(m, "now at %lld nsecs\n", (unsigned long long)now);
SEQ_printf(m, "\n");
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (3 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 06/17] selftests: add clock-helpers.h Thomas Weißschuh (Schneider Electric)
` (11 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
hrtimers use ktime_t in their implementation and API.
The timer list performs a lot of unnecessary conversion to nanoseconds
which make the code harder to read and are also wrong in case the values
ever become negative.
Remove the conversions.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timer_list.c | 57 +++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index ccbbb2ad1517..0406bf4488e9 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -20,7 +20,7 @@
struct timer_list_iter {
int cpu;
bool second_pass;
- u64 now;
+ ktime_t now;
};
/*
@@ -44,19 +44,19 @@ static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
static void
print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
- int idx, u64 now)
+ int idx, ktime_t now)
{
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
SEQ_printf(m, ", S:%02x", timer->is_queued);
SEQ_printf(m, "\n");
- SEQ_printf(m, " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
- (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
- (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
- (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
- (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
+ SEQ_printf(m, " # expires at %lld-%lld nsecs [in %lld to %lld nsecs]\n",
+ (long long)hrtimer_get_softexpires(timer),
+ (long long)hrtimer_get_expires(timer),
+ (long long)ktime_sub(hrtimer_get_softexpires(timer), now),
+ (long long)ktime_sub(hrtimer_get_expires(timer), now));
}
-static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
struct timerqueue_linked_node *curr;
struct hrtimer *timer, tmp;
@@ -94,7 +94,7 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *b
}
static void
-print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+print_base(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
SEQ_printf(m, " .base: %p\n", base);
SEQ_printf(m, " .index: %d\n", base->index);
@@ -105,10 +105,10 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
(long long) base->offset);
#endif
SEQ_printf(m, "active timers:\n");
- print_active_timers(m, base, now + ktime_to_ns(base->offset));
+ print_active_timers(m, base, ktime_add(now, base->offset));
}
-static void print_cpu(struct seq_file *m, int cpu, u64 now)
+static void print_cpu(struct seq_file *m, int cpu, ktime_t now)
{
struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
int i;
@@ -124,12 +124,11 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(cpu_base->x))
-#define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(cpu_base->x)))
+#define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(cpu_base->x))
#ifdef CONFIG_HIGH_RES_TIMERS
- P_ns(expires_next);
+ P_ktime(expires_next);
P(hres_active);
P(nr_events);
P(nr_retries);
@@ -137,15 +136,14 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
P(max_hang_time);
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#ifdef CONFIG_TICK_ONESHOT
# define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(ts->x))
-# define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(ts->x)))
+# define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(ts->x))
# define P_flag(x, f) \
SEQ_printf(m, " .%-15s: %d\n", #x, !!(DIAG_READ(ts->flags) & (f)))
@@ -153,22 +151,22 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
struct tick_sched *ts = tick_get_tick_sched(cpu);
P_flag(nohz, TS_FLAG_NOHZ);
P_flag(highres, TS_FLAG_HIGHRES);
- P_ns(last_tick);
+ P_ktime(last_tick);
P_flag(tick_stopped, TS_FLAG_STOPPED);
P(idle_calls);
P(idle_sleeps);
- P_ns(idle_entrytime);
- P_ns(idle_waketime);
+ P_ktime(idle_entrytime);
+ P_ktime(idle_waketime);
P(last_jiffies);
P(next_timer);
- P_ns(idle_expires);
+ P_ktime(idle_expires);
SEQ_printf(m, "jiffies: %llu\n",
(unsigned long long)jiffies);
}
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#undef P_flag
#undef DIAG_READ
SEQ_printf(m, "\n");
@@ -201,8 +199,7 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
SEQ_printf(m, " mult: %u\n", dev->mult);
SEQ_printf(m, " shift: %u\n", dev->shift);
SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
- SEQ_printf(m, " next_event: %lld nsecs\n",
- (unsigned long long) ktime_to_ns(dev->next_event));
+ SEQ_printf(m, " next_event: %lld nsecs\n", (long long)dev->next_event);
SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
@@ -255,17 +252,17 @@ static void timer_list_show_tickdevices_header(struct seq_file *m)
}
#endif
-static inline void timer_list_header(struct seq_file *m, u64 now)
+static inline void timer_list_header(struct seq_file *m, ktime_t now)
{
SEQ_printf(m, "Timer List Version: v0.11\n");
SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
- SEQ_printf(m, "now at %lld nsecs\n", (unsigned long long)now);
+ SEQ_printf(m, "now at %lld nsecs\n", (long long)now);
SEQ_printf(m, "\n");
}
void sysrq_timer_list_show(void)
{
- u64 now = ktime_to_ns(ktime_get());
+ ktime_t now = ktime_get();
int cpu;
timer_list_header(NULL, now);
@@ -323,7 +320,7 @@ static void *timer_list_start(struct seq_file *file, loff_t *offset)
struct timer_list_iter *iter = file->private;
if (!*offset)
- iter->now = ktime_to_ns(ktime_get());
+ iter->now = ktime_get();
iter->cpu = -1;
iter->second_pass = false;
return move_iter(iter, *offset);
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 06/17] selftests: add clock-helpers.h
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (4 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] selftests: Add clock-helpers.h tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h Thomas Weißschuh (Schneider Electric)
` (10 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Multiple selftests duplicate various clock-related functionality.
Add a new header to collect and deduplicate those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/clock-helpers.h | 76 +++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/tools/testing/selftests/clock-helpers.h b/tools/testing/selftests/clock-helpers.h
new file mode 100644
index 000000000000..01451f538e71
--- /dev/null
+++ b/tools/testing/selftests/clock-helpers.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __CLOCK_HELPERS_H
+#define __CLOCK_HELPERS_H
+
+#include <sys/types.h>
+#include <time.h>
+
+#define MSEC_PER_SEC 1000LL
+#define USEC_PER_MSEC 1000LL
+#define NSEC_PER_USEC 1000LL
+#define NSEC_PER_MSEC 1000000LL
+#define USEC_PER_SEC 1000000LL
+#define NSEC_PER_SEC 1000000000LL
+#define PSEC_PER_SEC 1000000000000LL
+#define FSEC_PER_SEC 1000000000000000LL
+
+#ifndef CLOCK_AUX
+#define CLOCK_AUX 16
+#endif
+
+#ifndef MAX_AUX_CLOCKS
+#define MAX_AUX_CLOCKS 8
+#endif
+
+#ifndef CLOCK_AUX_LAST
+#define CLOCK_AUX_LAST (CLOCK_AUX + MAX_AUX_CLOCKS - 1)
+#endif
+
+__attribute__((unused))
+static inline const char *clock_name(clockid_t clockid)
+{
+ switch (clockid) {
+ case CLOCK_REALTIME:
+ return "CLOCK_REALTIME";
+ case CLOCK_MONOTONIC:
+ return "CLOCK_MONOTONIC";
+ case CLOCK_PROCESS_CPUTIME_ID:
+ return "CLOCK_PROCESS_CPUTIME_ID";
+ case CLOCK_THREAD_CPUTIME_ID:
+ return "CLOCK_THREAD_CPUTIME_ID";
+ case CLOCK_MONOTONIC_RAW:
+ return "CLOCK_MONOTONIC_RAW";
+ case CLOCK_REALTIME_COARSE:
+ return "CLOCK_REALTIME_COARSE";
+ case CLOCK_MONOTONIC_COARSE:
+ return "CLOCK_MONOTONIC_COARSE";
+ case CLOCK_BOOTTIME:
+ return "CLOCK_BOOTTIME";
+ case CLOCK_REALTIME_ALARM:
+ return "CLOCK_REALTIME_ALARM";
+ case CLOCK_BOOTTIME_ALARM:
+ return "CLOCK_BOOTTIME_ALARM";
+ case CLOCK_TAI:
+ return "CLOCK_TAI";
+ case CLOCK_AUX + 0:
+ return "CLOCK_AUX0";
+ case CLOCK_AUX + 1:
+ return "CLOCK_AUX1";
+ case CLOCK_AUX + 2:
+ return "CLOCK_AUX2";
+ case CLOCK_AUX + 3:
+ return "CLOCK_AUX3";
+ case CLOCK_AUX + 4:
+ return "CLOCK_AUX4";
+ case CLOCK_AUX + 5:
+ return "CLOCK_AUX5";
+ case CLOCK_AUX + 6:
+ return "CLOCK_AUX6";
+ case CLOCK_AUX + 7:
+ return "CLOCK_AUX7";
+ };
+ return "UNKNOWN_CLOCKID";
+}
+
+#endif /* __CLOCK_HELPERS_H */
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (5 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 06/17] selftests: add clock-helpers.h Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment Thomas Weißschuh (Schneider Electric)
` (9 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Replace the many repetitions of custom clockid_t to string translation
with the clock_name() helper from clock-helpers.h.
Also drop the custom ?SEC_PER_?SEC definitions.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/adjtick.c | 5 ++-
.../testing/selftests/timers/alarmtimer-suspend.c | 38 ++------------------
.../testing/selftests/timers/inconsistency-check.c | 38 +++-----------------
tools/testing/selftests/timers/leap-a-day.c | 3 +-
tools/testing/selftests/timers/mqueue-lat.c | 3 +-
tools/testing/selftests/timers/nanosleep.c | 42 ++++------------------
tools/testing/selftests/timers/nsleep-lat.c | 36 ++-----------------
tools/testing/selftests/timers/posix_timers.c | 36 ++++++++++---------
tools/testing/selftests/timers/raw_skew.c | 3 +-
tools/testing/selftests/timers/set-2038.c | 3 +-
tools/testing/selftests/timers/set-timer-lat.c | 41 +++------------------
tools/testing/selftests/timers/valid-adjtimex.c | 4 +--
12 files changed, 47 insertions(+), 205 deletions(-)
diff --git a/tools/testing/selftests/timers/adjtick.c b/tools/testing/selftests/timers/adjtick.c
index 22d274d5520f..68009a6d6de8 100644
--- a/tools/testing/selftests/timers/adjtick.c
+++ b/tools/testing/selftests/timers/adjtick.c
@@ -22,10 +22,9 @@
#include <sys/time.h>
#include <sys/timex.h>
#include <time.h>
-#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
+#include "clock-helpers.h"
+#include "kselftest.h"
#define MILLION 1000000
diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c b/tools/testing/selftests/timers/alarmtimer-suspend.c
index d55d5b0377c6..120b3ce8b39e 100644
--- a/tools/testing/selftests/timers/alarmtimer-suspend.c
+++ b/tools/testing/selftests/timers/alarmtimer-suspend.c
@@ -29,10 +29,9 @@
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
#define SUSPEND_SECS 15
@@ -40,37 +39,6 @@ int alarmcount;
int alarm_clock_id;
struct timespec start_time;
-
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
-
long long timespec_sub(struct timespec a, struct timespec b)
{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
@@ -130,12 +98,12 @@ int main(void)
alarmcount = 0;
if (timer_create(alarm_clock_id, &se, &tm1) == -1) {
printf("timer_create failed, %s unsupported?: %s\n",
- clockstring(alarm_clock_id), strerror(errno));
+ clock_name(alarm_clock_id), strerror(errno));
break;
}
clock_gettime(alarm_clock_id, &start_time);
- printf("Start time (%s): %ld:%ld\n", clockstring(alarm_clock_id),
+ printf("Start time (%s): %ld:%ld\n", clock_name(alarm_clock_id),
start_time.tv_sec, start_time.tv_nsec);
printf("Setting alarm for every %i seconds\n", SUSPEND_SECS);
its1.it_value = start_time;
diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c
index 9ab7066b4e32..d7982ac4bd18 100644
--- a/tools/testing/selftests/timers/inconsistency-check.c
+++ b/tools/testing/selftests/timers/inconsistency-check.c
@@ -28,44 +28,14 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
#define CALLS_PER_LOOP 64
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -172,15 +142,15 @@ int main(int argc, char *argv[])
for (clockid = userclock; clockid < maxclocks; clockid++) {
if (clockid == CLOCK_HWSPECIFIC || clock_gettime(clockid, &ts)) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
continue;
}
if (consistency_test(clockid, runtime)) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
} else {
- ksft_test_result_pass("%-31s\n", clockstring(clockid));
+ ksft_test_result_pass("%-31s\n", clock_name(clockid));
}
}
ksft_exit_pass();
diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/selftests/timers/leap-a-day.c
index 71b49734e08c..b93cb5714b37 100644
--- a/tools/testing/selftests/timers/leap-a-day.c
+++ b/tools/testing/selftests/timers/leap-a-day.c
@@ -51,10 +51,9 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define CLOCK_TAI 11
time_t next_leap;
diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/selftests/timers/mqueue-lat.c
index ce8700c95cac..fa4c3e3f58fe 100644
--- a/tools/testing/selftests/timers/mqueue-lat.c
+++ b/tools/testing/selftests/timers/mqueue-lat.c
@@ -29,10 +29,9 @@
#include <signal.h>
#include <errno.h>
#include <mqueue.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define TARGET_TIMEOUT 100000000 /* 100ms in nanoseconds */
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index ceff18149a48..7df86dfc897f 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -27,44 +27,14 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
#define UNSUPPORTED 0xf00f
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- };
- return "UNKNOWN_CLOCKID";
-}
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -182,7 +152,7 @@ int main(int argc, char **argv)
if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
clockid == CLOCK_THREAD_CPUTIME_ID ||
clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
continue;
}
@@ -192,21 +162,21 @@ int main(int argc, char **argv)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
goto next;
}
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
}
- ksft_test_result_pass("%-31s\n", clockstring(clockid));
+ ksft_test_result_pass("%-31s\n", clock_name(clockid));
next:
ret = 0;
}
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index 15f6493ca7b5..d22973c87f21 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -24,10 +24,9 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
@@ -35,35 +34,6 @@
#define UNSUPPORTED 0xf00f
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- };
- return "UNKNOWN_CLOCKID";
-}
-
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
{
ts.tv_nsec += ns;
@@ -156,10 +126,10 @@ int main(int argc, char **argv)
}
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%s\n", clockstring(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
} else {
ksft_test_result(ret >= 0, "%s\n",
- clockstring(clockid));
+ clock_name(clockid));
}
}
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index fa168d802f9e..a92d4b957747 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -19,11 +19,9 @@
#include <pthread.h>
#include <stdbool.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
-
#define DELAY 2
static void __fatal_error(const char *test, const char *name, const char *what)
@@ -143,8 +141,9 @@ static void check_itimer(int which, const char *name)
ksft_test_result(check_diff(start, end) == 0, "%s\n", name);
}
-static void check_timer_create(int which, const char *name)
+static void check_timer_create(int which)
{
+ const char *name = clock_name(which);
struct timespec start, end;
struct itimerspec val = {
.it_value.tv_sec = DELAY,
@@ -457,8 +456,9 @@ static void check_delete(void)
ksft_test_result(!tsig.signals, "check_delete\n");
}
-static void check_sigev_none(int which, const char *name)
+static void check_sigev_none(int which)
{
+ const char *name = clock_name(which);
struct timespec start, now;
struct itimerspec its;
struct sigevent sev;
@@ -495,8 +495,9 @@ static void check_sigev_none(int which, const char *name)
"check_sigev_none %s\n", name);
}
-static void check_gettime(int which, const char *name)
+static void check_gettime(int which)
{
+ const char *name = clock_name(which);
struct itimerspec its, prev;
struct timespec start, now;
struct sigevent sev;
@@ -548,8 +549,9 @@ static void check_gettime(int which, const char *name)
ksft_test_result(wraps > 1, "check_gettime %s\n", name);
}
-static void check_overrun(int which, const char *name)
+static void check_overrun(int which)
{
+ const char *name = clock_name(which);
struct timespec start, now;
struct tmrsig tsig = { };
struct itimerspec its;
@@ -691,7 +693,7 @@ int main(int argc, char **argv)
check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL");
check_itimer(ITIMER_PROF, "ITIMER_PROF");
check_itimer(ITIMER_REAL, "ITIMER_REAL");
- check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_timer_create(CLOCK_THREAD_CPUTIME_ID);
/*
* It's unfortunately hard to reliably test a timer expiration
@@ -702,7 +704,7 @@ int main(int argc, char **argv)
* to ensure true parallelism. So test only one thread until we
* find a better solution.
*/
- check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
+ check_timer_create(CLOCK_PROCESS_CPUTIME_ID);
check_timer_distribution();
if (run_sig_ign_tests) {
@@ -710,18 +712,18 @@ int main(int argc, char **argv)
check_sig_ign(1);
check_rearm();
check_delete();
- check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_sigev_none(CLOCK_MONOTONIC);
+ check_sigev_none(CLOCK_PROCESS_CPUTIME_ID);
+ check_gettime(CLOCK_MONOTONIC);
+ check_gettime(CLOCK_PROCESS_CPUTIME_ID);
+ check_gettime(CLOCK_THREAD_CPUTIME_ID);
} else {
ksft_print_msg("Skipping SIG_IGN tests on kernel < 6.13\n");
}
- check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_overrun(CLOCK_MONOTONIC);
+ check_overrun(CLOCK_PROCESS_CPUTIME_ID);
+ check_overrun(CLOCK_THREAD_CPUTIME_ID);
ksft_finished();
}
diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c
index 2dd16cb4cdd0..0c87a8fb0d7f 100644
--- a/tools/testing/selftests/timers/raw_skew.c
+++ b/tools/testing/selftests/timers/raw_skew.c
@@ -25,10 +25,9 @@
#include <sys/time.h>
#include <sys/timex.h>
#include <time.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define shift_right(x, s) ({ \
__typeof__(x) __x = (x); \
__typeof__(s) __s = (s); \
diff --git a/tools/testing/selftests/timers/set-2038.c b/tools/testing/selftests/timers/set-2038.c
index c1235638406d..f522a3035ec6 100644
--- a/tools/testing/selftests/timers/set-2038.c
+++ b/tools/testing/selftests/timers/set-2038.c
@@ -27,10 +27,9 @@
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c
index e092c18befff..79ddba25d314 100644
--- a/tools/testing/selftests/timers/set-timer-lat.c
+++ b/tools/testing/selftests/timers/set-timer-lat.c
@@ -28,10 +28,9 @@
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
@@ -44,36 +43,6 @@ struct timespec start_time;
long long max_latency_ns;
int timer_fired_early;
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
-
long long timespec_sub(struct timespec a, struct timespec b)
{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
@@ -104,7 +73,7 @@ void sigalarm(int signo)
void describe_timer(int flags, int interval)
{
printf("%-22s %s %s ",
- clockstring(clock_id),
+ clock_name(clock_id),
flags ? "ABSTIME":"RELTIME",
interval ? "PERIODIC":"ONE-SHOT");
}
@@ -130,12 +99,12 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
if ((clock_id == CLOCK_REALTIME_ALARM) ||
(clock_id == CLOCK_BOOTTIME_ALARM)) {
printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n",
- clockstring(clock_id),
+ clock_name(clock_id),
flags ? "ABSTIME":"RELTIME");
/* Indicate timer isn't set, so caller doesn't wait */
return 1;
}
- printf("%s - timer_create() failed\n", clockstring(clock_id));
+ printf("%s - timer_create() failed\n", clock_name(clock_id));
return -1;
}
@@ -152,7 +121,7 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
err = timer_settime(*tm1, flags, &its1, &its2);
if (err) {
- printf("%s - timer_settime() failed\n", clockstring(clock_id));
+ printf("%s - timer_settime() failed\n", clock_name(clock_id));
return -1;
}
diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c
index dc2559eb11a5..f641d5fb0902 100644
--- a/tools/testing/selftests/timers/valid-adjtimex.c
+++ b/tools/testing/selftests/timers/valid-adjtimex.c
@@ -29,11 +29,9 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
-
#define ADJ_SETOFFSET 0x0100
#include <sys/syscall.h>
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (6 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
` (8 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The padding of the clock name is pointless as nothing else is printed.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
tools/testing/selftests/timers/nanosleep.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 7df86dfc897f..629e800135ad 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -152,7 +152,7 @@ int main(int argc, char **argv)
if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
clockid == CLOCK_THREAD_CPUTIME_ID ||
clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%-31s\n", clock_name(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
continue;
}
@@ -162,21 +162,21 @@ int main(int argc, char **argv)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%-31s\n", clock_name(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
goto next;
}
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clock_name(clockid));
+ ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clock_name(clockid));
+ ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
- ksft_test_result_pass("%-31s\n", clock_name(clockid));
+ ksft_test_result_pass("%s\n", clock_name(clockid));
next:
ret = 0;
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (7 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
` (7 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The test relies on the numeric values of the clockids.
As not all clocks are meant to be tested, this requires skipping some
clocks unconditionally, cluttering the result.
Use an equivalent, explicit list instead.
In addition to CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID and
CLOCK_HWSPECIFIC which were unconditionally skipped before, this also
unconditionally skips CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and
CLOCK_REALTIME_COARSE. clock_nanosleep() is not supported for those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nanosleep.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 629e800135ad..9dd662226261 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -30,9 +30,6 @@
#include "clock-helpers.h"
#include "kselftest.h"
-/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
-#define CLOCK_HWSPECIFIC 10
-
#define UNSUPPORTED 0xf00f
/* returns 1 if a <= b, 0 otherwise */
@@ -141,20 +138,21 @@ int main(int argc, char **argv)
{
long long length;
int clockid, ret;
- int max_clocks = CLOCK_TAI + 1;
- ksft_print_header();
- ksft_set_plan(max_clocks);
+ static const clockid_t tested_clocks[] = {
+ CLOCK_REALTIME,
+ CLOCK_MONOTONIC,
+ CLOCK_BOOTTIME,
+ CLOCK_BOOTTIME_ALARM,
+ CLOCK_REALTIME_ALARM,
+ CLOCK_TAI,
+ };
- for (clockid = CLOCK_REALTIME; clockid < max_clocks; clockid++) {
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(tested_clocks));
- /* Skip cputime clockids since nanosleep won't increment cputime */
- if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
- clockid == CLOCK_THREAD_CPUTIME_ID ||
- clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- continue;
- }
+ for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
+ clockid = tested_clocks[clock_index];
fflush(stdout);
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (8 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main() Thomas Weißschuh (Schneider Electric)
` (6 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The test currently defines its own custom error numbers.
These mirror the semantics from the standard KFST_* constants.
To make the code easier to read, use the standard result constants.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nanosleep.c | 36 ++++++++++++++----------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 9dd662226261..0a2ca1791f27 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -30,8 +30,6 @@
#include "clock-helpers.h"
#include "kselftest.h"
-#define UNSUPPORTED 0xf00f
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -60,15 +58,15 @@ int nanosleep_test(int clockid, long long ns)
/* First check abs time */
if (clock_gettime(clockid, &now))
- return UNSUPPORTED;
+ return KSFT_SKIP;
target = timespec_add(now, ns);
if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
- return UNSUPPORTED;
+ return KSFT_SKIP;
clock_gettime(clockid, &now);
if (!in_order(target, now))
- return -1;
+ return KSFT_FAIL;
/* Second check reltime */
clock_gettime(clockid, &now);
@@ -80,8 +78,8 @@ int nanosleep_test(int clockid, long long ns)
clock_gettime(clockid, &now);
if (!in_order(target, now))
- return -1;
- return 0;
+ return KSFT_FAIL;
+ return KSFT_PASS;
}
static void dummy_event_handler(int val)
@@ -100,38 +98,38 @@ static int nanosleep_test_remaining(int clockid)
sa.sa_handler = dummy_event_handler;
ret = sigaction(SIGALRM, &sa, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
ret = timer_create(clockid, NULL, &timer);
if (ret)
- return -1;
+ return KSFT_FAIL;
itimer.it_value.tv_nsec = NSEC_PER_SEC / 4;
ret = timer_settime(timer, 0, &itimer, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
rqtp.tv_nsec = NSEC_PER_SEC / 2;
ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
if (ret != EINTR)
- return -1;
+ return KSFT_FAIL;
ret = timer_delete(timer);
if (ret)
- return -1;
+ return KSFT_FAIL;
sa.sa_handler = SIG_DFL;
ret = sigaction(SIGALRM, &sa, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
if (!in_order((struct timespec) {}, rmtp))
- return -1;
+ return KSFT_FAIL;
if (!in_order(rmtp, rqtp))
- return -1;
+ return KSFT_FAIL;
- return 0;
+ return KSFT_PASS;
}
int main(int argc, char **argv)
@@ -159,18 +157,18 @@ int main(int argc, char **argv)
length = 10;
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
- if (ret == UNSUPPORTED) {
+ if (ret == KSFT_SKIP) {
ksft_test_result_skip("%s\n", clock_name(clockid));
goto next;
}
- if (ret < 0) {
+ if (ret == KSFT_FAIL) {
ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
- if (ret < 0) {
+ if (ret == KSFT_FAIL) {
ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (9 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure Thomas Weißschuh (Schneider Electric)
` (5 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Make the code easier to read by avoiding a goto.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nanosleep.c | 51 ++++++++++++++++--------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 0a2ca1791f27..5037481516df 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -132,10 +132,35 @@ static int nanosleep_test_remaining(int clockid)
return KSFT_PASS;
}
+static void nanosleep_test_clock(clockid_t clockid)
+{
+ long long length = 10;
+ int ret;
+
+ while (length <= (NSEC_PER_SEC * 10)) {
+ ret = nanosleep_test(clockid, length);
+ if (ret == KSFT_SKIP) {
+ ksft_test_result_skip("%s\n", clock_name(clockid));
+ return;
+ }
+ if (ret == KSFT_FAIL) {
+ ksft_test_result_fail("%s\n", clock_name(clockid));
+ ksft_exit_fail();
+ }
+ length *= 100;
+ }
+
+ ret = nanosleep_test_remaining(clockid);
+ if (ret == KSFT_FAIL) {
+ ksft_test_result_fail("%s\n", clock_name(clockid));
+ ksft_exit_fail();
+ }
+ ksft_test_result_pass("%s\n", clock_name(clockid));
+}
+
int main(int argc, char **argv)
{
- long long length;
- int clockid, ret;
+ int clockid;
static const clockid_t tested_clocks[] = {
CLOCK_REALTIME,
@@ -154,27 +179,7 @@ int main(int argc, char **argv)
fflush(stdout);
- length = 10;
- while (length <= (NSEC_PER_SEC * 10)) {
- ret = nanosleep_test(clockid, length);
- if (ret == KSFT_SKIP) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- goto next;
- }
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- length *= 100;
- }
- ret = nanosleep_test_remaining(clockid);
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- ksft_test_result_pass("%s\n", clock_name(clockid));
-next:
- ret = 0;
+ nanosleep_test_clock(clockid);
}
ksft_exit_pass();
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (10 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main() Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately Thomas Weißschuh (Schneider Electric)
` (4 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
An upcoming patch will remove the early exit on failure of a single
testcase. If a test fails because a timeout timer could not be deleted,
then that timeout timer might interfere with the following tettcases.
Exit the whole test case with a clear error message in this case.
Other failures are not problematic:
* If timer_settime() fails, a harmless unarmed timer is left around.
* The SIGALRM handler reconfigured for each call to
nanosleep_test_remaining() anyways.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
tools/testing/selftests/timers/nanosleep.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 5037481516df..dd899dcfb2cb 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -111,11 +111,14 @@ static int nanosleep_test_remaining(int clockid)
rqtp.tv_nsec = NSEC_PER_SEC / 2;
ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
- if (ret != EINTR)
- return KSFT_FAIL;
- ret = timer_delete(timer);
- if (ret)
+ if (timer_delete(timer)) {
+ ksft_exit_fail_msg("Unable to delete the timeout timer for %s. "
+ "This might interfere with following testcases.\n",
+ clock_name(clockid));
+ }
+
+ if (ret != EINTR)
return KSFT_FAIL;
sa.sa_handler = SIG_DFL;
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (11 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency Thomas Weißschuh (Schneider Electric)
` (3 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Currently the test for the sleep functionality itself and the one for
the remaining time are reported together. This makes the test output a
bit confusing, especially as the upcoming tests for auxiliary clocks
will have different results between the two parts.
Report each test part on its own.
This also allows continuing testing other clocks after a single one
has failed.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
tools/testing/selftests/timers/nanosleep.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index dd899dcfb2cb..b45e4c855259 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -142,23 +142,18 @@ static void nanosleep_test_clock(clockid_t clockid)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
- if (ret == KSFT_SKIP) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
+ if (ret != KSFT_PASS) {
+ ksft_test_result_report(ret, "%s\n", clock_name(clockid));
+ ksft_test_result_skip("%s (remaining)\n", clock_name(clockid));
return;
}
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
+
length *= 100;
}
+ ksft_test_result_pass("%s\n", clock_name(clockid));
ret = nanosleep_test_remaining(clockid);
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- ksft_test_result_pass("%s\n", clock_name(clockid));
+ ksft_test_result_report(ret, "%s (remaining)\n", clock_name(clockid));
}
int main(int argc, char **argv)
@@ -175,7 +170,7 @@ int main(int argc, char **argv)
};
ksft_print_header();
- ksft_set_plan(ARRAY_SIZE(tested_clocks));
+ ksft_set_plan(ARRAY_SIZE(tested_clocks) * 2);
for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
clockid = tested_clocks[clock_index];
@@ -184,5 +179,5 @@ int main(int argc, char **argv)
nanosleep_test_clock(clockid);
}
- ksft_exit_pass();
+ ksft_finished();
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (12 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
` (2 subsequent siblings)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Use the predefined symbol to make the code easier to understand.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nsleep-lat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index d22973c87f21..d46f17404439 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -27,7 +27,7 @@
#include "clock-helpers.h"
#include "kselftest.h"
-#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
+#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (13 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() Thomas Weißschuh (Schneider Electric)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The test relies on the numeric values of the clockids.
As not all clocks are meant to be tested, this requires skipping some
clocks unconditionally, cluttering the result.
Use an equivalent, explicit list instead.
In addition to CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID and
CLOCK_HWSPECIFIC which were unconditionally skipped before, this also
unconditionally skips CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and
CLOCK_REALTIME_COARSE. clock_nanosleep() is not supported for those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nsleep-lat.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index d46f17404439..af47c28f086b 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -29,9 +29,6 @@
#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
-/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
-#define CLOCK_HWSPECIFIC 10
-
#define UNSUPPORTED 0xf00f
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
@@ -97,24 +94,25 @@ int nanosleep_lat_test(int clockid, long long ns)
return 0;
}
-#define SKIPPED_CLOCK_COUNT 3
-
int main(int argc, char **argv)
{
long long length;
int clockid, ret;
- int max_clocks = CLOCK_TAI + 1;
- ksft_print_header();
- ksft_set_plan(max_clocks - CLOCK_REALTIME - SKIPPED_CLOCK_COUNT);
+ static const clockid_t tested_clocks[] = {
+ CLOCK_REALTIME,
+ CLOCK_MONOTONIC,
+ CLOCK_BOOTTIME,
+ CLOCK_BOOTTIME_ALARM,
+ CLOCK_REALTIME_ALARM,
+ CLOCK_TAI,
+ };
- for (clockid = CLOCK_REALTIME; clockid < max_clocks; clockid++) {
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(tested_clocks));
- /* Skip cputime clockids since nanosleep won't increment cputime */
- if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
- clockid == CLOCK_THREAD_CPUTIME_ID ||
- clockid == CLOCK_HWSPECIFIC)
- continue;
+ for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
+ clockid = tested_clocks[clock_index];
length = 10;
while (length <= (NSEC_PER_SEC * 10)) {
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (14 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() Thomas Weißschuh (Schneider Electric)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
The test currently defines its own custom error numbers.
These mirror the semantics from the standard KFST_* constants.
To make the code easier to read, use the standard result constants.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nsleep-lat.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index af47c28f086b..266ca0cc37ec 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -29,8 +29,6 @@
#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
-#define UNSUPPORTED 0xf00f
-
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
{
ts.tv_nsec += ns;
@@ -60,9 +58,9 @@ int nanosleep_lat_test(int clockid, long long ns)
target.tv_nsec = ns%NSEC_PER_SEC;
if (clock_gettime(clockid, &start))
- return UNSUPPORTED;
+ return KSFT_SKIP;
if (clock_nanosleep(clockid, 0, &target, NULL))
- return UNSUPPORTED;
+ return KSFT_SKIP;
count = 10;
@@ -74,7 +72,7 @@ int nanosleep_lat_test(int clockid, long long ns)
if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
- return -1;
+ return KSFT_FAIL;
}
/* Next check absolute latency */
@@ -88,10 +86,10 @@ int nanosleep_lat_test(int clockid, long long ns)
if (latency/count > UNRESONABLE_LATENCY) {
ksft_print_msg("Large abs latency: %lld ns :", latency/count);
- return -1;
+ return KSFT_FAIL;
}
- return 0;
+ return KSFT_PASS;
}
int main(int argc, char **argv)
@@ -123,12 +121,7 @@ int main(int argc, char **argv)
}
- if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- } else {
- ksft_test_result(ret >= 0, "%s\n",
- clock_name(clockid));
- }
+ ksft_test_result_report(ret, "%s\n", clock_name(clockid));
}
ksft_finished();
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
` (15 preceding siblings ...)
2026-08-03 10:04 ` [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
@ 2026-08-03 10:04 ` Thomas Weißschuh (Schneider Electric)
2026-08-11 16:13 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
16 siblings, 1 reply; 35+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-08-03 10:04 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar,
Anna-Maria Behnsen, Frederic Weisbecker, Shuah Khan
Cc: linux-kernel, linux-kselftest,
Thomas Weißschuh (Schneider Electric)
Both these functions can fail.
The first calls to those functions are already checked and result in
KSFT_SKIP.
If they start failing afterwards unexpectedly, report a hard error.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
---
tools/testing/selftests/timers/nsleep-lat.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index 266ca0cc37ec..5de0051ac8e3 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -65,10 +65,16 @@ int nanosleep_lat_test(int clockid, long long ns)
count = 10;
/* First check relative latency */
- clock_gettime(clockid, &start);
- for (i = 0; i < count; i++)
- clock_nanosleep(clockid, 0, &target, NULL);
- clock_gettime(clockid, &end);
+ if (clock_gettime(clockid, &start))
+ return KSFT_FAIL;
+
+ for (i = 0; i < count; i++) {
+ if (clock_nanosleep(clockid, 0, &target, NULL))
+ return KSFT_FAIL;
+ }
+
+ if (clock_gettime(clockid, &end))
+ return KSFT_FAIL;
if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
@@ -77,10 +83,13 @@ int nanosleep_lat_test(int clockid, long long ns)
/* Next check absolute latency */
for (i = 0; i < count; i++) {
- clock_gettime(clockid, &start);
+ if (clock_gettime(clockid, &start))
+ return KSFT_FAIL;
target = timespec_add(start, ns);
- clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL);
- clock_gettime(clockid, &end);
+ if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
+ return KSFT_FAIL;
+ if (clock_gettime(clockid, &end))
+ return KSFT_FAIL;
latency += timespec_sub(target, end);
}
--
2.55.0
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()
2026-08-03 10:04 ` [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:13 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:13 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 4fa377c19e111c539a530a8200996b911ceff9ff
Gitweb: https://git.kernel.org/tip/4fa377c19e111c539a530a8200996b911ceff9ff
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:48 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()
Both these functions can fail.
The first calls to those functions are already checked and result in
KSFT_SKIP.
If they start failing afterwards unexpectedly, report a hard error.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-17-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nsleep-lat.c | 23 +++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index 266ca0c..5de0051 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -65,10 +65,16 @@ int nanosleep_lat_test(int clockid, long long ns)
count = 10;
/* First check relative latency */
- clock_gettime(clockid, &start);
- for (i = 0; i < count; i++)
- clock_nanosleep(clockid, 0, &target, NULL);
- clock_gettime(clockid, &end);
+ if (clock_gettime(clockid, &start))
+ return KSFT_FAIL;
+
+ for (i = 0; i < count; i++) {
+ if (clock_nanosleep(clockid, 0, &target, NULL))
+ return KSFT_FAIL;
+ }
+
+ if (clock_gettime(clockid, &end))
+ return KSFT_FAIL;
if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
@@ -77,10 +83,13 @@ int nanosleep_lat_test(int clockid, long long ns)
/* Next check absolute latency */
for (i = 0; i < count; i++) {
- clock_gettime(clockid, &start);
+ if (clock_gettime(clockid, &start))
+ return KSFT_FAIL;
target = timespec_add(start, ns);
- clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL);
- clock_gettime(clockid, &end);
+ if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
+ return KSFT_FAIL;
+ if (clock_gettime(clockid, &end))
+ return KSFT_FAIL;
latency += timespec_sub(target, end);
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nsleep-lat: Reuse kselftest error numbers
2026-08-03 10:04 ` [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 0f474ee80c7ba1cab784c12a12232c53db5ad1fb
Gitweb: https://git.kernel.org/tip/0f474ee80c7ba1cab784c12a12232c53db5ad1fb
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:47 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nsleep-lat: Reuse kselftest error numbers
The test currently defines its own custom error numbers.
These mirror the semantics from the standard KFST_* constants.
To make the code easier to read, use the standard result constants.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-16-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nsleep-lat.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index af47c28..266ca0c 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -29,8 +29,6 @@
#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
-#define UNSUPPORTED 0xf00f
-
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
{
ts.tv_nsec += ns;
@@ -60,9 +58,9 @@ int nanosleep_lat_test(int clockid, long long ns)
target.tv_nsec = ns%NSEC_PER_SEC;
if (clock_gettime(clockid, &start))
- return UNSUPPORTED;
+ return KSFT_SKIP;
if (clock_nanosleep(clockid, 0, &target, NULL))
- return UNSUPPORTED;
+ return KSFT_SKIP;
count = 10;
@@ -74,7 +72,7 @@ int nanosleep_lat_test(int clockid, long long ns)
if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
- return -1;
+ return KSFT_FAIL;
}
/* Next check absolute latency */
@@ -88,10 +86,10 @@ int nanosleep_lat_test(int clockid, long long ns)
if (latency/count > UNRESONABLE_LATENCY) {
ksft_print_msg("Large abs latency: %lld ns :", latency/count);
- return -1;
+ return KSFT_FAIL;
}
- return 0;
+ return KSFT_PASS;
}
int main(int argc, char **argv)
@@ -123,12 +121,7 @@ int main(int argc, char **argv)
}
- if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- } else {
- ksft_test_result(ret >= 0, "%s\n",
- clock_name(clockid));
- }
+ ksft_test_result_report(ret, "%s\n", clock_name(clockid));
}
ksft_finished();
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nsleep-lat: Explicitly list the tested clocks
2026-08-03 10:04 ` [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 187ac443ed51e04dcf0df98d270863c3f54af8fc
Gitweb: https://git.kernel.org/tip/187ac443ed51e04dcf0df98d270863c3f54af8fc
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:46 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nsleep-lat: Explicitly list the tested clocks
The test relies on the numeric values of the clockids.
As not all clocks are meant to be tested, this requires skipping some
clocks unconditionally, cluttering the result.
Use an equivalent, explicit list instead.
In addition to CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID and
CLOCK_HWSPECIFIC which were unconditionally skipped before, this also
unconditionally skips CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and
CLOCK_REALTIME_COARSE. clock_nanosleep() is not supported for those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-15-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nsleep-lat.c | 26 +++++++++-----------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index d46f174..af47c28 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -29,9 +29,6 @@
#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
-/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
-#define CLOCK_HWSPECIFIC 10
-
#define UNSUPPORTED 0xf00f
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
@@ -97,24 +94,25 @@ int nanosleep_lat_test(int clockid, long long ns)
return 0;
}
-#define SKIPPED_CLOCK_COUNT 3
-
int main(int argc, char **argv)
{
long long length;
int clockid, ret;
- int max_clocks = CLOCK_TAI + 1;
- ksft_print_header();
- ksft_set_plan(max_clocks - CLOCK_REALTIME - SKIPPED_CLOCK_COUNT);
+ static const clockid_t tested_clocks[] = {
+ CLOCK_REALTIME,
+ CLOCK_MONOTONIC,
+ CLOCK_BOOTTIME,
+ CLOCK_BOOTTIME_ALARM,
+ CLOCK_REALTIME_ALARM,
+ CLOCK_TAI,
+ };
- for (clockid = CLOCK_REALTIME; clockid < max_clocks; clockid++) {
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(tested_clocks));
- /* Skip cputime clockids since nanosleep won't increment cputime */
- if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
- clockid == CLOCK_THREAD_CPUTIME_ID ||
- clockid == CLOCK_HWSPECIFIC)
- continue;
+ for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
+ clockid = tested_clocks[clock_index];
length = 10;
while (length <= (NSEC_PER_SEC * 10)) {
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency
2026-08-03 10:04 ` [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: a00f90877dcd4176da3564f5f126547aa3ddfead
Gitweb: https://git.kernel.org/tip/a00f90877dcd4176da3564f5f126547aa3ddfead
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:45 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency
Use the predefined symbol to make the code easier to understand.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-14-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nsleep-lat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index d22973c..d46f174 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -27,7 +27,7 @@
#include "clock-helpers.h"
#include "kselftest.h"
-#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
+#define UNRESONABLE_LATENCY (40 * NSEC_PER_MSEC)
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Report each test separately
2026-08-03 10:04 ` [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: a1211288234058b0d13e2cc4a910b556c5308fdd
Gitweb: https://git.kernel.org/tip/a1211288234058b0d13e2cc4a910b556c5308fdd
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:44 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nanosleep: Report each test separately
Currently the test for the sleep functionality itself and the one for
the remaining time are reported together. This makes the test output a
bit confusing, especially as the upcoming tests for auxiliary clocks
will have different results between the two parts.
Report each test part on its own.
This also allows continuing testing other clocks after a single one
has failed.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-13-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index dd899dc..b45e4c8 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -142,23 +142,18 @@ static void nanosleep_test_clock(clockid_t clockid)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
- if (ret == KSFT_SKIP) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
+ if (ret != KSFT_PASS) {
+ ksft_test_result_report(ret, "%s\n", clock_name(clockid));
+ ksft_test_result_skip("%s (remaining)\n", clock_name(clockid));
return;
}
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
+
length *= 100;
}
+ ksft_test_result_pass("%s\n", clock_name(clockid));
ret = nanosleep_test_remaining(clockid);
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- ksft_test_result_pass("%s\n", clock_name(clockid));
+ ksft_test_result_report(ret, "%s (remaining)\n", clock_name(clockid));
}
int main(int argc, char **argv)
@@ -175,7 +170,7 @@ int main(int argc, char **argv)
};
ksft_print_header();
- ksft_set_plan(ARRAY_SIZE(tested_clocks));
+ ksft_set_plan(ARRAY_SIZE(tested_clocks) * 2);
for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
clockid = tested_clocks[clock_index];
@@ -184,5 +179,5 @@ int main(int argc, char **argv)
nanosleep_test_clock(clockid);
}
- ksft_exit_pass();
+ ksft_finished();
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Explicitly handle timer_delete() failure
2026-08-03 10:04 ` [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: f2ff28a52255f04ab0de16a7d298e35360852890
Gitweb: https://git.kernel.org/tip/f2ff28a52255f04ab0de16a7d298e35360852890
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:43 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00
selftests: timers: nanosleep: Explicitly handle timer_delete() failure
An upcoming patch will remove the early exit on failure of a single
testcase. If a test fails because a timeout timer could not be deleted,
then that timeout timer might interfere with the following tettcases.
Exit the whole test case with a clear error message in this case.
Other failures are not problematic:
* If timer_settime() fails, a harmless unarmed timer is left around.
* The SIGALRM handler reconfigured for each call to
nanosleep_test_remaining() anyways.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-12-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 5037481..dd899dc 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -111,11 +111,14 @@ static int nanosleep_test_remaining(int clockid)
rqtp.tv_nsec = NSEC_PER_SEC / 2;
ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
- if (ret != EINTR)
- return KSFT_FAIL;
- ret = timer_delete(timer);
- if (ret)
+ if (timer_delete(timer)) {
+ ksft_exit_fail_msg("Unable to delete the timeout timer for %s. "
+ "This might interfere with following testcases.\n",
+ clock_name(clockid));
+ }
+
+ if (ret != EINTR)
return KSFT_FAIL;
sa.sa_handler = SIG_DFL;
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
2026-08-03 10:04 ` [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main() Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 061341a568146000de8d41791bf7612b2f6813b5
Gitweb: https://git.kernel.org/tip/061341a568146000de8d41791bf7612b2f6813b5
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:42 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
Make the code easier to read by avoiding a goto.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-11-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 51 +++++++++++----------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 0a2ca17..5037481 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -132,10 +132,35 @@ static int nanosleep_test_remaining(int clockid)
return KSFT_PASS;
}
+static void nanosleep_test_clock(clockid_t clockid)
+{
+ long long length = 10;
+ int ret;
+
+ while (length <= (NSEC_PER_SEC * 10)) {
+ ret = nanosleep_test(clockid, length);
+ if (ret == KSFT_SKIP) {
+ ksft_test_result_skip("%s\n", clock_name(clockid));
+ return;
+ }
+ if (ret == KSFT_FAIL) {
+ ksft_test_result_fail("%s\n", clock_name(clockid));
+ ksft_exit_fail();
+ }
+ length *= 100;
+ }
+
+ ret = nanosleep_test_remaining(clockid);
+ if (ret == KSFT_FAIL) {
+ ksft_test_result_fail("%s\n", clock_name(clockid));
+ ksft_exit_fail();
+ }
+ ksft_test_result_pass("%s\n", clock_name(clockid));
+}
+
int main(int argc, char **argv)
{
- long long length;
- int clockid, ret;
+ int clockid;
static const clockid_t tested_clocks[] = {
CLOCK_REALTIME,
@@ -154,27 +179,7 @@ int main(int argc, char **argv)
fflush(stdout);
- length = 10;
- while (length <= (NSEC_PER_SEC * 10)) {
- ret = nanosleep_test(clockid, length);
- if (ret == KSFT_SKIP) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- goto next;
- }
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- length *= 100;
- }
- ret = nanosleep_test_remaining(clockid);
- if (ret == KSFT_FAIL) {
- ksft_test_result_fail("%s\n", clock_name(clockid));
- ksft_exit_fail();
- }
- ksft_test_result_pass("%s\n", clock_name(clockid));
-next:
- ret = 0;
+ nanosleep_test_clock(clockid);
}
ksft_exit_pass();
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Reuse kselftest error numbers
2026-08-03 10:04 ` [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: bfe5bf0c5fab93f90d851688fe2d65590339ecec
Gitweb: https://git.kernel.org/tip/bfe5bf0c5fab93f90d851688fe2d65590339ecec
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:41 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: timers: nanosleep: Reuse kselftest error numbers
The test currently defines its own custom error numbers.
These mirror the semantics from the standard KFST_* constants.
To make the code easier to read, use the standard result constants.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-10-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 36 +++++++++------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 9dd6622..0a2ca17 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -30,8 +30,6 @@
#include "clock-helpers.h"
#include "kselftest.h"
-#define UNSUPPORTED 0xf00f
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -60,15 +58,15 @@ int nanosleep_test(int clockid, long long ns)
/* First check abs time */
if (clock_gettime(clockid, &now))
- return UNSUPPORTED;
+ return KSFT_SKIP;
target = timespec_add(now, ns);
if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
- return UNSUPPORTED;
+ return KSFT_SKIP;
clock_gettime(clockid, &now);
if (!in_order(target, now))
- return -1;
+ return KSFT_FAIL;
/* Second check reltime */
clock_gettime(clockid, &now);
@@ -80,8 +78,8 @@ int nanosleep_test(int clockid, long long ns)
clock_gettime(clockid, &now);
if (!in_order(target, now))
- return -1;
- return 0;
+ return KSFT_FAIL;
+ return KSFT_PASS;
}
static void dummy_event_handler(int val)
@@ -100,38 +98,38 @@ static int nanosleep_test_remaining(int clockid)
sa.sa_handler = dummy_event_handler;
ret = sigaction(SIGALRM, &sa, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
ret = timer_create(clockid, NULL, &timer);
if (ret)
- return -1;
+ return KSFT_FAIL;
itimer.it_value.tv_nsec = NSEC_PER_SEC / 4;
ret = timer_settime(timer, 0, &itimer, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
rqtp.tv_nsec = NSEC_PER_SEC / 2;
ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
if (ret != EINTR)
- return -1;
+ return KSFT_FAIL;
ret = timer_delete(timer);
if (ret)
- return -1;
+ return KSFT_FAIL;
sa.sa_handler = SIG_DFL;
ret = sigaction(SIGALRM, &sa, NULL);
if (ret)
- return -1;
+ return KSFT_FAIL;
if (!in_order((struct timespec) {}, rmtp))
- return -1;
+ return KSFT_FAIL;
if (!in_order(rmtp, rqtp))
- return -1;
+ return KSFT_FAIL;
- return 0;
+ return KSFT_PASS;
}
int main(int argc, char **argv)
@@ -159,18 +157,18 @@ int main(int argc, char **argv)
length = 10;
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
- if (ret == UNSUPPORTED) {
+ if (ret == KSFT_SKIP) {
ksft_test_result_skip("%s\n", clock_name(clockid));
goto next;
}
- if (ret < 0) {
+ if (ret == KSFT_FAIL) {
ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
- if (ret < 0) {
+ if (ret == KSFT_FAIL) {
ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Explicitly list the tested clocks
2026-08-03 10:04 ` [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 2999620932be363a97c1028f5636deefe08adb06
Gitweb: https://git.kernel.org/tip/2999620932be363a97c1028f5636deefe08adb06
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:40 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: timers: nanosleep: Explicitly list the tested clocks
The test relies on the numeric values of the clockids.
As not all clocks are meant to be tested, this requires skipping some
clocks unconditionally, cluttering the result.
Use an equivalent, explicit list instead.
In addition to CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID and
CLOCK_HWSPECIFIC which were unconditionally skipped before, this also
unconditionally skips CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and
CLOCK_REALTIME_COARSE. clock_nanosleep() is not supported for those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-9-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 26 +++++++++------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 629e800..9dd6622 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -30,9 +30,6 @@
#include "clock-helpers.h"
#include "kselftest.h"
-/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
-#define CLOCK_HWSPECIFIC 10
-
#define UNSUPPORTED 0xf00f
/* returns 1 if a <= b, 0 otherwise */
@@ -141,20 +138,21 @@ int main(int argc, char **argv)
{
long long length;
int clockid, ret;
- int max_clocks = CLOCK_TAI + 1;
- ksft_print_header();
- ksft_set_plan(max_clocks);
+ static const clockid_t tested_clocks[] = {
+ CLOCK_REALTIME,
+ CLOCK_MONOTONIC,
+ CLOCK_BOOTTIME,
+ CLOCK_BOOTTIME_ALARM,
+ CLOCK_REALTIME_ALARM,
+ CLOCK_TAI,
+ };
- for (clockid = CLOCK_REALTIME; clockid < max_clocks; clockid++) {
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(tested_clocks));
- /* Skip cputime clockids since nanosleep won't increment cputime */
- if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
- clockid == CLOCK_THREAD_CPUTIME_ID ||
- clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%s\n", clock_name(clockid));
- continue;
- }
+ for (size_t clock_index = 0; clock_index < ARRAY_SIZE(tested_clocks); clock_index++) {
+ clockid = tested_clocks[clock_index];
fflush(stdout);
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: nanosleep: Drop output alignment
2026-08-03 10:04 ` [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 142a2d312e7bb8e5ad524a4f2115523cf4904732
Gitweb: https://git.kernel.org/tip/142a2d312e7bb8e5ad524a4f2115523cf4904732
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:39 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: timers: nanosleep: Drop output alignment
The padding of the clock name is pointless as nothing else is printed.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-8-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/nanosleep.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 7df86df..629e800 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -152,7 +152,7 @@ int main(int argc, char **argv)
if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
clockid == CLOCK_THREAD_CPUTIME_ID ||
clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%-31s\n", clock_name(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
continue;
}
@@ -162,21 +162,21 @@ int main(int argc, char **argv)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%-31s\n", clock_name(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
goto next;
}
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clock_name(clockid));
+ ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clock_name(clockid));
+ ksft_test_result_fail("%s\n", clock_name(clockid));
ksft_exit_fail();
}
- ksft_test_result_pass("%-31s\n", clock_name(clockid));
+ ksft_test_result_pass("%s\n", clock_name(clockid));
next:
ret = 0;
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: timers: Use clock_name() and constants from clock-helpers.h
2026-08-03 10:04 ` [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 54200b87489b39f9437a91e2156c4c2d90412704
Gitweb: https://git.kernel.org/tip/54200b87489b39f9437a91e2156c4c2d90412704
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:38 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: timers: Use clock_name() and constants from clock-helpers.h
Replace the many repetitions of custom clockid_t to string translation
with the clock_name() helper from clock-helpers.h.
Also drop the custom ?SEC_PER_?SEC definitions.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-7-910cbd485390@linutronix.de
---
tools/testing/selftests/timers/adjtick.c | 5 +-
tools/testing/selftests/timers/alarmtimer-suspend.c | 38 +----------
tools/testing/selftests/timers/inconsistency-check.c | 38 +---------
tools/testing/selftests/timers/leap-a-day.c | 3 +-
tools/testing/selftests/timers/mqueue-lat.c | 3 +-
tools/testing/selftests/timers/nanosleep.c | 42 +----------
tools/testing/selftests/timers/nsleep-lat.c | 36 +---------
tools/testing/selftests/timers/posix_timers.c | 36 ++++-----
tools/testing/selftests/timers/raw_skew.c | 3 +-
tools/testing/selftests/timers/set-2038.c | 3 +-
tools/testing/selftests/timers/set-timer-lat.c | 41 +----------
tools/testing/selftests/timers/valid-adjtimex.c | 4 +-
12 files changed, 47 insertions(+), 205 deletions(-)
diff --git a/tools/testing/selftests/timers/adjtick.c b/tools/testing/selftests/timers/adjtick.c
index 22d274d..68009a6 100644
--- a/tools/testing/selftests/timers/adjtick.c
+++ b/tools/testing/selftests/timers/adjtick.c
@@ -22,10 +22,9 @@
#include <sys/time.h>
#include <sys/timex.h>
#include <time.h>
-#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
+#include "clock-helpers.h"
+#include "kselftest.h"
#define MILLION 1000000
diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c b/tools/testing/selftests/timers/alarmtimer-suspend.c
index d55d5b0..120b3ce 100644
--- a/tools/testing/selftests/timers/alarmtimer-suspend.c
+++ b/tools/testing/selftests/timers/alarmtimer-suspend.c
@@ -29,10 +29,9 @@
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
#define SUSPEND_SECS 15
@@ -40,37 +39,6 @@ int alarmcount;
int alarm_clock_id;
struct timespec start_time;
-
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
-
long long timespec_sub(struct timespec a, struct timespec b)
{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
@@ -130,12 +98,12 @@ int main(void)
alarmcount = 0;
if (timer_create(alarm_clock_id, &se, &tm1) == -1) {
printf("timer_create failed, %s unsupported?: %s\n",
- clockstring(alarm_clock_id), strerror(errno));
+ clock_name(alarm_clock_id), strerror(errno));
break;
}
clock_gettime(alarm_clock_id, &start_time);
- printf("Start time (%s): %ld:%ld\n", clockstring(alarm_clock_id),
+ printf("Start time (%s): %ld:%ld\n", clock_name(alarm_clock_id),
start_time.tv_sec, start_time.tv_nsec);
printf("Setting alarm for every %i seconds\n", SUSPEND_SECS);
its1.it_value = start_time;
diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c
index 9ab7066..d7982ac 100644
--- a/tools/testing/selftests/timers/inconsistency-check.c
+++ b/tools/testing/selftests/timers/inconsistency-check.c
@@ -28,44 +28,14 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
#define CALLS_PER_LOOP 64
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -172,15 +142,15 @@ int main(int argc, char *argv[])
for (clockid = userclock; clockid < maxclocks; clockid++) {
if (clockid == CLOCK_HWSPECIFIC || clock_gettime(clockid, &ts)) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
continue;
}
if (consistency_test(clockid, runtime)) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
} else {
- ksft_test_result_pass("%-31s\n", clockstring(clockid));
+ ksft_test_result_pass("%-31s\n", clock_name(clockid));
}
}
ksft_exit_pass();
diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/selftests/timers/leap-a-day.c
index 71b4973..b93cb57 100644
--- a/tools/testing/selftests/timers/leap-a-day.c
+++ b/tools/testing/selftests/timers/leap-a-day.c
@@ -51,10 +51,9 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define CLOCK_TAI 11
time_t next_leap;
diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/selftests/timers/mqueue-lat.c
index ce8700c..fa4c3e3 100644
--- a/tools/testing/selftests/timers/mqueue-lat.c
+++ b/tools/testing/selftests/timers/mqueue-lat.c
@@ -29,10 +29,9 @@
#include <signal.h>
#include <errno.h>
#include <mqueue.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define TARGET_TIMEOUT 100000000 /* 100ms in nanoseconds */
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index ceff181..7df86df 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -27,44 +27,14 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
#define UNSUPPORTED 0xf00f
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- };
- return "UNKNOWN_CLOCKID";
-}
-
/* returns 1 if a <= b, 0 otherwise */
static inline int in_order(struct timespec a, struct timespec b)
{
@@ -182,7 +152,7 @@ int main(int argc, char **argv)
if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
clockid == CLOCK_THREAD_CPUTIME_ID ||
clockid == CLOCK_HWSPECIFIC) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
continue;
}
@@ -192,21 +162,21 @@ int main(int argc, char **argv)
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%-31s\n", clockstring(clockid));
+ ksft_test_result_skip("%-31s\n", clock_name(clockid));
goto next;
}
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
}
length *= 100;
}
ret = nanosleep_test_remaining(clockid);
if (ret < 0) {
- ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_test_result_fail("%-31s\n", clock_name(clockid));
ksft_exit_fail();
}
- ksft_test_result_pass("%-31s\n", clockstring(clockid));
+ ksft_test_result_pass("%-31s\n", clock_name(clockid));
next:
ret = 0;
}
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index 15f6493..d22973c 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -24,10 +24,9 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
@@ -35,35 +34,6 @@
#define UNSUPPORTED 0xf00f
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- };
- return "UNKNOWN_CLOCKID";
-}
-
struct timespec timespec_add(struct timespec ts, unsigned long long ns)
{
ts.tv_nsec += ns;
@@ -156,10 +126,10 @@ int main(int argc, char **argv)
}
if (ret == UNSUPPORTED) {
- ksft_test_result_skip("%s\n", clockstring(clockid));
+ ksft_test_result_skip("%s\n", clock_name(clockid));
} else {
ksft_test_result(ret >= 0, "%s\n",
- clockstring(clockid));
+ clock_name(clockid));
}
}
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index fa168d8..a92d4b9 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -19,11 +19,9 @@
#include <pthread.h>
#include <stdbool.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
-
#define DELAY 2
static void __fatal_error(const char *test, const char *name, const char *what)
@@ -143,8 +141,9 @@ static void check_itimer(int which, const char *name)
ksft_test_result(check_diff(start, end) == 0, "%s\n", name);
}
-static void check_timer_create(int which, const char *name)
+static void check_timer_create(int which)
{
+ const char *name = clock_name(which);
struct timespec start, end;
struct itimerspec val = {
.it_value.tv_sec = DELAY,
@@ -457,8 +456,9 @@ static void check_delete(void)
ksft_test_result(!tsig.signals, "check_delete\n");
}
-static void check_sigev_none(int which, const char *name)
+static void check_sigev_none(int which)
{
+ const char *name = clock_name(which);
struct timespec start, now;
struct itimerspec its;
struct sigevent sev;
@@ -495,8 +495,9 @@ static void check_sigev_none(int which, const char *name)
"check_sigev_none %s\n", name);
}
-static void check_gettime(int which, const char *name)
+static void check_gettime(int which)
{
+ const char *name = clock_name(which);
struct itimerspec its, prev;
struct timespec start, now;
struct sigevent sev;
@@ -548,8 +549,9 @@ static void check_gettime(int which, const char *name)
ksft_test_result(wraps > 1, "check_gettime %s\n", name);
}
-static void check_overrun(int which, const char *name)
+static void check_overrun(int which)
{
+ const char *name = clock_name(which);
struct timespec start, now;
struct tmrsig tsig = { };
struct itimerspec its;
@@ -691,7 +693,7 @@ int main(int argc, char **argv)
check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL");
check_itimer(ITIMER_PROF, "ITIMER_PROF");
check_itimer(ITIMER_REAL, "ITIMER_REAL");
- check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_timer_create(CLOCK_THREAD_CPUTIME_ID);
/*
* It's unfortunately hard to reliably test a timer expiration
@@ -702,7 +704,7 @@ int main(int argc, char **argv)
* to ensure true parallelism. So test only one thread until we
* find a better solution.
*/
- check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
+ check_timer_create(CLOCK_PROCESS_CPUTIME_ID);
check_timer_distribution();
if (run_sig_ign_tests) {
@@ -710,18 +712,18 @@ int main(int argc, char **argv)
check_sig_ign(1);
check_rearm();
check_delete();
- check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_sigev_none(CLOCK_MONOTONIC);
+ check_sigev_none(CLOCK_PROCESS_CPUTIME_ID);
+ check_gettime(CLOCK_MONOTONIC);
+ check_gettime(CLOCK_PROCESS_CPUTIME_ID);
+ check_gettime(CLOCK_THREAD_CPUTIME_ID);
} else {
ksft_print_msg("Skipping SIG_IGN tests on kernel < 6.13\n");
}
- check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
- check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
- check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
+ check_overrun(CLOCK_MONOTONIC);
+ check_overrun(CLOCK_PROCESS_CPUTIME_ID);
+ check_overrun(CLOCK_THREAD_CPUTIME_ID);
ksft_finished();
}
diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c
index 2dd16cb..0c87a8f 100644
--- a/tools/testing/selftests/timers/raw_skew.c
+++ b/tools/testing/selftests/timers/raw_skew.c
@@ -25,10 +25,9 @@
#include <sys/time.h>
#include <sys/timex.h>
#include <time.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define shift_right(x, s) ({ \
__typeof__(x) __x = (x); \
__typeof__(s) __s = (s); \
diff --git a/tools/testing/selftests/timers/set-2038.c b/tools/testing/selftests/timers/set-2038.c
index c123563..f522a30 100644
--- a/tools/testing/selftests/timers/set-2038.c
+++ b/tools/testing/selftests/timers/set-2038.c
@@ -27,10 +27,9 @@
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
#define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c
index e092c18..79ddba2 100644
--- a/tools/testing/selftests/timers/set-timer-lat.c
+++ b/tools/testing/selftests/timers/set-timer-lat.c
@@ -28,10 +28,9 @@
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
@@ -44,36 +43,6 @@ struct timespec start_time;
long long max_latency_ns;
int timer_fired_early;
-char *clockstring(int clockid)
-{
- switch (clockid) {
- case CLOCK_REALTIME:
- return "CLOCK_REALTIME";
- case CLOCK_MONOTONIC:
- return "CLOCK_MONOTONIC";
- case CLOCK_PROCESS_CPUTIME_ID:
- return "CLOCK_PROCESS_CPUTIME_ID";
- case CLOCK_THREAD_CPUTIME_ID:
- return "CLOCK_THREAD_CPUTIME_ID";
- case CLOCK_MONOTONIC_RAW:
- return "CLOCK_MONOTONIC_RAW";
- case CLOCK_REALTIME_COARSE:
- return "CLOCK_REALTIME_COARSE";
- case CLOCK_MONOTONIC_COARSE:
- return "CLOCK_MONOTONIC_COARSE";
- case CLOCK_BOOTTIME:
- return "CLOCK_BOOTTIME";
- case CLOCK_REALTIME_ALARM:
- return "CLOCK_REALTIME_ALARM";
- case CLOCK_BOOTTIME_ALARM:
- return "CLOCK_BOOTTIME_ALARM";
- case CLOCK_TAI:
- return "CLOCK_TAI";
- }
- return "UNKNOWN_CLOCKID";
-}
-
-
long long timespec_sub(struct timespec a, struct timespec b)
{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
@@ -104,7 +73,7 @@ void sigalarm(int signo)
void describe_timer(int flags, int interval)
{
printf("%-22s %s %s ",
- clockstring(clock_id),
+ clock_name(clock_id),
flags ? "ABSTIME":"RELTIME",
interval ? "PERIODIC":"ONE-SHOT");
}
@@ -130,12 +99,12 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
if ((clock_id == CLOCK_REALTIME_ALARM) ||
(clock_id == CLOCK_BOOTTIME_ALARM)) {
printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n",
- clockstring(clock_id),
+ clock_name(clock_id),
flags ? "ABSTIME":"RELTIME");
/* Indicate timer isn't set, so caller doesn't wait */
return 1;
}
- printf("%s - timer_create() failed\n", clockstring(clock_id));
+ printf("%s - timer_create() failed\n", clock_name(clock_id));
return -1;
}
@@ -152,7 +121,7 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
err = timer_settime(*tm1, flags, &its1, &its2);
if (err) {
- printf("%s - timer_settime() failed\n", clockstring(clock_id));
+ printf("%s - timer_settime() failed\n", clock_name(clock_id));
return -1;
}
diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c
index dc2559e..f641d5f 100644
--- a/tools/testing/selftests/timers/valid-adjtimex.c
+++ b/tools/testing/selftests/timers/valid-adjtimex.c
@@ -29,11 +29,9 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
+#include "clock-helpers.h"
#include "kselftest.h"
-#define NSEC_PER_SEC 1000000000LL
-#define USEC_PER_SEC 1000000LL
-
#define ADJ_SETOFFSET 0x0100
#include <sys/syscall.h>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] selftests: Add clock-helpers.h
2026-08-03 10:04 ` [PATCH v2 06/17] selftests: add clock-helpers.h Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits
Cc: thomas.weissschuh, Thomas Gleixner, John Stultz, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 431012dd0a291bc135eb88d8a62d7424576800fa
Gitweb: https://git.kernel.org/tip/431012dd0a291bc135eb88d8a62d7424576800fa
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:37 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
selftests: Add clock-helpers.h
Multiple selftests duplicate various clock-related functionality.
Add a new header to collect and deduplicate those.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-6-910cbd485390@linutronix.de
---
tools/testing/selftests/clock-helpers.h | 76 ++++++++++++++++++++++++-
1 file changed, 76 insertions(+)
create mode 100644 tools/testing/selftests/clock-helpers.h
diff --git a/tools/testing/selftests/clock-helpers.h b/tools/testing/selftests/clock-helpers.h
new file mode 100644
index 0000000..01451f5
--- /dev/null
+++ b/tools/testing/selftests/clock-helpers.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __CLOCK_HELPERS_H
+#define __CLOCK_HELPERS_H
+
+#include <sys/types.h>
+#include <time.h>
+
+#define MSEC_PER_SEC 1000LL
+#define USEC_PER_MSEC 1000LL
+#define NSEC_PER_USEC 1000LL
+#define NSEC_PER_MSEC 1000000LL
+#define USEC_PER_SEC 1000000LL
+#define NSEC_PER_SEC 1000000000LL
+#define PSEC_PER_SEC 1000000000000LL
+#define FSEC_PER_SEC 1000000000000000LL
+
+#ifndef CLOCK_AUX
+#define CLOCK_AUX 16
+#endif
+
+#ifndef MAX_AUX_CLOCKS
+#define MAX_AUX_CLOCKS 8
+#endif
+
+#ifndef CLOCK_AUX_LAST
+#define CLOCK_AUX_LAST (CLOCK_AUX + MAX_AUX_CLOCKS - 1)
+#endif
+
+__attribute__((unused))
+static inline const char *clock_name(clockid_t clockid)
+{
+ switch (clockid) {
+ case CLOCK_REALTIME:
+ return "CLOCK_REALTIME";
+ case CLOCK_MONOTONIC:
+ return "CLOCK_MONOTONIC";
+ case CLOCK_PROCESS_CPUTIME_ID:
+ return "CLOCK_PROCESS_CPUTIME_ID";
+ case CLOCK_THREAD_CPUTIME_ID:
+ return "CLOCK_THREAD_CPUTIME_ID";
+ case CLOCK_MONOTONIC_RAW:
+ return "CLOCK_MONOTONIC_RAW";
+ case CLOCK_REALTIME_COARSE:
+ return "CLOCK_REALTIME_COARSE";
+ case CLOCK_MONOTONIC_COARSE:
+ return "CLOCK_MONOTONIC_COARSE";
+ case CLOCK_BOOTTIME:
+ return "CLOCK_BOOTTIME";
+ case CLOCK_REALTIME_ALARM:
+ return "CLOCK_REALTIME_ALARM";
+ case CLOCK_BOOTTIME_ALARM:
+ return "CLOCK_BOOTTIME_ALARM";
+ case CLOCK_TAI:
+ return "CLOCK_TAI";
+ case CLOCK_AUX + 0:
+ return "CLOCK_AUX0";
+ case CLOCK_AUX + 1:
+ return "CLOCK_AUX1";
+ case CLOCK_AUX + 2:
+ return "CLOCK_AUX2";
+ case CLOCK_AUX + 3:
+ return "CLOCK_AUX3";
+ case CLOCK_AUX + 4:
+ return "CLOCK_AUX4";
+ case CLOCK_AUX + 5:
+ return "CLOCK_AUX5";
+ case CLOCK_AUX + 6:
+ return "CLOCK_AUX6";
+ case CLOCK_AUX + 7:
+ return "CLOCK_AUX7";
+ };
+ return "UNKNOWN_CLOCKID";
+}
+
+#endif /* __CLOCK_HELPERS_H */
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] timer_list: Use ktime_t over nanoseconds
2026-08-03 10:04 ` [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 859b069ec5a328bd0bca301f6b9d87ff1dfc4b1d
Gitweb: https://git.kernel.org/tip/859b069ec5a328bd0bca301f6b9d87ff1dfc4b1d
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:36 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
timer_list: Use ktime_t over nanoseconds
hrtimers use ktime_t in their implementation and API.
The timer list performs a lot of unnecessary conversion to nanoseconds
which make the code harder to read and are also wrong in case the values
ever become negative.
Remove the conversions.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-5-910cbd485390@linutronix.de
---
kernel/time/timer_list.c | 57 ++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index ccbbb2a..0406bf4 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -20,7 +20,7 @@
struct timer_list_iter {
int cpu;
bool second_pass;
- u64 now;
+ ktime_t now;
};
/*
@@ -44,19 +44,19 @@ static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
static void
print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
- int idx, u64 now)
+ int idx, ktime_t now)
{
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
SEQ_printf(m, ", S:%02x", timer->is_queued);
SEQ_printf(m, "\n");
- SEQ_printf(m, " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
- (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
- (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
- (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
- (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
+ SEQ_printf(m, " # expires at %lld-%lld nsecs [in %lld to %lld nsecs]\n",
+ (long long)hrtimer_get_softexpires(timer),
+ (long long)hrtimer_get_expires(timer),
+ (long long)ktime_sub(hrtimer_get_softexpires(timer), now),
+ (long long)ktime_sub(hrtimer_get_expires(timer), now));
}
-static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
struct timerqueue_linked_node *curr;
struct hrtimer *timer, tmp;
@@ -94,7 +94,7 @@ next_one:
}
static void
-print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+print_base(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
SEQ_printf(m, " .base: %p\n", base);
SEQ_printf(m, " .index: %d\n", base->index);
@@ -105,10 +105,10 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
(long long) base->offset);
#endif
SEQ_printf(m, "active timers:\n");
- print_active_timers(m, base, now + ktime_to_ns(base->offset));
+ print_active_timers(m, base, ktime_add(now, base->offset));
}
-static void print_cpu(struct seq_file *m, int cpu, u64 now)
+static void print_cpu(struct seq_file *m, int cpu, ktime_t now)
{
struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
int i;
@@ -124,12 +124,11 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(cpu_base->x))
-#define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(cpu_base->x)))
+#define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(cpu_base->x))
#ifdef CONFIG_HIGH_RES_TIMERS
- P_ns(expires_next);
+ P_ktime(expires_next);
P(hres_active);
P(nr_events);
P(nr_retries);
@@ -137,15 +136,14 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
P(max_hang_time);
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#ifdef CONFIG_TICK_ONESHOT
# define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(ts->x))
-# define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(ts->x)))
+# define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(ts->x))
# define P_flag(x, f) \
SEQ_printf(m, " .%-15s: %d\n", #x, !!(DIAG_READ(ts->flags) & (f)))
@@ -153,22 +151,22 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
struct tick_sched *ts = tick_get_tick_sched(cpu);
P_flag(nohz, TS_FLAG_NOHZ);
P_flag(highres, TS_FLAG_HIGHRES);
- P_ns(last_tick);
+ P_ktime(last_tick);
P_flag(tick_stopped, TS_FLAG_STOPPED);
P(idle_calls);
P(idle_sleeps);
- P_ns(idle_entrytime);
- P_ns(idle_waketime);
+ P_ktime(idle_entrytime);
+ P_ktime(idle_waketime);
P(last_jiffies);
P(next_timer);
- P_ns(idle_expires);
+ P_ktime(idle_expires);
SEQ_printf(m, "jiffies: %llu\n",
(unsigned long long)jiffies);
}
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#undef P_flag
#undef DIAG_READ
SEQ_printf(m, "\n");
@@ -201,8 +199,7 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
SEQ_printf(m, " mult: %u\n", dev->mult);
SEQ_printf(m, " shift: %u\n", dev->shift);
SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
- SEQ_printf(m, " next_event: %lld nsecs\n",
- (unsigned long long) ktime_to_ns(dev->next_event));
+ SEQ_printf(m, " next_event: %lld nsecs\n", (long long)dev->next_event);
SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
@@ -255,17 +252,17 @@ static void timer_list_show_tickdevices_header(struct seq_file *m)
}
#endif
-static inline void timer_list_header(struct seq_file *m, u64 now)
+static inline void timer_list_header(struct seq_file *m, ktime_t now)
{
SEQ_printf(m, "Timer List Version: v0.11\n");
SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
- SEQ_printf(m, "now at %lld nsecs\n", (unsigned long long)now);
+ SEQ_printf(m, "now at %lld nsecs\n", (long long)now);
SEQ_printf(m, "\n");
}
void sysrq_timer_list_show(void)
{
- u64 now = ktime_to_ns(ktime_get());
+ ktime_t now = ktime_get();
int cpu;
timer_list_header(NULL, now);
@@ -323,7 +320,7 @@ static void *timer_list_start(struct seq_file *file, loff_t *offset)
struct timer_list_iter *iter = file->private;
if (!*offset)
- iter->now = ktime_to_ns(ktime_get());
+ iter->now = ktime_get();
iter->cpu = -1;
iter->second_pass = false;
return move_iter(iter, *offset);
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] timer_list: Use standard 'long long' format placeholders
2026-08-03 10:04 ` [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 40e05cf391c8a815cb0a94c9d9e474ebd78807f9
Gitweb: https://git.kernel.org/tip/40e05cf391c8a815cb0a94c9d9e474ebd78807f9
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:35 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
timer_list: Use standard 'long long' format placeholders
'%Ld' and '%Lu' are GNU extensions. While they do work for kernel code,
checkpatch complains about them all the time. Replace them with the
standard placeholders for 'long long' types, namely '%lld' and '%llu'.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-4-910cbd485390@linutronix.de
---
kernel/time/timer_list.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 8823e7d..ccbbb2a 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -49,7 +49,7 @@ print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
SEQ_printf(m, ", S:%02x", timer->is_queued);
SEQ_printf(m, "\n");
- SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
+ SEQ_printf(m, " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
(unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
(unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
(long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
@@ -101,7 +101,7 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
SEQ_printf(m, " .resolution: %u nsecs\n", hrtimer_resolution);
#ifdef CONFIG_HIGH_RES_TIMERS
- SEQ_printf(m, " .offset: %Ld nsecs\n",
+ SEQ_printf(m, " .offset: %lld nsecs\n",
(long long) base->offset);
#endif
SEQ_printf(m, "active timers:\n");
@@ -122,10 +122,10 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#define DIAG_READ(x) data_race(READ_ONCE(x))
#define P(x) \
- SEQ_printf(m, " .%-15s: %Lu\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(cpu_base->x))
#define P_ns(x) \
- SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
(unsigned long long)ktime_to_ns(DIAG_READ(cpu_base->x)))
#ifdef CONFIG_HIGH_RES_TIMERS
@@ -141,10 +141,10 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#ifdef CONFIG_TICK_ONESHOT
# define P(x) \
- SEQ_printf(m, " .%-15s: %Lu\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(ts->x))
# define P_ns(x) \
- SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
+ SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
(unsigned long long)ktime_to_ns(DIAG_READ(ts->x)))
# define P_flag(x, f) \
SEQ_printf(m, " .%-15s: %d\n", #x, !!(DIAG_READ(ts->flags) & (f)))
@@ -162,7 +162,7 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
P(last_jiffies);
P(next_timer);
P_ns(idle_expires);
- SEQ_printf(m, "jiffies: %Lu\n",
+ SEQ_printf(m, "jiffies: %llu\n",
(unsigned long long)jiffies);
}
#endif
@@ -201,7 +201,7 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
SEQ_printf(m, " mult: %u\n", dev->mult);
SEQ_printf(m, " shift: %u\n", dev->shift);
SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
- SEQ_printf(m, " next_event: %Ld nsecs\n",
+ SEQ_printf(m, " next_event: %lld nsecs\n",
(unsigned long long) ktime_to_ns(dev->next_event));
SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
@@ -259,7 +259,7 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
{
SEQ_printf(m, "Timer List Version: v0.11\n");
SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
- SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
+ SEQ_printf(m, "now at %lld nsecs\n", (unsigned long long)now);
SEQ_printf(m, "\n");
}
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] hrtimer: Add a lockdep assertion to hrtimer_update_base()
2026-08-03 10:04 ` [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base() Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: d2e6ee3ecb76464e7146c1b4774383fee4b48146
Gitweb: https://git.kernel.org/tip/d2e6ee3ecb76464e7146c1b4774383fee4b48146
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:34 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
hrtimer: Add a lockdep assertion to hrtimer_update_base()
Document and verify that the hrtimer_cpu_base::lock is held at this point.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-3-910cbd485390@linutronix.de
---
kernel/time/hrtimer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 540561d..530d612 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -677,6 +677,8 @@ static ktime_t hrtimer_update_next_event(struct hrtimer_cpu_base *cpu_base)
static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
{
+ lockdep_assert_held(&base->lock);
+
ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
ktime_t *offs_tai = &base->clock_base[HRTIMER_BASE_TAI].offset;
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] timekeeping: Use u32 for clock_was_set_seq
2026-08-03 10:04 ` [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 406a037ce7a03a37bf2b03010791ea9343ecc233
Gitweb: https://git.kernel.org/tip/406a037ce7a03a37bf2b03010791ea9343ecc233
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:33 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
timekeeping: Use u32 for clock_was_set_seq
Use an explicitly sized type to make the code a bit more consistent
with other fields of the datastructure and other sequence counters.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-2-910cbd485390@linutronix.de
---
include/linux/hrtimer_bases.h | 2 +-
include/linux/timekeeper_internal.h | 2 +-
include/linux/timekeeping.h | 2 +-
kernel/time/hrtimer.c | 2 +-
kernel/time/timekeeping.c | 5 +++--
kernel/time/timekeeping.h | 2 +-
6 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/include/linux/hrtimer_bases.h b/include/linux/hrtimer_bases.h
index 70b99e6..d4c83ec 100644
--- a/include/linux/hrtimer_bases.h
+++ b/include/linux/hrtimer_bases.h
@@ -84,7 +84,7 @@ struct hrtimer_cpu_base {
raw_spinlock_t lock;
unsigned int cpu;
unsigned int active_bases;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
bool hres_active;
bool deferred_rearm;
bool deferred_needs_update;
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 9c198f6..fe077d9 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -169,7 +169,7 @@ struct timekeeper {
u32 cs_ns_to_cyc_mult;
u32 cs_ns_to_cyc_shift;
u64 cs_ns_to_cyc_maxns;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
u8 cs_was_changed_seq;
u8 clock_valid;
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 561313b..efa9442 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -303,7 +303,7 @@ struct system_time_snapshot {
ktime_t monoraw;
enum clocksource_ids cs_id;
enum clocksource_ids hw_csid;
- unsigned int clock_was_set_seq;
+ u32 clock_was_set_seq;
u8 cs_was_changed_seq;
u8 valid;
};
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 48ee17e..540561d 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -903,8 +903,8 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram)
static bool update_needs_ipi(struct hrtimer_cpu_base *cpu_base, unsigned int active)
{
struct hrtimer_clock_base *base;
- unsigned int seq;
ktime_t expires;
+ u32 seq;
/*
* Update the base offsets unconditionally so the following
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index d02103b..ea2e6e5 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1567,10 +1567,11 @@ int get_device_system_crosststamp(int (*get_time_fn)
struct system_device_crosststamp *xtstamp)
{
u64 syscnt_cycles, cycles, now, interval_start;
- unsigned int seq, clock_was_set_seq = 0;
ktime_t base_sys, base_raw, *offs;
+ u32 clock_was_set_seq = 0;
u64 nsec_sys, nsec_raw;
u8 cs_was_changed_seq;
+ unsigned int seq;
bool do_interp;
struct timekeeper *tk;
struct tk_data *tkd;
@@ -2843,7 +2844,7 @@ void do_timer(unsigned long ticks)
*
* Called from hrtimer_interrupt() or retrigger_next_event()
*/
-ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real,
+ktime_t ktime_get_update_offsets_now(u32 *cwsseq, ktime_t *offs_real,
ktime_t *offs_boot, ktime_t *offs_tai)
{
struct timekeeper *tk = &tk_core.timekeeper;
diff --git a/kernel/time/timekeeping.h b/kernel/time/timekeeping.h
index 198d060..4201f9e 100644
--- a/kernel/time/timekeeping.h
+++ b/kernel/time/timekeeping.h
@@ -4,7 +4,7 @@
/*
* Internal interfaces for kernel/time/
*/
-extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq,
+extern ktime_t ktime_get_update_offsets_now(u32 *cwsseq,
ktime_t *offs_real,
ktime_t *offs_boot,
ktime_t *offs_tai);
^ permalink raw reply [flat|nested] 35+ messages in thread
* [tip: timers/core] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock()
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
@ 2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric)
0 siblings, 0 replies; 35+ messages in thread
From: tip-bot2 for Thomas Weißschuh (Schneider Electric) @ 2026-08-11 16:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 4f39d3c19bdc6b9cd4a8de7cbc563264cac9a348
Gitweb: https://git.kernel.org/tip/4f39d3c19bdc6b9cd4a8de7cbc563264cac9a348
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:32 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:19 +02:00
timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock()
The current name is not clear about its behavior.
Rename it.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-1-910cbd485390@linutronix.de
---
include/linux/posix-timers.h | 2 +-
kernel/time/timekeeping.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 4117827..9a1a0c6 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -37,7 +37,7 @@ static inline int clockid_to_fd(const clockid_t clk)
return ~(clk >> 3);
}
-static inline bool clockid_aux_valid(clockid_t id)
+static inline bool clockid_is_aux_clock(clockid_t id)
{
return IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) && id >= CLOCK_AUX && id <= CLOCK_AUX_LAST;
}
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4e6d594..d02103b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -3101,7 +3101,7 @@ static inline unsigned int clockid_to_tkid(unsigned int id)
static inline struct tk_data *aux_get_tk_data(clockid_t id)
{
- if (!clockid_aux_valid(id))
+ if (!clockid_is_aux_clock(id))
return NULL;
return &timekeeper_data[clockid_to_tkid(id)];
}
@@ -3196,7 +3196,7 @@ EXPORT_SYMBOL_GPL(ktime_get_aux_ts64);
static int aux_get_res(clockid_t id, struct timespec64 *tp)
{
- if (!clockid_aux_valid(id))
+ if (!clockid_is_aux_clock(id))
return -ENODEV;
tp->tv_sec = aux_clock_resolution_ns() / NSEC_PER_SEC;
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2026-08-11 16:14 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 06/17] selftests: add clock-helpers.h Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] selftests: Add clock-helpers.h tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:13 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®