Re: [PATCH v4 10/20] sched/core: Push current task from non preferred CPU
From: K Prateek Nayak
Date: Thu Jun 18 2026 - 00:09:54 EST
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.
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().
> +
> + 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.
> + rq = __migrate_task(rq, &rf, p, cpu);
> + }
> +
> + rq_unlock(rq, &rf);
> + raw_spin_unlock_irq(&p->pi_lock);
> + put_task_struct(p);
> +
> + return 0;
> +}
--
Thanks and Regards,
Prateek