From patchwork Mon Aug 14 15:08:05 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: 135516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2830710vqi; Mon, 14 Aug 2023 08:47:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHH61K1/OpEYW5m0vfscmU/czRseoJfFo+ZkTatVuS745je+dxbXtRiNbU+9+5d+6R07fjX X-Received: by 2002:a05:6a20:3d13:b0:140:45aa:c601 with SMTP id y19-20020a056a203d1300b0014045aac601mr15022803pzi.30.1692028024763; Mon, 14 Aug 2023 08:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692028024; cv=none; d=google.com; s=arc-20160816; b=TReHoZFFSxN8U+nozw2xU5DYgyx9w7EbOAZJ6ePIXrGkUwl5CHO3AAEoc3KP9y7yZD sx9LB7nzVGRZgCc00+HVR8yR4cnh+UkCP1MlfDgdUhRgdK06qA6l5jEqTOmisaBL8a23 GwMLWAzQMQJeNqbPN5BaJ+lIFs5GeoEKtV5oH0g13ouuCFxItTLVQRRB7rZrb1MEQqUk cxluvHx5JP1XuMw5rIWJ8H0gjc8fC6P3r4Vt+TvZWDu1zvxzakvcrNjk+cVClkc56Wol XSdnGk6rnTLo06lOa8wfFT1t3UHBgPYNZvvRKb8mjLw264K/i78ORAgtzWNyMjncf9C/ O+vw== 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=dDBBLrQiUI949l0/QFU5QO+sFl+OnZWaMOm9rfnBDlc=; fh=utQzrRGpdyneC53QA2zUro1rWgCYMKhBZhFdjXY/HTE=; b=A9/Z+uCkUyfrVsSSpHVHyYLVJ1dCR9SwVeFooEHthoLoIiFpYUsG43JxU+ZxpBb0td g66pHgi1xBMuAMwkjJbjhiGWG9Jc5rJ3TDsXscza4/kRDuuaY3r4nRyqqBGWm6t3F8Z5 TelYCSBwrpf5FsMk9c3sKnenNLRNABsBYxWQ/3n1ZA5nTd82AEuotADNOmilDTUQ7wyb yyXGfe5v/jn0vQ7VvlrlvLBGVHvzMkGhXLwzoFb93+huAyB4Yvwy/yX3DIPxyXzqw/LW IptVcW5JPZc4tqB5XC6CVvMk26drMmm5ra+XfpjE7/CRo9rZwHRwmrcEDvb9AMunkbd+ QtCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EioAf7K9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mDzlwZiM; 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 t23-20020a656097000000b0056574d63583si6513721pgu.306.2023.08.14.08.46.37; Mon, 14 Aug 2023 08:47:04 -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=EioAf7K9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mDzlwZiM; 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 S232815AbjHNPIp (ORCPT + 99 others); Mon, 14 Aug 2023 11:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjHNPIK (ORCPT ); Mon, 14 Aug 2023 11:08:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C56F810C1; Mon, 14 Aug 2023 08:08:07 -0700 (PDT) Date: Mon, 14 Aug 2023 15:08:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692025686; 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=dDBBLrQiUI949l0/QFU5QO+sFl+OnZWaMOm9rfnBDlc=; b=EioAf7K9NRdIg3o5RHW+Q9YUjr4GhLLnKTOiTV+GUIahs8zoax5QwlY5r9V4RnD/rNS5Wy 5HzYdUO72dUvgqhp9Om9ns9HX71DRkz8cQhY3ZwV4NJvNNYQffiVzcfR9WWM2HNtpseQUO IcIi4QQe8IWXLleefPiQwnOdbKhe1N6zRa4Ff/aigh2SuHFyROV01S3U6k+HxSC0PvBQJj 9X0XF2qGwMEOMsmwcYB63uOzgq4pIct1v5y3HjvBV3GkDRgwOIp3nRP40I2uPbyKK7HT4M xwLCS0WmoiyCSMKfG9NewmCOYfPEFMM0yq5aTp2GVkDhE8PHcXTpfYT0/N39Fw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692025686; 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=dDBBLrQiUI949l0/QFU5QO+sFl+OnZWaMOm9rfnBDlc=; b=mDzlwZiM4X/73Pq3RNBt4CWOPnIoZrG5PqrOticMBIZieuQTo/mzRPjIKsn8+2Rwkf/7Fa r0mnB+8CUwNt4rDg== 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 wake_up_if_idle() Cc: "Peter Zijlstra (Intel)" , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230801211812.032678917@infradead.org> References: <20230801211812.032678917@infradead.org> MIME-Version: 1.0 Message-ID: <169202568576.27769.17983708536271256088.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: 1773071837496223342 X-GMAIL-MSGID: 1774219978014594320 The following commit has been merged into the sched/core branch of tip: Commit-ID: 4eb054f92b066ec0a0cba6896ee8eff4c91dfc9e Gitweb: https://git.kernel.org/tip/4eb054f92b066ec0a0cba6896ee8eff4c91dfc9e Author: Peter Zijlstra AuthorDate: Tue, 01 Aug 2023 22:41:25 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 14 Aug 2023 17:01:25 +02:00 sched: Simplify wake_up_if_idle() 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.032678917@infradead.org --- kernel/sched/core.c | 20 ++++++-------------- kernel/sched/sched.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 66478a6..65ebf43 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3939,21 +3939,13 @@ static void __ttwu_queue_wakelist(struct task_struct *p, int cpu, int wake_flags void wake_up_if_idle(int cpu) { struct rq *rq = cpu_rq(cpu); - struct rq_flags rf; - - rcu_read_lock(); - if (!is_idle_task(rcu_dereference(rq->curr))) - goto out; - - rq_lock_irqsave(rq, &rf); - if (is_idle_task(rq->curr)) - resched_curr(rq); - /* Else CPU is not idle, do nothing here: */ - rq_unlock_irqrestore(rq, &rf); - -out: - rcu_read_unlock(); + guard(rcu)(); + if (is_idle_task(rcu_dereference(rq->curr))) { + guard(rq_lock_irqsave)(rq); + if (is_idle_task(rq->curr)) + resched_curr(rq); + } } bool cpus_share_cache(int this_cpu, int that_cpu) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index c299a58..3a01b7a 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1705,6 +1705,21 @@ rq_unlock(struct rq *rq, struct rq_flags *rf) raw_spin_rq_unlock(rq); } +DEFINE_LOCK_GUARD_1(rq_lock, struct rq, + rq_lock(_T->lock, &_T->rf), + rq_unlock(_T->lock, &_T->rf), + struct rq_flags rf) + +DEFINE_LOCK_GUARD_1(rq_lock_irq, struct rq, + rq_lock_irq(_T->lock, &_T->rf), + rq_unlock_irq(_T->lock, &_T->rf), + struct rq_flags rf) + +DEFINE_LOCK_GUARD_1(rq_lock_irqsave, struct rq, + rq_lock_irqsave(_T->lock, &_T->rf), + rq_unlock_irqrestore(_T->lock, &_T->rf), + struct rq_flags rf) + static inline struct rq * this_rq_lock_irq(struct rq_flags *rf) __acquires(rq->lock)