From: "tip-bot2 for Chengming Zhou" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Valentin Schneider <vschneid@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Chengming Zhou <zhouchengming@bytedance.com>,
Ingo Molnar <mingo@kernel.org>,
"Steven Rostedt (Google)" <rostedt@goodmis.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/core] sched/core: Micro-optimize ttwu_runnable()
Date: Sat, 07 Jan 2023 10:53:00 -0000 [thread overview]
Message-ID: <167308878060.4906.15196822670119776065.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20221223103257.4962-1-zhouchengming@bytedance.com>
The following commit has been merged into the sched/core branch of tip:
Commit-ID: efe09385864f3441c71711f91e621992f9423c01
Gitweb: https://git.kernel.org/tip/efe09385864f3441c71711f91e621992f9423c01
Author: Chengming Zhou <zhouchengming@bytedance.com>
AuthorDate: Fri, 23 Dec 2022 18:32:56 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 07 Jan 2023 10:48:38 +01:00
sched/core: Micro-optimize ttwu_runnable()
ttwu_runnable() is used as a fast wakeup path when the wakee task
is running on CPU or runnable on RQ, in both cases we can just
set its state to TASK_RUNNING to prevent a sleep.
If the wakee task is on_cpu running, we don't need to update_rq_clock()
or check_preempt_curr().
But if the wakee task is on_rq && !on_cpu (e.g. an IRQ hit before
the task got to schedule() and the task been preempted), we should
check_preempt_curr() to see if it can preempt the current running.
This also removes the class->task_woken() callback from ttwu_runnable(),
which wasn't required per the RT/DL implementations: any required push
operation would have been queued during class->set_next_task() when p
got preempted.
ttwu_runnable() also loses the update to rq->idle_stamp, as by definition
the rq cannot be idle in this scenario.
Suggested-by: Valentin Schneider <vschneid@redhat.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20221223103257.4962-1-zhouchengming@bytedance.com
---
kernel/sched/core.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f99ee69..255a318 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3720,9 +3720,16 @@ static int ttwu_runnable(struct task_struct *p, int wake_flags)
rq = __task_rq_lock(p, &rf);
if (task_on_rq_queued(p)) {
- /* check_preempt_curr() may use rq clock */
- update_rq_clock(rq);
- ttwu_do_wakeup(rq, p, wake_flags, &rf);
+ if (!task_on_cpu(rq, p)) {
+ /*
+ * When on_rq && !on_cpu the task is preempted, see if
+ * it should preempt the task that is current now.
+ */
+ update_rq_clock(rq);
+ check_preempt_curr(rq, p, wake_flags);
+ }
+ WRITE_ONCE(p->__state, TASK_RUNNING);
+ trace_sched_wakeup(p);
ret = 1;
}
__task_rq_unlock(rq, &rf);
prev parent reply other threads:[~2023-01-07 10:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-23 10:32 [PATCH v6 1/2] sched/core: Minor optimize ttwu_runnable() Chengming Zhou
2022-12-23 10:32 ` [PATCH v6 2/2] sched/core: Reorganize ttwu_do_wakeup() and ttwu_do_activate() Chengming Zhou
2023-01-07 10:53 ` [tip: sched/core] " tip-bot2 for Chengming Zhou
2023-01-07 10:53 ` tip-bot2 for Chengming Zhou [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=167308878060.4906.15196822670119776065.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
--cc=zhouchengming@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®