From nobody Wed Oct 8 19:12:17 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C58B2D540B; Wed, 25 Jun 2025 18:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750876714; cv=none; b=LaaRh7+3nyWQKI1+yyFnuZCFfuXkHRrrGr1l4uNzMX93GvJqCdUrc6tsst2tLA8PRIor3dfAnUsHlV9tDfickhAI2LdcIBRPCthR/N3+Vvhev87M+VYUx1uW763Q+PQhgrg2O+kOyzdl7cn+DlwHByoMCM6jjE5O4uVy1Loldoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750876714; c=relaxed/simple; bh=96e9cJKXFPDju4/QSz3RUdC00J74o8uGRyHcUOVWnN8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=SRDg1B7NiGkA9kKgUY5CcdcP9nuHmvc/gKOcztiUUiiFqBsChD/HzjxlwsL4gj1pnrPl6gfv4GTL9Rzh9q3uRzDAWKh5QPmXiX5jFE4QmjnXKUmXo0q3EM6HR2E1RIn22/gXd/haVwpzfZOL4zXG/A9l62EZ+1ydGMpUxRQISmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fCdPmwJR; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+Cyx31IM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fCdPmwJR"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+Cyx31IM" Message-ID: <20250625183757.803890875@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750876710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=SJrzO2St6DYrac8L0oTt1CLLzIVb9v9DvCiT5mXNVHY=; b=fCdPmwJRg7Ou2R4hHzMxhWnOPrZgDleYTMjSd/DcmB/d9Xu8+2O3QWSYF8QcI6OadknX3q 7FpyZWxmWLn5SymB+NVBqp3YQF68rUg+SATplPniamuvgNLTPrmza+9R5W/GMel0BnuVnq 4SVUbEJ58J/c2o9pguJCH+U7UaTnaiewkYJzW8T+1gzPdgb+77YZyRpEsp5hnipJqIuBs7 XtTzpDjH121XIy/w2Z0lSL1M/on2YuHeVAQfZ6eUiv+o1oXHbvs9ju81XO5AwssI18a+JE uMjjRlilLp0FllCUPDUUErgZvWz7gjEx4OjO4c4NMJc7ayuNbPC5bh80N/PQrQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750876710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=SJrzO2St6DYrac8L0oTt1CLLzIVb9v9DvCiT5mXNVHY=; b=+Cyx31IMUHC8B125ju7SNCfyAAxBtEY//FGD0F2HUgWll/CpH4QMghvxlfE0B3r5PmQ1MI ktxNhZx7bo2uejDA== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch V3 01/11] timekeeping: Update auxiliary timekeepers on clocksource change References: <20250625182951.587377878@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 25 Jun 2025 20:38:29 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Propagate a system clocksource change to the auxiliary timekeepers so that they can pick up the new clocksource. Signed-off-by: Thomas Gleixner --- kernel/time/timekeeping.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) --- --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -119,8 +119,10 @@ static struct tk_fast tk_fast_raw ____c =20 #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 =20 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); } =20 + tk_aux_update_clocksource(); + if (old) { if (old->disable) old->disable(old); @@ -2651,6 +2655,30 @@ EXPORT_SYMBOL(hardpps); #endif /* CONFIG_NTP_PPS */ =20 #ifdef CONFIG_POSIX_AUX_CLOCKS + +/* Bitmap for the activated auxiliary timekeepers */ +static unsigned long aux_timekeepers; + +/* Invoked from timekeeping after a clocksource change */ +static void tk_aux_update_clocksource(void) +{ + unsigned long active =3D READ_ONCE(aux_timekeepers); + unsigned int id; + + for_each_set_bit(id, &active, BITS_PER_LONG) { + struct tk_data *tkd =3D &timekeeper_data[id + TIMEKEEPER_AUX_FIRST]; + struct timekeeper *tks =3D &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 =3D TIMEKEEPER_AUX_FIRST; i <=3D TIMEKEEPER_AUX_LAST; i++)