[tip: sched/urgent] sched/core: Clear a stale rq->core_pick after dequeue

From: tip-bot2 for Ibrahim Elshahed

Date: Mon Nov 23 2026 - 04:44:35 EST


The following commit has been merged into the sched/urgent branch of tip:

Commit-ID: b704f052aa943903be7140fa8bd805b1de9d5afb
Gitweb: https://git.kernel.org/tip/b704f052aa943903be7140fa8bd805b1de9d5afb
Author: Ibrahim Elshahed <lshahed@xxxxxxxxx>
AuthorDate: Fri, 20 Nov 2026 10:58:20
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitterDate: Mon, 23 Nov 2026 10:38:26 +01:00

sched/core: Clear a stale rq->core_pick after dequeue

A core-wide selection leaves the task chosen for each sibling in that
sibling's rq->core_pick until pick_next_task() on the sibling consumes
it. If the task is dequeued before the sibling consumes it, for example
migrated away, the pointer stays until the sibling's next
pick_next_task() overwrites it. Until then
__sched_core_account_forceidle() keeps charging forced idle time to a
task that no longer runs there and, with schedstats enabled, to its
cgroup, even after the task has exited.

Clear rq->core_pick and rq->core_dl_server in sched_core_dequeue() once
the pending pick is dequeued, and don't wait for pick_next_task() to
overwrite them.

Fixes: 4feee7d12603 ("sched/core: Forced idle accounting")
Co-developed-by: Roman Kagan <rkagan@xxxxxxxxx>
Signed-off-by: Roman Kagan <rkagan@xxxxxxxxx>
Signed-off-by: Ibrahim Elshahed <lshahed@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20261120105822.7770-2-lshahed@xxxxxxxxx
---
kernel/sched/core.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 42b99be..4b1d36c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -329,6 +329,15 @@ void sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags)
}

/*
+ * @p left this rq, so it can no longer be the pick a sibling made.
+ * This also avoids forced idle accounting charging it once it is gone.
+ */
+ if (rq->core_pick == p) {
+ rq->core_pick = NULL;
+ rq->core_dl_server = NULL;
+ }
+
+ /*
* Migrating the last task off the cpu, with the cpu in forced idle
* state. Reschedule to create an accounting edge for forced idle,
* and re-examine whether the core is still in forced idle state.