[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175129592646.406.9501444922223792636.tip-bot2@tip-bot2>
Date: Mon, 30 Jun 2025 15:05:26 -0000
From: "tip-bot2 for Thomas Gleixner" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Thomas Gleixner <tglx@...utronix.de>, John Stultz <jstultz@...gle.com>,
x86@...nel.org, linux-kernel@...r.kernel.org
Subject: [tip: timers/ptp] timekeeping: Update auxiliary timekeepers on
clocksource change
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 9f7729480a2c771bbe49b7eab034a8eaa5e27bfb
Gitweb: https://git.kernel.org/tip/9f7729480a2c771bbe49b7eab034a8eaa5e27bfb
Author: Thomas Gleixner <tglx@...utronix.de>
AuthorDate: Wed, 25 Jun 2025 20:38:29 +02:00
Committer: Thomas Gleixner <tglx@...utronix.de>
CommitterDate: Fri, 27 Jun 2025 20:13:12 +02:00
timekeeping: Update auxiliary timekeepers on clocksource change
Propagate a system clocksource change to the auxiliary timekeepers so that
they can pick up the new clocksource.
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Acked-by: John Stultz <jstultz@...gle.com>
Link: https://lore.kernel.org/all/20250625183757.803890875@linutronix.de
---
kernel/time/timekeeping.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 7d3693a..ee97570 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -119,8 +119,10 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned = {
#ifdef CONFIG_POSIX_AUX_CLOCKS
static __init void tk_aux_setup(void);
+static void tk_aux_update_clocksource(void);
#else
static inline void tk_aux_setup(void) { }
+static inline void tk_aux_update_clocksource(void) { }
#endif
unsigned long timekeeper_lock_irqsave(void)
@@ -1548,6 +1550,8 @@ static int change_clocksource(void *data)
timekeeping_update_from_shadow(&tk_core, TK_UPDATE_ALL);
}
+ tk_aux_update_clocksource();
+
if (old) {
if (old->disable)
old->disable(old);
@@ -2651,6 +2655,35 @@ EXPORT_SYMBOL(hardpps);
#endif /* CONFIG_NTP_PPS */
#ifdef CONFIG_POSIX_AUX_CLOCKS
+
+/*
+ * Bitmap for the activated auxiliary timekeepers to allow lockless quick
+ * checks in the hot paths without touching extra cache lines. If set, then
+ * the state of the corresponding timekeeper has to be re-checked under
+ * timekeeper::lock.
+ */
+static unsigned long aux_timekeepers;
+
+/* Invoked from timekeeping after a clocksource change */
+static void tk_aux_update_clocksource(void)
+{
+ unsigned long active = READ_ONCE(aux_timekeepers);
+ unsigned int id;
+
+ for_each_set_bit(id, &active, BITS_PER_LONG) {
+ struct tk_data *tkd = &timekeeper_data[id + TIMEKEEPER_AUX_FIRST];
+ struct timekeeper *tks = &tkd->shadow_timekeeper;
+
+ guard(raw_spinlock_irqsave)(&tkd->lock);
+ if (!tks->clock_valid)
+ continue;
+
+ timekeeping_forward_now(tks);
+ tk_setup_internals(tks, tk_core.timekeeper.tkr_mono.clock);
+ timekeeping_update_from_shadow(tkd, TK_UPDATE_ALL);
+ }
+}
+
static __init void tk_aux_setup(void)
{
for (int i = TIMEKEEPER_AUX_FIRST; i <= TIMEKEEPER_AUX_LAST; i++)
Powered by blists - more mailing lists