From patchwork Sat Jan 7 10:53:00 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: 40364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1247320wrt; Sat, 7 Jan 2023 02:56:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXthAkc9czw7J7g+03U3WRDErpOLc6tyAGHmysXaGkfAe/sXfgfrk3EFAvFWM/IJKxqsVEI/ X-Received: by 2002:a05:6a20:d80c:b0:a3:9127:98e6 with SMTP id iv12-20020a056a20d80c00b000a3912798e6mr87022662pzb.11.1673088966139; Sat, 07 Jan 2023 02:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673088966; cv=none; d=google.com; s=arc-20160816; b=nYR5Sndyt9jlK+rzcXAPN/gvIPSsjGFaR0mD0WpWZCD4fN/aG5NwP56tQL+s1NNyE4 ASGH4bPbSoR3/qG3vawg+B8LI4n2cQvosK8LU4ljkjJQPblOzNJ6pzS2F7KLD/2rOIPS xL5V6J0dWFpFneoDFy+jZyUC8hs/31ZIFfO8yiK01MnH61JtKMtXpG9mY1F7uWyJVXbG IopwyLRfmf3H9xeqFKZU4k50PvLpyX3Yb+BidemPeXSyi8DHytQ7bHS5nAvADqi2iqbN C06pYp3R5135KNH2YULjVHkfY8eEwh7go0c1KnYyb/QFZmAp03DQ0Bu0bnzfXgTtAEfC doPw== 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=zotIngnfFjUCAlEXnwMFZZiKtOu852+3JcwkGFgHyGI=; b=LiyivcpAWJ9oK7/tExr3+fccGGRIwDvhpxbdErM2i6zypRv9mAxw6kWxd2IhXN2Piz OKNXq+Ox5UpJ0urvrQGVxoTLPJeuJNkOcOyixlmHrpoAFXE58JuRJauuxH5HNTLMmE6b Aemsuzbu9BmRvNhGugUrts3NPoUT1Bdbn3a2tfXSxlNmAB/+7MEgNP4sXxavkKknyXfw FOvBmkQp2bRYfaN0VxttPOH6WOKv1Vvazc2UnCGDmFK7qHuIsYk3XlE5OHTp3hJj7LNQ 6L8Fj6bwqib8hMLaP19sNa6anamrUbtDdfmJH5LBOG3jHmbuV+iwUK7mE/SDAvcU2XhH 0WVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D7SFbj7i; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FIxCSEoj; 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 i70-20020a638749000000b004779a46d07csi4027590pge.183.2023.01.07.02.55.53; Sat, 07 Jan 2023 02:56:06 -0800 (PST) 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=D7SFbj7i; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FIxCSEoj; 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 S232210AbjAGKxQ (ORCPT + 99 others); Sat, 7 Jan 2023 05:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230213AbjAGKxF (ORCPT ); Sat, 7 Jan 2023 05:53:05 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29DF41AA01; Sat, 7 Jan 2023 02:53:02 -0800 (PST) Date: Sat, 07 Jan 2023 10:53:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673088780; 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=zotIngnfFjUCAlEXnwMFZZiKtOu852+3JcwkGFgHyGI=; b=D7SFbj7iRON1xym7pO2Yd5j+VZDjiza5Oe29ZLm7s6HpVmrLojMMWx4q/DK8y332jKiC8O 1M48+emaXZ2vB/JUAj7n04lrGTjHdx7PEfgNuFpBPYGjQ9lxSdoDv5ItRuAIxDjE+nBcYu o2eHXw0+97SRH6gmlOyvM97wOH7UOh16TH3xaX3yD+yT39Ew2f0JlQ55s2bcTvOR5S7/5j 033/ETHZZmjQycLscJOeO1OuoXLXVRKiPVOhakm/chKxbcWuPPGS6e0DppeG07goavsJD8 RuRuqaWs/sJWp29Slfz4/rExzHJ6oOHYxd0IMHM5gu5bwICwh0AUpJsxw+ZwpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673088780; 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=zotIngnfFjUCAlEXnwMFZZiKtOu852+3JcwkGFgHyGI=; b=FIxCSEoj7dUot1ZPrumcwqzfSAL+it4aJCc2PTGDkyGua3d2gU1lccgjayrc/6Qdzyvecv A5g9FiwjlwQERfCw== From: "tip-bot2 for Chengming Zhou" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/core: Reorganize ttwu_do_wakeup() and ttwu_do_activate() Cc: Peter Zijlstra , Chengming Zhou , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221223103257.4962-2-zhouchengming@bytedance.com> References: <20221223103257.4962-2-zhouchengming@bytedance.com> MIME-Version: 1.0 Message-ID: <167308878040.4906.10135833329024897698.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753000942876812418?= X-GMAIL-MSGID: =?utf-8?q?1754360935334033676?= The following commit has been merged into the sched/core branch of tip: Commit-ID: 160fb0d83f206b3429fc495864a022110f9e4978 Gitweb: https://git.kernel.org/tip/160fb0d83f206b3429fc495864a022110f9e4978 Author: Chengming Zhou AuthorDate: Fri, 23 Dec 2022 18:32:57 +08:00 Committer: Ingo Molnar CommitterDate: Sat, 07 Jan 2023 10:48:38 +01:00 sched/core: Reorganize ttwu_do_wakeup() and ttwu_do_activate() ttwu_do_activate() is used for a complete wakeup, in which we will activate_task() and use ttwu_do_wakeup() to mark the task runnable and perform wakeup-preemption, also call class->task_woken() callback and update the rq->idle_stamp. Since ttwu_runnable() is not a complete wakeup, don't need all those done in ttwu_do_wakeup(), so we can move those to ttwu_do_activate() to simplify ttwu_do_wakeup(), making it only mark the task runnable to be reused in ttwu_runnable() and try_to_wake_up(). This patch should not have any functional changes. Suggested-by: Peter Zijlstra Signed-off-by: Chengming Zhou Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20221223103257.4962-2-zhouchengming@bytedance.com --- kernel/sched/core.c | 64 +++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 255a318..03b8529 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3625,14 +3625,39 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_flags) } /* - * Mark the task runnable and perform wakeup-preemption. + * Mark the task runnable. */ -static void ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags, - struct rq_flags *rf) +static inline void ttwu_do_wakeup(struct task_struct *p) { - check_preempt_curr(rq, p, wake_flags); WRITE_ONCE(p->__state, TASK_RUNNING); trace_sched_wakeup(p); +} + +static void +ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, + struct rq_flags *rf) +{ + int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK; + + lockdep_assert_rq_held(rq); + + if (p->sched_contributes_to_load) + rq->nr_uninterruptible--; + +#ifdef CONFIG_SMP + if (wake_flags & WF_MIGRATED) + en_flags |= ENQUEUE_MIGRATED; + else +#endif + if (p->in_iowait) { + delayacct_blkio_end(p); + atomic_dec(&task_rq(p)->nr_iowait); + } + + activate_task(rq, p, en_flags); + check_preempt_curr(rq, p, wake_flags); + + ttwu_do_wakeup(p); #ifdef CONFIG_SMP if (p->sched_class->task_woken) { @@ -3662,31 +3687,6 @@ static void ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags, #endif } -static void -ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, - struct rq_flags *rf) -{ - int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK; - - lockdep_assert_rq_held(rq); - - if (p->sched_contributes_to_load) - rq->nr_uninterruptible--; - -#ifdef CONFIG_SMP - if (wake_flags & WF_MIGRATED) - en_flags |= ENQUEUE_MIGRATED; - else -#endif - if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } - - activate_task(rq, p, en_flags); - ttwu_do_wakeup(rq, p, wake_flags, rf); -} - /* * Consider @p being inside a wait loop: * @@ -3728,8 +3728,7 @@ static int ttwu_runnable(struct task_struct *p, int wake_flags) update_rq_clock(rq); check_preempt_curr(rq, p, wake_flags); } - WRITE_ONCE(p->__state, TASK_RUNNING); - trace_sched_wakeup(p); + ttwu_do_wakeup(p); ret = 1; } __task_rq_unlock(rq, &rf); @@ -4095,8 +4094,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) goto out; trace_sched_waking(p); - WRITE_ONCE(p->__state, TASK_RUNNING); - trace_sched_wakeup(p); + ttwu_do_wakeup(p); goto out; }