[PATCH 1/2] sched/core: Clear a stale rq->core_pick after dequeue
From: Ibrahim Elshahed
Date: Tue Nov 17 2026 - 09:27:34 EST
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")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Roman Kagan <rkagan@xxxxxxxxx>
Signed-off-by: Roman Kagan <rkagan@xxxxxxxxx>
Signed-off-by: Ibrahim Elshahed <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 175b52a7ea..b1718ba5a4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -328,6 +328,15 @@ void sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags)
RB_CLEAR_NODE(&p->core_node);
}
+ /*
+ * @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,
--
2.47.3