From patchwork Mon Aug 14 15:08:04 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: 135505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2824073vqi; Mon, 14 Aug 2023 08:35:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFreqk3cyNq4wEzulVFdS+9Bs/01MEw/In2S1M3eoCzUX+ZYSdbOAr326belIW3x+x7//ky X-Received: by 2002:a05:6a20:13cd:b0:12c:2dc7:74bc with SMTP id ho13-20020a056a2013cd00b0012c2dc774bcmr11500532pzc.46.1692027328988; Mon, 14 Aug 2023 08:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692027328; cv=none; d=google.com; s=arc-20160816; b=AQTHsF7/1SOBlqm5mOsW4z8ocJabSiVuqUIx4c1wpvrr2qFEJo5sy/ayuyii/CHnxE WbsxyzsP6jUNL02dnoZWdU2f5ysVjhMDHrOqJLntLjXwsW99CLhwl3sza5DV4MCyBQB+ TH5xnuBNj6kRtBk6jWN8qdNrQ0SW8r93hfRB8enOcHd0x5ZmytGC2WBa2Y5740AM3Whj Ecei3Ob1hNgBl7DDI/H8ZTDYIEBlPRaBr3LRNeehu1I/MbTQuJGB6v2XE2q9EMpuhDIU 4QEvOsN5UV1zClX8koVl5ixbxMPSQ77tY1P2SYHpMVdytDAnkj06ETDQzrvLE0ZjrfZN KAFg== 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=4MG8zIdJaSPttNahgRZX3O6vRsNEXcaW746LCNK2vMc=; fh=utQzrRGpdyneC53QA2zUro1rWgCYMKhBZhFdjXY/HTE=; b=W4TQhYj9l0bwRlFh02LQNx+kvDDACPR0iHiU1Q9hoHuUe0qSWsBwDqqeWfQdVmbAOp dEpVOJbrerCyJ1+oDMt9eLEKfCS/BZKNULGe5sgRwzNeVpT4CvXP0rFFw2dl8nEAdT/l /Igszhe+GhH+8T31XuFcaNusuZ6O/nvdB5y6u8AMnrF0rFoJ+WQ3CPWLP3RO/zzNsALe 7Av5MA5q+PuFtuMq53w5BQzvubl31QgY8Xi7r3g8A7jevNdyfh0Raio/ybGKnmEcC5/0 sGaw/x4Q+faEIlYRQDdj94hlcahZqou3FfdLIUybVay5Ssh3IJibN/6nGSaOB5DHyiiw 3YAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RoDhZ4+K; dkim=neutral (no key) header.i=@linutronix.de header.b=Q5Qcc+x0; 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 b36-20020a630c24000000b00563dfffe7b9si8688520pgl.810.2023.08.14.08.35.09; Mon, 14 Aug 2023 08:35:28 -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=RoDhZ4+K; dkim=neutral (no key) header.i=@linutronix.de header.b=Q5Qcc+x0; 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 S232710AbjHNPIf (ORCPT + 99 others); Mon, 14 Aug 2023 11:08:35 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773067694968694900 X-GMAIL-MSGID: 1774219248250156562 The following commit has been merged into the sched/core branch of tip: Commit-ID: 4bdada79f3464d85f6e187213c088e7c934e0554 Gitweb: https://git.kernel.org/tip/4bdada79f3464d85f6e187213c088e7c934e0554 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 = current; - unsigned long flags; + struct migration_arg arg; int dest_cpu; - raw_spin_lock_irqsave(&p->pi_lock, flags); - dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC); - if (dest_cpu == smp_processor_id()) - goto unlock; + scoped_guard (raw_spinlock_irqsave, &p->pi_lock) { + dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC); + if (dest_cpu == smp_processor_id()) + return; - if (likely(cpu_active(dest_cpu))) { - struct migration_arg arg = { p, dest_cpu }; + if (unlikely(!cpu_active(dest_cpu))) + return; - raw_spin_unlock_irqrestore(&p->pi_lock, flags); - stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg); - return; + arg = (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); } #endif