创建新任务时,linux内核如何唤醒空闲处理器? [英] How does linux kernel wake idle processor up when new task created?

查看:30
本文介绍了创建新任务时,linux内核如何唤醒空闲处理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Linux 内核的新手.目前,我查看了空闲代码并有一个问题.当处理器在它们自己的运行队列中没有任何任务时,它可能进入空闲模式,特定的 WFI(等待中断).(我提到的都是关于 ARM 架构而不是 X86.所以 X86 有问题.)停留在 WFI 状态后,可能其他处理器(非空闲)想要传播他们的任务是空闲处理器(通过负载平衡).当时一个繁忙的处理器使任务迁移.在我看来,当任务迁移时,空闲处理器应该立即唤醒以处理任务.对?然而,我找不到任何唤醒空闲处理器的代码,但只找到有关将任务注册到空闲处理器的运行队列的代码.

I'm newbie on Linux Kernel. Currently, I looked into idle codes and had a quesition. When processor doesn't have any taks in their own runqueue then it may go into idle mode, specific WFI(wating for interrupt). (All I mentioned is about ARM architecture not X86. So something is wrong for X86.) After staying in WFI state, maybe other processor(not idle) want to spread their task to this, idle processor(by load balance). At that time a busy processor makes task imigrated. In my point of view, when the task is imigrated, the idle processor should wake up immidiatley to process the task. right? However, I couldn't find any codes waking up idle processor but only found codes about registering task to idle processor's runqueue.

我想知道在给定新任务时唤醒处理器背后的机制是什么.或者它只是将任务从一个队列移动到另一个队列,直到被唤醒一些不可预测的IRQ?

I'd like to know what mechanism is behind of waking processor up when new task is given. Or it just move task from one queue to other's than let it be until woken up by some unpredictable IRQ?

请告诉我真相:)

推荐答案

WFI 是 ARM 的特殊协处理器指令.例如,

WFI is a special co-processor instruction for the ARM. For example,

 ENTRY(cpu_arm946_do_idle)
         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
         mov     pc, lr

它与 Linux 无关(直接).

It has nothing to do with Linux (directly).

如果没有工作要做,有一个特殊的idle 任务在ARM 上运行WFI 指令.idle 任务是最低优先级的 Linux 任务,如果没有其他任务,就会被调度.如果 WFIidle 完成,则某些驱动程序会在没有工作时中断(可能是计时器).在SMP情况下,如果有其他进程可以迁移,则不会进入idle;调度程序检查这一点.如果负载变高,那么繁忙的处理器需要唤醒其他处理器;在带有中断的 ARM 的情况下.通常这种处理在 arch/arch/kernel/process.c 中.例如 x86default_idle().我不知道 x86 的具体工作原理,但您可以查看源代码.

There is a special idle task that runs the WFI instruction on the ARM, if there is no work to do. The idle task is the very lowest priority Linux task, scheduled if there is nothing else. If WFI is done by idle, some driver will interrupt (maybe a timer) when there is no work to do. In the SMP case, it will not go to idle if there are other processes that can be migrated; the scheduler checks this. If a load gets high, then the busy processor needs to wake the others; In the case of an ARM with an interrupt. Usually this handling is in arch/arch/kernel/process.c. For example the x86 has default_idle(). I don't know specifics of how the x86 works, but you can look at the source.

对于您的问题创建新任务时,Linux 内核如何唤醒空闲处理器?,答案是没有.只有fork()(以及一些类似的函数)可以创建一个新任务;最初来自 init 任务,然后是它的一个子任务.如果您有一个 cron 作业,它会在进入 sleep/idle 之前安排一个计时器.这个定时器会唤醒系统,重新安排cron,然后cron 会调用fork(),来创建新的任务.

For your question How does linux kernel wake idle processor up when new task created?, the answer is it doesn't. Only fork() (and some similar functions) can create a new task; originally from the init task and then one of it's children. If you have a cron job, it will have scheduled a timer before it goes to sleep/idle. This timer will wake the system, re-schedule cron and then cron will call fork(), to create the new task.

其他相关机制有 cpufreq, cpuidle, kernel/power

Other related mechanisms are cpufreq, cpuidle, kernel/power etc.

真相总是客观/主观,当然不是全球.向我展示真相metric,我可以向您展示真相.

The truth is always objective/subjective and certainly is not global. Show me the metric for the truth and I can show you the truth.

这篇关于创建新任务时,linux内核如何唤醒空闲处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆