From patchwork Mon Aug 14 15:08:03 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: 135504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2823829vqi; Mon, 14 Aug 2023 08:35:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuqzTyFIfhzhe5umqHch9vFkdyybOnLsct6AtchOQgV0omCfjJX9/nC0ZKSRKtaaEB3WTB X-Received: by 2002:a2e:300e:0:b0:2b6:cf0f:1fbf with SMTP id w14-20020a2e300e000000b002b6cf0f1fbfmr7299519ljw.42.1692027303409; Mon, 14 Aug 2023 08:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692027303; cv=none; d=google.com; s=arc-20160816; b=OB7kHslioYlIXrv79Y2oUxhtZ4x6SUNaZeWbXPSXzAJfSWkda2kwWtDHU7vIOS0Mcp 3g9F9Kx9dZz6wwzP39GxUnEDsc1hvIOSyJzH5vQr6Codt9psdXYBevGhhXcApyniWtGO vg0BMPgepdvXdgYZJuRWB8b4iuEz56IE1XLkW8nG9ku1SQzCKwb20QMcZHvp8JMFte8a zjnZQtkf3al7Md+EfJnhFH8FJnD+kXvI9Ae7kVyakGFAZQ6dvjEHQ39zManp4RX7Txgk oD9d/4w7O2KjKh0PLXksD07Zi6gUH5GwomLa0MslQncQvnInXwUMk3jvrCmidiqgZaEf mn6w== 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=+POrq0SodKs+44G1WTBVPsIgZNhqV59p2iutKfz5rh4=; fh=utQzrRGpdyneC53QA2zUro1rWgCYMKhBZhFdjXY/HTE=; b=eZXlquCy2LvsSY4Ojd9ejqCqoFx8LME72k54eIL2VqfEEKpOoBPm+/4YiTl5nFp5OO P8gkilpnwQavKZurxxyKae2W6nMB87yEVmh3YAvaiYl3H2V9se/QKGB8hUyEbuVVof6P kGavPM7nDnTWN92XNGG64bf5c/RUhJonrQcWi2uZmcQMLHsrjaUo5eyTPp9pVdHXOxKg /W97ItMcZ8n9P/LVxYi5dRbhuT1Seo/M+9YhRqbx9yxnOQkTOx5ptwnFBPFBH5646+2R g3gFEaMkdQnaFiUnMqRmn9vh7FW4vNOdTaRfSfiPjMaDBVwwznGRONoJYLZejb/s/NT+ 53Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="ekIcT+U/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cFkaDA+M; 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 d6-20020a170906344600b0099d96df4cd9si3495668ejb.361.2023.08.14.08.34.35; Mon, 14 Aug 2023 08:35:03 -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="ekIcT+U/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cFkaDA+M; 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 S232596AbjHNPI2 (ORCPT + 99 others); Mon, 14 Aug 2023 11:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbjHNPIG (ORCPT ); Mon, 14 Aug 2023 11:08:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFE68E77; Mon, 14 Aug 2023 08:08:05 -0700 (PDT) Date: Mon, 14 Aug 2023 15:08:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692025684; 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=+POrq0SodKs+44G1WTBVPsIgZNhqV59p2iutKfz5rh4=; b=ekIcT+U/I0//Hx9VsYTVfMisaGsbYJ1oaOO1WHK0e8GjTd2PNNZz3i+i5wLBD4YGsoqQhd Za97wh9OoazqmX7FXsLegNPi8ozSPCBvUaniWT05hkZr7+NI8sxHthHJPZ4lgkre+xhvZW 1JFb+o2OVZkgm75sUAK5K8E2nO1mvyuHWUqayis1AWggnzFgMtxVLd7Z0DBEEwU5jDx0OF ygOK3yZE3JzrnBvgpAIIyPmaKdpXyAQRVRANhdG37g2gWSo+CxzRhv+xucN+7KZSB+MBoE /rSEbXoJ+kp60mRS0R+9RlQex84JXDyTcsJd2VbY0emXxMOLxwZChrkpMTs1Bw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692025684; 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=+POrq0SodKs+44G1WTBVPsIgZNhqV59p2iutKfz5rh4=; b=cFkaDA+MEVg9pJoAx9woy9pS+aalsUAreBYLvrfrOr/Dhte7ho9q7ByPqnA+uaNriN0zUs i44ZxOkiuuaO7vBQ== 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_core_cpu_{starting,deactivate}() Cc: "Peter Zijlstra (Intel)" , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230801211812.371787909@infradead.org> References: <20230801211812.371787909@infradead.org> MIME-Version: 1.0 Message-ID: <169202568347.27769.10237844051102997046.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: 1773064846516016790 X-GMAIL-MSGID: 1774219221441221138 The following commit has been merged into the sched/core branch of tip: Commit-ID: 7170509cadbb76e5fa7d7b090d2cbdb93d56a2de Gitweb: https://git.kernel.org/tip/7170509cadbb76e5fa7d7b090d2cbdb93d56a2de Author: Peter Zijlstra AuthorDate: Tue, 01 Aug 2023 22:41:30 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 14 Aug 2023 17:01:27 +02:00 sched: Simplify sched_core_cpu_{starting,deactivate}() 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.371787909@infradead.org --- kernel/sched/core.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f113a44..efe3848 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6400,20 +6400,24 @@ static void queue_core_balance(struct rq *rq) queue_balance_callback(rq, &per_cpu(core_balance_head, rq->cpu), sched_core_balance); } +DEFINE_LOCK_GUARD_1(core_lock, int, + sched_core_lock(*_T->lock, &_T->flags), + sched_core_unlock(*_T->lock, &_T->flags), + unsigned long flags) + static void sched_core_cpu_starting(unsigned int cpu) { const struct cpumask *smt_mask = cpu_smt_mask(cpu); struct rq *rq = cpu_rq(cpu), *core_rq = NULL; - unsigned long flags; int t; - sched_core_lock(cpu, &flags); + guard(core_lock)(&cpu); WARN_ON_ONCE(rq->core != rq); /* if we're the first, we'll be our own leader */ if (cpumask_weight(smt_mask) == 1) - goto unlock; + return; /* find the leader */ for_each_cpu(t, smt_mask) { @@ -6427,7 +6431,7 @@ static void sched_core_cpu_starting(unsigned int cpu) } if (WARN_ON_ONCE(!core_rq)) /* whoopsie */ - goto unlock; + return; /* install and validate core_rq */ for_each_cpu(t, smt_mask) { @@ -6438,29 +6442,25 @@ static void sched_core_cpu_starting(unsigned int cpu) WARN_ON_ONCE(rq->core != core_rq); } - -unlock: - sched_core_unlock(cpu, &flags); } static void sched_core_cpu_deactivate(unsigned int cpu) { const struct cpumask *smt_mask = cpu_smt_mask(cpu); struct rq *rq = cpu_rq(cpu), *core_rq = NULL; - unsigned long flags; int t; - sched_core_lock(cpu, &flags); + guard(core_lock)(&cpu); /* if we're the last man standing, nothing to do */ if (cpumask_weight(smt_mask) == 1) { WARN_ON_ONCE(rq->core != rq); - goto unlock; + return; } /* if we're not the leader, nothing to do */ if (rq->core != rq) - goto unlock; + return; /* find a new leader */ for_each_cpu(t, smt_mask) { @@ -6471,7 +6471,7 @@ static void sched_core_cpu_deactivate(unsigned int cpu) } if (WARN_ON_ONCE(!core_rq)) /* impossible */ - goto unlock; + return; /* copy the shared state to the new leader */ core_rq->core_task_seq = rq->core_task_seq; @@ -6493,9 +6493,6 @@ static void sched_core_cpu_deactivate(unsigned int cpu) rq = cpu_rq(t); rq->core = core_rq; } - -unlock: - sched_core_unlock(cpu, &flags); } static inline void sched_core_cpu_dying(unsigned int cpu)