Re: [RFC PATCH 1/3] sched: Make migrate_task_to() take any task

From: Peter Zijlstra
Date: Wed Jun 21 2023 - 09:05:11 EST


On Tue, Jun 13, 2023 at 12:20:02AM -0500, David Vernet wrote:
> The migrate_task_to() function exposed from kernel/sched/core.c migrates
> the current task, which is silently assumed to also be its first
> argument, to the specified CPU. The function uses stop_one_cpu() to
> migrate the task to the target CPU, which won't work if @p is not the
> current task as the stop_one_cpu() callback isn't invoked on remote
> CPUs.
>
> While this operation is useful for task_numa_migrate() in fair.c, it
> would be useful if __migrate_task() in core.c was given external
> linkage, as it actually can be used to migrate any task to a CPU.
>
> This patch therefore:
> 1. Renames the existing migrate_task_to() be called
> numa_migrate_current_task_to().
> 2. Renames __migrate_task() to migrate_task_to(), gives it global
> linkage, and updates all callers accordingly.
>
> A follow-on patch will call the new migrate_task_to() from fair.c when
> migrating a task in a shared wakequeue to a remote CPU.

I would suggest simply exposing move_queued_task(). You can actually do
is_cpu_allowed() before you do the whole lock dance, or even before
pull.

And then you don't have to create silly long function names either.