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

tip-bot2 for Ibrahim Elshahed posted 1 patch 11 hours ago
There is a newer version of this series
kernel/sched/core.c |  9 +++++++++
1 file changed, 9 insertions(+)
[tip: sched/urgent] sched/core: Clear a stale rq->core_pick after dequeue
Posted by tip-bot2 for Ibrahim Elshahed 11 hours ago
The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     bf437249e07b84fcee0fe192cc8591592d336355
Gitweb:        https://git.kernel.org/tip/bf437249e07b84fcee0fe192cc8591592d336355
Author:        Ibrahim Elshahed <lshahed@amazon.de>
AuthorDate:    Fri, 20 Nov 2026 10:58:20 
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 22 Nov 2026 16:16:44 +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@amazon.de>
Signed-off-by: Roman Kagan <rkagan@amazon.de>
Signed-off-by: Ibrahim Elshahed <lshahed@amazon.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261120105822.7770-2-lshahed@amazon.de
---
 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.