From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057424; b=2TsnW5mqxA1vUdeQeItA2gQ4vSsZjfc7evjwSooPZbT6Oy7oOkGlPcuuwu/ZAV6ScUXc ca2wcPI5r+Odi4xjkGnGuEH/RdA/jr2AWt0gjSZNtySVh97PbY3X7YcckoKb/vW9TvLaR raH60HYE+dR1agDiJ1IfM71bM1iDAYYHObCS/Vgmifm8EPGFyNRFNGsPhTEYM1yg5vvCv kfOBajSeR1QaqaYWLWotKs7Hkur7Pb7p3BdNbJXlU8YsbHcDil1t299AnjyO6p/C+Jgp3 ksAWiBZ436Hvl6V0RYTTjBWmbScx6A72CpBNLhLRhrO0almIeEc259P6fA7s7WTjBew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796057424; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Developer-Signature:X-Developer-Key; bh=Xx3ifXC9/dT5XLHQyqcWk8YtCBFma6DnAqsjtx7507c=; b=tnymEdyhJBsjygv2+pOhGS7vI4qbDEQ+PlttTwjXLSaqRvVQijuaGRrAag53KFsPlacN KZGB1VUzFM4UiPeT1cNVVbcPTCTgh3sTZPiGdSvvShlLzBTofsvroIbbOtHYg97tJqGgJ m/PCMXgh+EZUzMt63vCFRsBlMvAcrXqed5pfL6x0rtEDNEYnPQDkSdLQJU5H57NepnzBW x793Ugqsmyi7PA9ls/qmZvwRhyBTGoXNVnHT2ETQmuN5hzxaEaq/KhxxyMy9v07AKl/p5 UZwpGjljt5DMHYBOSJKn9tNpce7wI8EMuLxQ/Uk7wd09RLGBnJ+eKLE1FvLBC5cvHoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b="fQEen8/J"; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Uoy5Q8Rv; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F35E8606A330 for ; Mon, 30 Nov 2026 16:50:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F35E8606A330 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.a=rsa-sha256 header.s=2020 header.b=fQEen8/J; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Uoy5Q8Rv From: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1796057422; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xx3ifXC9/dT5XLHQyqcWk8YtCBFma6DnAqsjtx7507c=; b=fQEen8/JX57w0ysajTXIJmRLwZOEsYifmKG8eR4duyo+elXVR+El0qpN49dEvG6D12L7Qk vH2KQTp+7Z1HM4hOICPRfHwVvHxgzxQ72jbcBkwj4XbDDTh/byxgjG4Or2LcRqp3vHcR5m zpRLS6ZHJg0nIssQ3n8yvCrAdhmR9rXz5BisdwNpTqnhfmrKJezgIO+RFaq3DkuEYhksmP LOU9k+soL4oHR4ja5tFWKtbb+MIu3sPVVCFhqcDrfcUvuYAhnp+wF0P7srJwtHkyXY5huy cIeygI6NWahP+3jIeo6yB9/PRWJEHBqZ1HHenR4pV+x51jJUw+phOL4E0LFcNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1796057422; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xx3ifXC9/dT5XLHQyqcWk8YtCBFma6DnAqsjtx7507c=; b=Uoy5Q8RvGmZeXRKEiy2IWk0jIraXwbltU2w6MLMqGEPHGnVWhn9pMU5Rl3ZOANSaH+6CSa 2vHVZTvdS/u+RrCQ== Date: Mon, 30 Nov 2026 17:50:03 +0100 Subject: [PATCH v3 4/4] timekeeping: Introduce and use timekeeper_is_clock_valid() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20261130-timekeeping-conditionals-v3-4-3f95edbfec4d@linutronix.de> References: <20261130-timekeeping-conditionals-v3-0-3f95edbfec4d@linutronix.de> In-Reply-To: <20261130-timekeeping-conditionals-v3-0-3f95edbfec4d@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1796057406; l=2859; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=qnyisVpe7cVQXZtfuuMol5dan/bqERJGpy9R+e5lBs4=; b=ZFhXicqFGTqoyWU2BZYfT8dp17ziy1367MJDByrGrU0U/0WOoCQ10JK7fSHVBOc5x182a29q+ 1m21oCNuxoEC8/2wYyAO7W+f1/5SArLQPd3BR2q8rsr89gMaG45MXo6 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= 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) --- 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