From nobody Thu Dec 18 18:19:43 2025 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 B0BFFC04E69 for ; Mon, 14 Aug 2023 15:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232725AbjHNPIg (ORCPT ); Mon, 14 Aug 2023 11:08:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232647AbjHNPIH (ORCPT ); Mon, 14 Aug 2023 11:08:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82CB10DB; Mon, 14 Aug 2023 08:08:06 -0700 (PDT) Date: Mon, 14 Aug 2023 15:08:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692025685; 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=4MG8zIdJaSPttNahgRZX3O6vRsNEXcaW746LCNK2vMc=; b=RoDhZ4+Kl0lbICE+t7kADNeImv/UR2CKzyWTtj54Z0UAkt9j7WYeSc/hZLy60a3oF+sqhz VvSc3qjnR5lC7AgtDETNtQ3ELCLqDQh2F1kBE4j8xZxoMcHbXjRwKW0VEkDkQhZ/U+Tr31 6KCw5Vi6RUd44rkFrccw6VAKT/51+9un5RjDTpnvAGeCHvK93Oz40TBPyXabjGt4Ql/sXq pKCU9kxb3o5Mndj5k+LzmRUizKbNABYPXOpqInETIACPseg/U42zE1ql6tdBGGcQXgL5Lf vT3Nz+iRgexIF7K5VImEIs7elpHqTNFSRIDVPv+uQyoJoxXDYm8TV6qtMzEtRg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692025685; 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=4MG8zIdJaSPttNahgRZX3O6vRsNEXcaW746LCNK2vMc=; b=Q5Qcc+x0j1p3HtKhvPdVshLubnm2DRKWX8qFvEYilchkZEVBcwrM6jDi4MDFHqV9TqnVmd epaq5PcTpj8+PTCA== 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: Simplify sched_exec() Cc: "Peter Zijlstra (Intel)" , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230801211812.168490417@infradead.org> References: <20230801211812.168490417@infradead.org> MIME-Version: 1.0 Message-ID: <169202568491.27769.6494521766531042551.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: 4bdada79f3464d85f6e187213c088e7c934e0554 Gitweb: https://git.kernel.org/tip/4bdada79f3464d85f6e187213c088e7c9= 34e0554 Author: Peter Zijlstra AuthorDate: Tue, 01 Aug 2023 22:41:27 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 14 Aug 2023 17:01:26 +02:00 sched: Simplify sched_exec() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Link: https://lore.kernel.org/r/20230801211812.168490417@infradead.org --- kernel/sched/core.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 68bd68d..cd7f2ed 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5498,23 +5498,20 @@ unsigned int nr_iowait(void) void sched_exec(void) { struct task_struct *p =3D current; - unsigned long flags; + struct migration_arg arg; int dest_cpu; =20 - raw_spin_lock_irqsave(&p->pi_lock, flags); - dest_cpu =3D p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC); - if (dest_cpu =3D=3D smp_processor_id()) - goto unlock; + scoped_guard (raw_spinlock_irqsave, &p->pi_lock) { + dest_cpu =3D p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC); + if (dest_cpu =3D=3D smp_processor_id()) + return; =20 - if (likely(cpu_active(dest_cpu))) { - struct migration_arg arg =3D { p, dest_cpu }; + if (unlikely(!cpu_active(dest_cpu))) + return; =20 - raw_spin_unlock_irqrestore(&p->pi_lock, flags); - stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg); - return; + arg =3D (struct migration_arg){ p, dest_cpu }; } -unlock: - raw_spin_unlock_irqrestore(&p->pi_lock, flags); + stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg); } =20 #endif