Re: [PATCH] sched/core: keep offline cpus out of core-wide selections

From: Ahmed Abdelraoof

Date: Thu Dec 03 2026 - 08:29:56 EST


On Mon, 2 Nov 2026 14:07:28 +0100, Peter Zijlstra wrote:
> On Sun, Nov 01, 2026 at 10:12:18PM +0000, Ahmed Abdelraoof wrote:
>
> > kernel/sched/core.c | 12 ++++++++++++
> > kernel/sched/core_sched.c | 2 +-
> > 2 files changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index d7c3b43158de..f55f6a0befcc 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -6413,6 +6413,9 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
> > */
> > max = NULL;
> > for_each_cpu_wrap(i, smt_mask, cpu) {
> > + if (!cpu_online(i))
> > + continue;
> > +
> > rq_i = cpu_rq(i);
> >
> > /*
> > @@ -6448,6 +6451,8 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
> > for_each_cpu(i, smt_mask) {
> > rq_i = cpu_rq(i);
> > p = rq_i->core_pick;
> > + if (!p)
> > + continue;
>
> Can't you do what you do in the last hunk for all 3 cases? It seems
> unfortunate to have 3 different ways to iterate in one patch.
>

For the first case, I think we can but I am not sure it is a good idea.
We do not have for_each_cpu_wrap_and(), so we would need to create it.
At the same time, the patch targets stable@.

For the second case, I do not think it will work. When onlining a new
CPU, there is a short window where the CPU is online but its task
pointer is still NULL leading to crash.

Doing things in the opposite order (set task pointer first and then
online) would lead to cases where the CPU can run tasks, but the group
leader does not see it? At least that is my intuition.


Let me know what you think.

Cheers,
Ahmed.