mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh (Schneider Electric)" <thomas.weissschuh@linutronix.de>
To: John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Stephen Boyd <sboyd@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	"Thomas Weißschuh (Schneider Electric)"
	<thomas.weissschuh@linutronix.de>
Subject: [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid()
Date: Mon, 30 Nov 2026 17:50:03 +0100	[thread overview]
Message-ID: <20261130-timekeeping-conditionals-v3-4-3f95edbfec4d@linutronix.de> (raw)
In-Reply-To: <20261130-timekeeping-conditionals-v3-0-3f95edbfec4d@linutronix.de>

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


      parent reply	other threads:[~2026-11-30 16:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Thomas Weißschuh (Schneider Electric) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130-timekeeping-conditionals-v3-4-3f95edbfec4d@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®