From patchwork Tue Sep 12 10:28:57 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: 138311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp537249vqx; Tue, 12 Sep 2023 09:43:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHU1beCopYJ3eZnWL490igO76PViDCkefYpBzaZ6uCNFuwKyb70Vjw9iM9i5nzKKYIDR3+J X-Received: by 2002:a05:6a21:78a7:b0:151:577:32d1 with SMTP id bf39-20020a056a2178a700b00151057732d1mr16884528pzc.22.1694537000447; Tue, 12 Sep 2023 09:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694537000; cv=none; d=google.com; s=arc-20160816; b=QIvg6gFtj1YVPoGUaHKJKcY+vYZoBzFy4/up4Sxmmzsz7MU9MYuBzoTCs0Ii2D9WyX s5ijQVxTI20q54TalahZMxOLoZCBe0tN3EFMKOnW56Dt+rOnKl+ME6zXjWmVyXKklaGB fuHh0L8HR30tf7am0ALRpco/K93jVpazODt/U2z+QLNggchV4j77/CZLwkhzU/0mZUGi /9BHFDsYXKd8QnsdP5gWbRS6kQYu6eNjcjJnpkRRvi8KnAcafJo4251C3qqLmguCRhD3 Qb0R1Nao9KxoU3mtaf3eG71/8lVOq7BgEyvvuGCw4lzjfGGUntK6APJ/7QnsOHlskiWO 6a4w== 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:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=VXRRfkFwSrMNvUqDICWKRhyF5qixjDDPRyBswJVjB5g=; fh=H2MkSknZKy/XcUE0SNWlqZifRHvGVZQUr5cmv0Cbtz8=; b=WnacONmQXoZoLii9rZW6cCrLd3NC/qIPuX6l7mPTpGYXmRdQklh8hyJwXaHDmW9Z84 72NCosYSK7T/x4dn7K6lc4WvA+ftOE4GzXvGzsS2EaWNLFmXvv0cRzqixpOqlIqIQLi+ /zNPUpbBKSGoOFSpHbe16fK2HuSyijJeOcCeVDadWit3hey/sxIgXSDVMTB0KhCYg9Ew o5kr+l/iYdJlSE4auBv/pYeCCB2AtaCpKNet4gpw1BPoby7B2bOh4xG9pFNrkZnag8tC KtYV0T1CLd6/v1XLthsfZNp66JVyWl7kbMZ1FOuG9WDntVOmZJ/z6vxrDflR8sIpJ9Fe qK/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VKa2aIhn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o24-20020a637318000000b005774c8b658dsi5424963pgc.316.2023.09.12.09.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:43:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VKa2aIhn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C9FC280E4FFB; Tue, 12 Sep 2023 03:34:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234198AbjILKdP (ORCPT + 37 others); Tue, 12 Sep 2023 06:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234380AbjILKag (ORCPT ); Tue, 12 Sep 2023 06:30:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4197B171F; Tue, 12 Sep 2023 03:28:59 -0700 (PDT) Date: Tue, 12 Sep 2023 10:28:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694514537; 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; bh=VXRRfkFwSrMNvUqDICWKRhyF5qixjDDPRyBswJVjB5g=; b=VKa2aIhn3L2I725I6DMPv3XQvNl5zPYoUvPze6uTxVLOjWFHrNuOgRY4Wlcsdd+8zGUSlT JxyoqtoxKEyCBdYmLlizemCdIencynzjboAMw3EGlZN8IdwJneKtQNiRlVa0p/RcZwY8jz vtwecfDXLN4kYH5rPOkyHjDw4mOtM6+2HyBh8qb0EITOcAsJpOYHCnNAlf3/BLkNh+GUiT iFgkDWvrBYnmL84Ey//EvvqvDfsZAIIS+AvfXVNtnM1uQFU9Wy1lVvUP9HkYAJTtuubeva PPpQTM0frjbstz8ewUFWiOC9yr1+1fzEqqhFSc5MM+5k0JYuXRzwy/8p5utPlg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694514537; 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; bh=VXRRfkFwSrMNvUqDICWKRhyF5qixjDDPRyBswJVjB5g=; b=LHvOw+5pfsfOSlHpburzjoj5PP8PUSyACvT2RBXmaxMnUyFBtzddKbxquTrfcWz0/38x6u l1H4O8i6sU0BOBBA== 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 tg_set_cfs_bandwidth() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169451453718.27769.14337569530437107129.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 03:34:34 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776850829444355315 X-GMAIL-MSGID: 1776850829444355315 The following commit has been merged into the sched/core branch of tip: Commit-ID: f838a17459e09ec1d573d71f1575aea8c85cccd5 Gitweb: https://git.kernel.org/tip/f838a17459e09ec1d573d71f1575aea8c85cccd5 Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 20:45:16 +02:00 Committer: root CommitterDate: Sat, 09 Sep 2023 15:10:17 +02:00 sched: Simplify tg_set_cfs_bandwidth() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/cpu.h | 2 ++ kernel/sched/core.c | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 6e6e57e..3520613 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -148,6 +148,8 @@ static inline int remove_cpu(unsigned int cpu) { return -EPERM; } static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { } #endif /* !CONFIG_HOTPLUG_CPU */ +DEFINE_LOCK_GUARD_0(cpus_read_lock, cpus_read_lock(), cpus_read_unlock()) + #ifdef CONFIG_PM_SLEEP_SMP extern int freeze_secondary_cpus(int primary); extern void thaw_secondary_cpus(void); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index bcae6e3..081a249 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10803,11 +10803,12 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota, * Prevent race between setting of cfs_rq->runtime_enabled and * unthrottle_offline_cfs_rqs(). */ - cpus_read_lock(); - mutex_lock(&cfs_constraints_mutex); + guard(cpus_read_lock)(); + guard(mutex)(&cfs_constraints_mutex); + ret = __cfs_schedulable(tg, period, quota); if (ret) - goto out_unlock; + return ret; runtime_enabled = quota != RUNTIME_INF; runtime_was_enabled = cfs_b->quota != RUNTIME_INF; @@ -10817,39 +10818,38 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota, */ if (runtime_enabled && !runtime_was_enabled) cfs_bandwidth_usage_inc(); - raw_spin_lock_irq(&cfs_b->lock); - cfs_b->period = ns_to_ktime(period); - cfs_b->quota = quota; - cfs_b->burst = burst; - __refill_cfs_bandwidth_runtime(cfs_b); + scoped_guard (raw_spinlock_irq, &cfs_b->lock) { + cfs_b->period = ns_to_ktime(period); + cfs_b->quota = quota; + cfs_b->burst = burst; - /* Restart the period timer (if active) to handle new period expiry: */ - if (runtime_enabled) - start_cfs_bandwidth(cfs_b); + __refill_cfs_bandwidth_runtime(cfs_b); - raw_spin_unlock_irq(&cfs_b->lock); + /* + * Restart the period timer (if active) to handle new + * period expiry: + */ + if (runtime_enabled) + start_cfs_bandwidth(cfs_b); + } for_each_online_cpu(i) { struct cfs_rq *cfs_rq = tg->cfs_rq[i]; struct rq *rq = cfs_rq->rq; - struct rq_flags rf; - rq_lock_irq(rq, &rf); + guard(rq_lock_irq)(rq); cfs_rq->runtime_enabled = runtime_enabled; cfs_rq->runtime_remaining = 0; if (cfs_rq->throttled) unthrottle_cfs_rq(cfs_rq); - rq_unlock_irq(rq, &rf); } + if (runtime_was_enabled && !runtime_enabled) cfs_bandwidth_usage_dec(); -out_unlock: - mutex_unlock(&cfs_constraints_mutex); - cpus_read_unlock(); - return ret; + return 0; } static int tg_set_cfs_quota(struct task_group *tg, long cfs_quota_us)