Linux内核如何在多个内核之间迁移进程? [英] How does Linux kernel migrate the process among multiple cores?
问题描述
上下文:
进程1在核心0上执行.Core-1处于空闲状态.
Process-1 is executing on core-0. Core-1 is idle.
现在,进程1使用 sched_setaffinity()
更改其CPU亲和性为core-1.
Now, process-1 uses sched_setaffinity()
to change its CPU affinity as core-1.
问题:
哪些内核函数将process-1迁移到core-1上执行?
Which kernel function(s) migrate the process-1 to execute on core-1?
推荐答案
以下是从内核中的 sched_setaffinity
系统调用入口点开始的调用序列:
Here is the call sequence starting from the sched_setaffinity
system call entry point in the kernel:
在最后一个函数中,有两种情况,如第1101行:
In the last function, there are two cases as shown in the code at line 1101:
if (task_running(rq, p) || p->state == TASK_WAKING) {
// ...
stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
// ...
} else if (task_on_rq_queued(p)) {
rq = move_queued_task(rq, &rf, p, dest_cpu);
}
如果要迁移的任务当前正在运行或正在唤醒,则可以通过调用 stop_one_cpu
来迁移它,该命令依次调用以下函数:
If the task to be migrated is currently running or waking up, then it is migrated by calling stop_one_cpu
, which calls the following functions in order:
最后一个函数 move_queued_task
是将任务从当前运行队列实际移动到目标运行队列的函数.请注意,这是从 __ set_cpus_allowed_ptr
的另一个分支调用的函数.该分支处理任务处于其他任何状态的情况.
The last function, move_queued_task
, is the one that actually moves the task from the current runqueue to the target runqueue. Note that this is the same function that is called from the other branch of __set_cpus_allowed_ptr
. That branch handles the case where the task is in any of the other states.
这篇关于Linux内核如何在多个内核之间迁移进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!