From: Peter Zijlstra <peterz@infradead.org>
To: Mike Galbraith <efault@gmx.de>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, clm@meta.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH 2/5] sched: Optimize ttwu() / select_task_rq()
Date: Fri, 13 Jun 2025 11:40:52 +0200 [thread overview]
Message-ID: <20250613094052.GF2278213@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <334e48ebbf34d853777672449cb29d5f06c751b7.camel@gmx.de>
On Mon, Jun 09, 2025 at 07:01:47AM +0200, Mike Galbraith wrote:
Right; so the problem being that we can race with
migrate_disable_switch().
> kernel/sched/core.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4313,7 +4313,10 @@ int try_to_wake_up(struct task_struct *p
> ttwu_queue_wakelist(p, task_cpu(p), wake_flags))
> break;
>
> - cpu = select_task_rq(p, p->wake_cpu, &wake_flags);
> + if (is_migration_disabled(p))
> + cpu = -1;
> + else
> + cpu = select_task_rq(p, p->wake_cpu, &wake_flags);
>
> /*
> * If the owning (remote) CPU is still in the middle of schedule() with
> @@ -4326,6 +4329,9 @@ int try_to_wake_up(struct task_struct *p
> */
> smp_cond_load_acquire(&p->on_cpu, !VAL);
>
> + if (cpu == -1)
> + cpu = select_task_rq(p, p->wake_cpu, &wake_flags);
> +
> if (task_cpu(p) != cpu) {
> if (p->in_iowait) {
> delayacct_blkio_end(p);
>
So select_task_rq() already checks is_migration_disabled(); just not
well enough. Also, I'm thinking that if we see migration_disabled, we
don't need to call it a second time, just let it be where it was.
Does something like this help? Specifically, when nr_cpus_allowed == 1
|| is_migration_disabled(), don't change @cpu at all.
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3593,7 +3593,7 @@ int select_task_rq(struct task_struct *p
cpu = p->sched_class->select_task_rq(p, cpu, *wake_flags);
*wake_flags |= WF_RQ_SELECTED;
} else {
- cpu = cpumask_any(p->cpus_ptr);
+ cpu = task_cpu(p);
}
/*
next prev parent reply other threads:[~2025-06-13 9:41 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 9:45 [RFC][PATCH 0/5] sched: Try and address some recent-ish regressions Peter Zijlstra
2025-05-20 9:45 ` [RFC][PATCH 1/5] sched/deadline: Less agressive dl_server handling Peter Zijlstra
2025-06-03 16:03 ` Juri Lelli
2025-06-13 9:43 ` Peter Zijlstra
2025-05-20 9:45 ` [RFC][PATCH 2/5] sched: Optimize ttwu() / select_task_rq() Peter Zijlstra
2025-06-09 5:01 ` Mike Galbraith
2025-06-13 9:40 ` Peter Zijlstra [this message]
2025-06-13 10:20 ` Mike Galbraith
2025-05-20 9:45 ` [RFC][PATCH 3/5] sched: Split up ttwu_runnable() Peter Zijlstra
2025-05-20 9:45 ` [RFC][PATCH 4/5] sched: Add ttwu_queue controls Peter Zijlstra
2025-05-20 9:45 ` [RFC][PATCH 5/5] sched: Add ttwu_queue support for delayed tasks Peter Zijlstra
2025-06-06 15:03 ` Vincent Guittot
2025-06-06 15:38 ` Peter Zijlstra
2025-06-06 16:55 ` Vincent Guittot
2025-06-11 9:39 ` Peter Zijlstra
2025-06-16 12:39 ` Vincent Guittot
2025-06-06 16:18 ` Phil Auld
2025-06-16 12:01 ` Peter Zijlstra
2025-06-16 16:37 ` Peter Zijlstra
2025-06-13 7:34 ` Dietmar Eggemann
2025-06-13 9:51 ` Peter Zijlstra
2025-06-13 10:46 ` Peter Zijlstra
2025-06-16 8:16 ` Dietmar Eggemann
2025-05-28 19:59 ` [RFC][PATCH 0/5] sched: Try and address some recent-ish regressions Peter Zijlstra
2025-05-29 1:41 ` Chris Mason
2025-06-14 10:04 ` Peter Zijlstra
2025-06-16 0:35 ` Chris Mason
2025-05-29 10:18 ` Beata Michalska
2025-05-30 9:00 ` Peter Zijlstra
2025-05-30 10:04 ` Chris Mason
2025-06-02 4:44 ` K Prateek Nayak
2025-06-13 3:28 ` K Prateek Nayak
2025-06-14 10:15 ` Peter Zijlstra
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=20250613094052.GF2278213@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=clm@meta.com \
--cc=dietmar.eggemann@arm.com \
--cc=efault@gmx.de \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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®