Re: [PATCH v2 06/12] sched: Introduce ttwu_do_migrate()

From: Vincent Guittot
Date: Thu Jul 10 2025 - 12:52:40 EST


On Wed, 2 Jul 2025 at 14:12, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> Split out the migration related bits into their own function for later
> re-use.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

Reviewed-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>


> ---
> kernel/sched/core.c | 26 ++++++++++++++++----------
> 1 file changed, 16 insertions(+), 10 deletions(-)
>
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3774,6 +3774,21 @@ static int ttwu_runnable(struct task_str
> return 1;
> }
>
> +static inline bool ttwu_do_migrate(struct task_struct *p, int cpu)
> +{
> + if (task_cpu(p) == cpu)
> + return false;
> +
> + if (p->in_iowait) {
> + delayacct_blkio_end(p);
> + atomic_dec(&task_rq(p)->nr_iowait);
> + }
> +
> + psi_ttwu_dequeue(p);
> + set_task_cpu(p, cpu);
> + return true;
> +}
> +
> void sched_ttwu_pending(void *arg)
> {
> struct llist_node *llist = arg;
> @@ -4268,17 +4283,8 @@ int try_to_wake_up(struct task_struct *p
> * their previous state and preserve Program Order.
> */
> smp_cond_load_acquire(&p->on_cpu, !VAL);
> -
> - if (task_cpu(p) != cpu) {
> - if (p->in_iowait) {
> - delayacct_blkio_end(p);
> - atomic_dec(&task_rq(p)->nr_iowait);
> - }
> -
> + if (ttwu_do_migrate(p, cpu))
> wake_flags |= WF_MIGRATED;
> - psi_ttwu_dequeue(p);
> - set_task_cpu(p, cpu);
> - }
>
> ttwu_queue(p, cpu, wake_flags);
> }
>
>