* [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks
@ 2026-11-30 16:49 Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 1/4] timekeeping: Move timekeeper_is_core_tk() up in the file Thomas Weißschuh (Schneider Electric)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-11-30 16:49 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
Cc: linux-kernel, Thomas Weißschuh (Schneider Electric)
Some of the conditionals around auxiliary timekeepers are known at
compile time but are currently checked at runtime.
Introduce and use some helpers to avoid the runtime overhead.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
Changes in v3:
- Rebase on current tip/timers/core.
- Improve the title of patch 3 a bit.
- Keep some more whitespace around the function definitions in patch 3.
- Link to v2: https://patch.msgid.link/20260908-timekeeping-conditionals-v2-0-5ebc3e7e1da0@linutronix.de
Changes in v2:
- Rebase on v7.3-rc1.
- Link to v1: https://patch.msgid.link/20260812-timekeeping-conditionals-v1-0-75ebe366677d@linutronix.de
---
Thomas Weißschuh (Schneider Electric) (4):
timekeeping: Move timekeeper_is_core_tk() up in the file
timekeeping: Use timekeeper_is_core_tk() in timekeeping_update_on_shadow()
timekeeping: Remove the unnecessary tk_is_aux()
timekeeping: Introduce and use timekeeper_is_clock_valid()
kernel/time/timekeeping.c | 39 ++++++++++++++++++---------------------
1 file changed, 18 insertions(+), 21 deletions(-)
---
base-commit: f21571ed8908094d4d1c15271487475e02864496
change-id: 20260701-timekeeping-conditionals-25e2d45d86d9
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/4] timekeeping: Move timekeeper_is_core_tk() up in the file
2026-11-30 16:49 [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks Thomas Weißschuh (Schneider Electric)
@ 2026-11-30 16:50 ` Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 2/4] timekeeping: Use timekeeper_is_core_tk() in timekeeping_update_on_shadow() Thomas Weißschuh (Schneider Electric)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-11-30 16:50 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
Cc: linux-kernel, Thomas Weißschuh (Schneider Electric)
New users are about to be introduced which require the definition
earlier in the file.
Move it.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timekeeping.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3668bd24fa4f..ac67cb636d7b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -93,6 +93,11 @@ static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)
tk->monotonic_to_aux = ktime_to_timespec64(offs);
}
+static inline bool timekeeper_is_core_tk(struct timekeeper *tk)
+{
+ return !IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tk->id == TIMEKEEPER_CORE;
+}
+
/* flag for if timekeeping is suspended */
int __read_mostly timekeeping_suspended;
@@ -1743,11 +1748,6 @@ int do_settimeofday64(const struct timespec64 *ts)
}
EXPORT_SYMBOL(do_settimeofday64);
-static inline bool timekeeper_is_core_tk(struct timekeeper *tk)
-{
- return !IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tk->id == TIMEKEEPER_CORE;
-}
-
/**
* __timekeeping_inject_offset - Adds or subtracts from the current time.
* @tkd: Pointer to the timekeeper to modify
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 2/4] timekeeping: Use timekeeper_is_core_tk() in timekeeping_update_on_shadow()
2026-11-30 16:49 [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 1/4] timekeeping: Move timekeeper_is_core_tk() up in the file Thomas Weißschuh (Schneider Electric)
@ 2026-11-30 16:50 ` Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 3/4] timekeeping: Remove the unnecessary tk_is_aux() Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid() Thomas Weißschuh (Schneider Electric)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-11-30 16:50 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
Cc: linux-kernel, Thomas Weißschuh (Schneider Electric)
If CONFIG_POSIX_AUX_CLOCKS is disabled, the timekeeper is known to be
the core timekeeper.
Use the helper to avoid the conditional at runtime in this case.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ac67cb636d7b..9d304a998758 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -845,7 +845,7 @@ static void timekeeping_update_from_shadow(struct tk_data *tkd, unsigned int act
tk_update_ktime_data(tk);
tk->tkr_mono.base_real = tk->tkr_mono.base + tk->offs_real;
- if (tk->id == TIMEKEEPER_CORE) {
+ if (timekeeper_is_core_tk(tk)) {
tk_update_ns_to_cyc(tk, &tkd->timekeeper);
update_vsyscall(tk);
update_pvclock_gtod(tk, action & TK_CLOCK_WAS_SET);
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 3/4] timekeeping: Remove the unnecessary tk_is_aux()
2026-11-30 16:49 [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 1/4] timekeeping: Move timekeeper_is_core_tk() up in the file Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 2/4] timekeeping: Use timekeeper_is_core_tk() in timekeeping_update_on_shadow() Thomas Weißschuh (Schneider Electric)
@ 2026-11-30 16:50 ` Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid() Thomas Weißschuh (Schneider Electric)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-11-30 16:50 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
Cc: linux-kernel, Thomas Weißschuh (Schneider Electric)
Any timekeeper which is not the core timekeeper is already known to be
an auxiliary one. There is no need for an additional conditional.
Remove the 'else if' and the now unused tk_is_aux().
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timekeeping.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 9d304a998758..601f21865622 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -66,10 +66,6 @@ static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
return ktime_get_aux_ts64(CLOCK_AUX + tkid - TIMEKEEPER_AUX_FIRST, ts);
}
-static inline bool tk_is_aux(const struct timekeeper *tk)
-{
- return tk->id >= TIMEKEEPER_AUX_FIRST && tk->id <= TIMEKEEPER_AUX_LAST;
-}
static inline struct tk_data *aux_get_tk_data(clockid_t id);
#else
static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
@@ -77,10 +73,6 @@ static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
return false;
}
-static inline bool tk_is_aux(const struct timekeeper *tk)
-{
- return false;
-}
static inline struct tk_data *aux_get_tk_data(clockid_t id)
{
return NULL;
@@ -852,7 +844,7 @@ static void timekeeping_update_from_shadow(struct tk_data *tkd, unsigned int act
update_fast_timekeeper(&tk->tkr_mono, &tk_fast_mono);
update_fast_timekeeper(&tk->tkr_raw, &tk_fast_raw);
- } else if (tk_is_aux(tk)) {
+ } else {
vdso_time_update_aux(tk);
}
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid()
2026-11-30 16:49 [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks Thomas Weißschuh (Schneider Electric)
` (2 preceding siblings ...)
2026-11-30 16:50 ` [PATCH v3 3/4] timekeeping: Remove the unnecessary tk_is_aux() Thomas Weißschuh (Schneider Electric)
@ 2026-11-30 16:50 ` Thomas Weißschuh (Schneider Electric)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-11-30 16:50 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
Cc: linux-kernel, Thomas Weißschuh (Schneider Electric)
If CONFIG_POSIX_AUX_CLOCKS is disabled only the core timekeeper exists
which is always valid.
Introduce and use a helper function to avoid the runtime conditional
in this case.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
kernel/time/timekeeping.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 601f21865622..284d9ff9fab3 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -90,6 +90,11 @@ static inline bool timekeeper_is_core_tk(struct timekeeper *tk)
return !IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tk->id == TIMEKEEPER_CORE;
}
+static inline bool timekeeper_is_clock_valid(const struct timekeeper *tk)
+{
+ return !IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tk->clock_valid;
+}
+
/* flag for if timekeeping is suspended */
int __read_mostly timekeeping_suspended;
@@ -1299,7 +1304,7 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst
seq = read_seqcount_begin(&tkd->seq);
/* Aux clocks can be invalid */
- if (!tk->clock_valid)
+ if (!timekeeper_is_clock_valid(tk))
return;
now = tk_clock_read_snapshot(&tk->tkr_mono, &chs);
@@ -3013,7 +3018,7 @@ static int __do_adjtimex(struct tk_data *tkd, struct __kernel_timex *txc,
guard(raw_spinlock_irqsave)(&tkd->lock);
- if (!tks->clock_valid)
+ if (!timekeeper_is_clock_valid(tks))
return -ENODEV;
if (txc->modes & ADJ_SETOFFSET) {
@@ -3128,7 +3133,7 @@ static void tk_aux_update_clocksource(void)
struct timekeeper *tks = &tkd->shadow_timekeeper;
guard(raw_spinlock_irqsave)(&tkd->lock);
- if (!tks->clock_valid)
+ if (!timekeeper_is_clock_valid(tks))
continue;
timekeeping_forward_now(tks);
@@ -3147,7 +3152,7 @@ static void tk_aux_advance(void)
struct tk_data *aux_tkd = &timekeeper_data[id + TIMEKEEPER_AUX_FIRST];
guard(raw_spinlock)(&aux_tkd->lock);
- if (aux_tkd->shadow_timekeeper.clock_valid)
+ if (timekeeper_is_clock_valid(&aux_tkd->shadow_timekeeper))
__timekeeping_advance(aux_tkd, TK_ADV_TICK);
}
}
@@ -3175,7 +3180,7 @@ bool ktime_get_aux(clockid_t id, ktime_t *kt)
aux_tk = &aux_tkd->timekeeper;
do {
seq = read_seqcount_begin(&aux_tkd->seq);
- if (!aux_tk->clock_valid)
+ if (!timekeeper_is_clock_valid(aux_tk))
return false;
base = ktime_add(aux_tk->tkr_mono.base, aux_tk->offs_aux);
@@ -3238,7 +3243,7 @@ static int aux_clock_set(const clockid_t id, const struct timespec64 *tnew)
aux_tks = &aux_tkd->shadow_timekeeper;
guard(raw_spinlock_irq)(&aux_tkd->lock);
- if (!aux_tks->clock_valid)
+ if (!timekeeper_is_clock_valid(aux_tks))
return -ENODEV;
/* Forward the timekeeper base time */
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 16:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 16:49 [PATCH v3 0/4] timekeeping: Avoid some runtime conditionals around auxiliary clocks Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 1/4] timekeeping: Move timekeeper_is_core_tk() up in the file Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 2/4] timekeeping: Use timekeeper_is_core_tk() in timekeeping_update_on_shadow() Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 3/4] timekeeping: Remove the unnecessary tk_is_aux() Thomas Weißschuh (Schneider Electric)
2026-11-30 16:50 ` [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid() 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®