Re: [PATCH v4 10/20] sched/core: Push current task from non preferred CPU
From: Shrikanth Hegde
Date: Thu Jun 18 2026 - 02:06:19 EST
On 6/18/26 9:39 AM, K Prateek Nayak wrote:
Hello Shrikanth,
On 6/17/2026 11:11 PM, Shrikanth Hegde wrote:
+static int sched_non_preferred_cpu_push_stop(void *arg)
+{
+ struct task_struct *p = arg;
+ struct rq *rq = this_rq();
+ struct rq_flags rf;
+ int cpu;
+
+ /* sanity check */
+ if (cpu_preferred(rq->cpu))
+ return 0;
I think this early return path should also clear "push_task_work_done"
indicator, otherwise, we will fail to schedule the stopper on this CPU
next time.
Ok.
Also, we may need to add a context_unsafe_alias(rq) call here to keep
the context analysis bits happy similar to migration_cpu_stop().
Let me see that.
+
+ raw_spin_lock_irq(&p->pi_lock);
+ rq_lock(rq, &rf);
+ rq->push_task_work_done = 0;
+
+ update_rq_clock(rq);
+
+ if (task_rq(p) == rq && task_on_rq_queued(p)) {
+ cpu = select_fallback_rq(rq->cpu, p);
Do we need a task_has_preferred_cpus() sanity check here?
If the affinity changed before the stopper grabbed the p->pi_lock, and
there are no preferred CPUs to run on anymore, might as well keep the
task here instead of migrating it away.
No I think.
If affinity changed before stopper started running,
subsequent select_fallback_rq will return the CPU it can run.
If it has no choice but a non-preferred CPU, it will return a non-preferred CPU too.
+ rq = __migrate_task(rq, &rf, p, cpu);
+ }
+
+ rq_unlock(rq, &rf);
+ raw_spin_unlock_irq(&p->pi_lock);
+ put_task_struct(p);
+
+ return 0;
+}