[RFC PATCH v5 26/29] sched/core: Execute enqueued balance callbacks after migrate_disable_switch

Yuri Andriaccio
2026-04-30T21:39:23Z

Execute balance callbacks after migrate_disable_switch.
Balancing may be requested on the __schedule path, in migrate_disable_switch,
when the running task is throttled and then pushed away from its runqueue.

Signed-off-by: Yuri Andriaccio <yurand2000@gmail.com>
---
kernel/sched/core.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 24ffe933527c..03bd86cc8d4f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2352,6 +2352,9 @@ do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx);

static void migrate_disable_switch(struct rq *rq, struct task_struct *p)
{
+ struct rq_flags rf;
+ struct balance_callback *head;
+
struct affinity_context ac = {
.new_mask = cpumask_of(rq->cpu),
.flags = SCA_MIGRATE_DISABLE,
@@ -2363,8 +2366,13 @@ static void migrate_disable_switch(struct rq *rq, struct task_struct *p)
if (p->cpus_ptr != &p->cpus_mask)
return;

- scoped_guard (task_rq_lock, p)
- do_set_cpus_allowed(p, &ac);
+ rq = task_rq_lock(p, &rf);
+
+ do_set_cpus_allowed(p, &ac);
+
+ head = splice_balance_callbacks(rq);
+ task_rq_unlock(rq, p, &rf);
+ balance_callbacks(rq, head);
}

void ___migrate_enable(void)
--
2.53.0