From nobody Sun Feb 8 06:21:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 709B6C7EE2E for ; Mon, 5 Jun 2023 19:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235349AbjFETQ1 (ORCPT ); Mon, 5 Jun 2023 15:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235316AbjFETQT (ORCPT ); Mon, 5 Jun 2023 15:16:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 242EA106; Mon, 5 Jun 2023 12:16:18 -0700 (PDT) Date: Mon, 05 Jun 2023 19:16:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685992576; h=from:from:sender:sender:reply-to: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=loUCh3mQ7cd9tnMZzQQVTLxAaBWXXDkTcaTj6SaaSWc=; b=1A1sUf/DK+dYMcVeqdxtMmTg4olFzIbCXci5FVoAnjCg4N++wjHU9MdL0ejAhEV7tkknb8 Bt10svxOvrFPdMV5smeyMa+rSRCFjUOoCCMpVBH1jkaZu7Jrn+SEaHq02KhoXdmHV/r2Uz +0Vz/jjW9Z/+yI78euoZojqUVj641CplVeKTRTljraoYwY6349sg+Hfz7Iqkh99vwKOmuG aPnF4eDJe9Ak+/o19dC5oDye9KeIRfirzuwvuZCFqgJyBuGkiy6YgxDJLyq74WIqn0Tij3 knKctEALFu0Ldpqk4n6WddjcgBsSh1kxvxEp3F8VJIFN/e6RgU4CjQ1G7yC9/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685992576; h=from:from:sender:sender:reply-to: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=loUCh3mQ7cd9tnMZzQQVTLxAaBWXXDkTcaTj6SaaSWc=; b=IOufVU2FZqxbeTIqsnA1d9LwDWWJ1cb25k0T+wS/NzbAmcHty0/dhciHpQLhw+lGdaaZoN zeg1vSjG1otmsLCQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/clock: Provide local_clock_noinstr() Cc: "Peter Zijlstra (Intel)" , Michael Kelley , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230519102715.978624636@infradead.org> References: <20230519102715.978624636@infradead.org> MIME-Version: 1.0 Message-ID: <168599257584.404.17317155359728357563.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: fb7d4948c4da2dbd26da4b7ec76bbd2f19ff862a Gitweb: https://git.kernel.org/tip/fb7d4948c4da2dbd26da4b7ec76bbd2f1= 9ff862a Author: Peter Zijlstra AuthorDate: Fri, 19 May 2023 12:21:10 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 05 Jun 2023 21:11:09 +02:00 sched/clock: Provide local_clock_noinstr() Now that all ARCH_WANTS_NO_INSTR architectures (arm64, loongarch, s390, x86) provide sched_clock_noinstr(), use this to provide local_clock_noinstr(). This local_clock_noinstr() will be safe to use from noinstr code with the assumption that any such noinstr code is non-preemptible (it had better be, entry code will have IRQs disabled while __cpuidle must have preemption disabled). Specifically, preempt_enable_notrace(), a common part of many a sched_clock() implementation calls out to schedule() -- even though, per the above, it will never trigger -- which frustrates noinstr validation. vmlinux.o: warning: objtool: local_clock+0xb5: call to preempt_schedule_n= otrace_thunk() leaves .noinstr.text section Signed-off-by: Peter Zijlstra (Intel) Tested-by: Michael Kelley # Hyper-V Link: https://lore.kernel.org/r/20230519102715.978624636@infradead.org --- include/linux/sched/clock.h | 17 ++++++++++++++++- kernel/sched/clock.c | 19 +++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/linux/sched/clock.h b/include/linux/sched/clock.h index ca008f7..196f0ca 100644 --- a/include/linux/sched/clock.h +++ b/include/linux/sched/clock.h @@ -12,7 +12,16 @@ * * Please use one of the three interfaces below. */ -extern unsigned long long notrace sched_clock(void); +extern u64 sched_clock(void); + +#if defined(CONFIG_ARCH_WANTS_NO_INSTR) || defined(CONFIG_GENERIC_SCHED_CL= OCK) +extern u64 sched_clock_noinstr(void); +#else +static __always_inline u64 sched_clock_noinstr(void) +{ + return sched_clock(); +} +#endif =20 /* * See the comment in kernel/sched/clock.c @@ -45,6 +54,11 @@ static inline u64 cpu_clock(int cpu) return sched_clock(); } =20 +static __always_inline u64 local_clock_noinstr(void) +{ + return sched_clock_noinstr(); +} + static __always_inline u64 local_clock(void) { return sched_clock(); @@ -79,6 +93,7 @@ static inline u64 cpu_clock(int cpu) return sched_clock_cpu(cpu); } =20 +extern u64 local_clock_noinstr(void); extern u64 local_clock(void); =20 #endif diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index b5cc2b5..5a575a0 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -266,7 +266,7 @@ static __always_inline u64 sched_clock_local(struct sch= ed_clock_data *scd) s64 delta; =20 again: - now =3D sched_clock(); + now =3D sched_clock_noinstr(); delta =3D now - scd->tick_raw; if (unlikely(delta < 0)) delta =3D 0; @@ -293,22 +293,29 @@ again: return clock; } =20 -noinstr u64 local_clock(void) +noinstr u64 local_clock_noinstr(void) { u64 clock; =20 if (static_branch_likely(&__sched_clock_stable)) - return sched_clock() + __sched_clock_offset; + return sched_clock_noinstr() + __sched_clock_offset; =20 if (!static_branch_likely(&sched_clock_running)) - return sched_clock(); + return sched_clock_noinstr(); =20 - preempt_disable_notrace(); clock =3D sched_clock_local(this_scd()); - preempt_enable_notrace(); =20 return clock; } + +u64 local_clock(void) +{ + u64 now; + preempt_disable_notrace(); + now =3D local_clock_noinstr(); + preempt_enable_notrace(); + return now; +} EXPORT_SYMBOL_GPL(local_clock); =20 static notrace u64 sched_clock_remote(struct sched_clock_data *scd)