Re: [PATCH 2/2] sched/core: Don't skip a pending core-wide pick on idle re-entry

From: Peter Zijlstra

Date: Wed Nov 18 2026 - 09:40:41 EST


On Tue, Nov 17, 2026 at 02:27:03PM +0000, Ibrahim Elshahed wrote:

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index b1718ba5a4..58b429bbe3 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -347,6 +347,17 @@ void sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags)
> resched_curr(rq);
> }
>
> +/*
> + * An idle CPU with an empty runqueue must still call pick_next_task() while
> + * it has a pending core-wide pick or the core is forced idle. Only that pick
> + * consumes rq->core_pick and ends the forced idle.
> + */
> +static inline bool sched_core_idle_needs_pick(struct rq *rq)
> +{
> + return sched_core_enabled(rq) &&
> + (rq->core_pick || rq->core->core_forceidle_count);
> +}

I'm not sure I understand the rq->core_pick condition here. We already
have !rq->nr_running, and if we have rq->core_pick, then nr_running must
be non-zero, right?

> static int sched_task_is_throttled(struct task_struct *p, int cpu)
> {
> if (p->sched_class->task_is_throttled)
> @@ -550,6 +561,7 @@ void sched_core_put(void)
> static inline void sched_core_enqueue(struct rq *rq, struct task_struct *p) { }
> static inline void
> sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags) { }
> +static inline bool sched_core_idle_needs_pick(struct rq *rq) { return false; }
>
> #endif /* !CONFIG_SCHED_CORE */
>
> @@ -7285,8 +7297,13 @@ static void __sched notrace __schedule(int sched_mode)
> */
> prev_state = READ_ONCE(prev->__state);
> if (sched_mode == SM_IDLE) {
> - /* SCX must consult the BPF scheduler to tell if rq is empty */
> - if (!rq->nr_running && !scx_enabled()) {
> + /*
> + * SCX must consult the BPF scheduler to tell if rq is empty,
> + * and core scheduling may need pick_next_task() to consume
> + * rq->core_pick or to end forced idle.
> + */
> + if (!rq->nr_running && !scx_enabled() &&
> + !sched_core_idle_needs_pick(rq)) {
> next = prev;
> rq->next_class = &idle_sched_class;
> goto picked;
> --
> 2.47.3
>