From patchwork Mon Jun 5 19:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 103469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2913149vqr; Mon, 5 Jun 2023 12:41:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PMpQ93h6pMFy4h9ch8q8E2i6br7gTYC1FBatmUKJubOs8RzSuRdsRFXEKyagebA71JySP X-Received: by 2002:a17:902:f54e:b0:1b0:524b:e597 with SMTP id h14-20020a170902f54e00b001b0524be597mr17476plf.2.1685994085473; Mon, 05 Jun 2023 12:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685994085; cv=none; d=google.com; s=arc-20160816; b=D5nZy2wwo0UYl6cWegxijn8pckOUHzAQEECY3sd31d7rnqUqgL9VoUyqBTHZRbL0q3 0pxjtVfGEE2Y2npFOraoqFPEF+RT7Rh8BVt494qvH9aPlqh9kqk5MPgpLrdSJY0zrB3s SYmtblEyXM6qwauVHG+vy8H5afaB9jWm2t3eClBpJ4b/soA3WcWO4+xCdfYyAMXPp9fU c0+PUAv4zL+F9FOrW77xi1JEsVB8hFviQ5uiAQXS1OYl2A7vxKAnzrFx+b/lZH0Z2M+B qYwVDIH6n7Vu7mlzj7i9v8L4BSF2FHe6y3X93hoS8v7yngvfWMuMDoAYQRM2CioDtgt6 w6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=loUCh3mQ7cd9tnMZzQQVTLxAaBWXXDkTcaTj6SaaSWc=; b=WCog8k1sNCCvohjQao7dfCV/QkIAZVdRhvKFx3N3n5o1j+ta6rrBcsWkkqfmdhweT1 L7GSHoINbOx6G4F0NsZ5bk/ylGIv0TeLxViUT4PVCjHCD1v1abkUTspk94SwwrUfXnR3 up3noa961M7yfot3Y6p+MIBt6BiECDUcM2SbClpp51/UsIIkjuWtXmOA/utDEUdG9uCx k920QiKywkigGX9i/VkqkL0rHJZeOH/3B9polRiNe5IM9t0OaYZ4QLGNaFmN0H8iNOLG EnJjMe2U5lbGySd63ahH4SAUocoluqPm6CF0PXc3f79ZdB7Lj/GzBStTva+1qyO56lML BguQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="1A1sUf/D"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902ea0300b001a50dcd10c2si5916158plg.247.2023.06.05.12.41.13; Mon, 05 Jun 2023 12:41:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="1A1sUf/D"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235442AbjFETQ0 (ORCPT + 99 others); Mon, 5 Jun 2023 15:16:26 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766318491911363004?= X-GMAIL-MSGID: =?utf-8?q?1767892934449584930?= The following commit has been merged into the sched/core branch of tip: Commit-ID: fb7d4948c4da2dbd26da4b7ec76bbd2f19ff862a Gitweb: https://git.kernel.org/tip/fb7d4948c4da2dbd26da4b7ec76bbd2f19ff862a 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_notrace_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_CLOCK) +extern u64 sched_clock_noinstr(void); +#else +static __always_inline u64 sched_clock_noinstr(void) +{ + return sched_clock(); +} +#endif /* * See the comment in kernel/sched/clock.c @@ -45,6 +54,11 @@ static inline u64 cpu_clock(int cpu) return sched_clock(); } +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); } +extern u64 local_clock_noinstr(void); extern u64 local_clock(void); #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 sched_clock_data *scd) s64 delta; again: - now = sched_clock(); + now = sched_clock_noinstr(); delta = now - scd->tick_raw; if (unlikely(delta < 0)) delta = 0; @@ -293,22 +293,29 @@ again: return clock; } -noinstr u64 local_clock(void) +noinstr u64 local_clock_noinstr(void) { u64 clock; if (static_branch_likely(&__sched_clock_stable)) - return sched_clock() + __sched_clock_offset; + return sched_clock_noinstr() + __sched_clock_offset; if (!static_branch_likely(&sched_clock_running)) - return sched_clock(); + return sched_clock_noinstr(); - preempt_disable_notrace(); clock = sched_clock_local(this_scd()); - preempt_enable_notrace(); return clock; } + +u64 local_clock(void) +{ + u64 now; + preempt_disable_notrace(); + now = local_clock_noinstr(); + preempt_enable_notrace(); + return now; +} EXPORT_SYMBOL_GPL(local_clock); static notrace u64 sched_clock_remote(struct sched_clock_data *scd)