在多核x86处理器中设置亲和性

时间:2022-01-21 03:12:39

( I ask because it was before serious SMP and multicore that I studied OS. I like to have some vision of how code is being executed. )

(我问,因为它是在我学习操作系统的严重SMP和多核之前。我喜欢对代码的执行方式有所了解。)

If I have a multicore x86 CPU booting directly into my program. Can someone recommend a website which describes what assembler commands do I have to control affinity?

如果我有一个多核x86 CPU直接启动到我的程序中。有人可以推荐一个网站来描述我必须控制亲和力的汇编程序命令吗?

2 个解决方案

#1


Affinity is not determined by the CPU state and can therefore not be modified by assembly (alone). You need participation of the OS. And each OS will have a specific call to do this.

亲和性不是由CPU状态决定的,因此不能通过汇编(单独)进行修改。您需要参与操作系统。每个操作系统都会有一个特定的调用来执行此操作。

What the OS will do: the OS will have a scheduler, which is in effect a program who determines which process runs when on what processor. With setting the affinity as a user, you configure this scheduler.

操作系统将执行的操作:操作系统将具有调度程序,该调度程序实际上是一个程序,用于确定在哪个处理器上运行哪个进程。通过将亲缘关系设置为用户,可以配置此调度程序。

And if you wouldn't have a OS (which the question seems to imply I think), then you're writing the scheduler yourself and you will have own control of the configuration and you will probably start with a global runqueue and for each processor (core) watch this runqueue, and retrieve processes to run from it.

如果你没有操作系统(这个问题似乎暗示我认为),那么你自己编写调度程序并且你将拥有自己的配置控制权,你可能会从全局运行队列和每个处理器开始(核心)观察此runqueue,并检索从中运行的进程。

So how does this work then? During boot, only one CPU is running. If you as the OS are ready for it, you 'boot' the other CPUs which start executing your code, and which will probably run a kind of scheduler.

那么这是如何工作的呢?在引导期间,只有一个CPU正在运行。如果您已经为操作系统做好了准备,那么您将“启动”开始执行代码的其他CPU,并且可能会运行一种调度程序。

For an example implementation, see Linux 2.6.29 arch/x86/kernel/smpboot.c function do_boot_cpu(), which brings a CPU online in several ways using APIC.

有关示例实现,请参阅Linux 2.6.29 arch / x86 / kernel / smpboot.c函数do_boot_cpu(),它使用API​​C以多种方式使CPU联机。

#2


Here's a pretty good explanation of how QNX does it. It doesn't go as far as supplying the required ASM (which would be platform dependant anyway) but it may help with the concepts:

这里有一个很好的解释QNX如何做到这一点。它没有提供所需的ASM(无论如何都是平台相关的),但它可能有助于概念:

http://www.embedded.com/columns/technicalinsights/183702309?_requestid=408789

and a range of articles from the same site

以及来自同一网站的一系列文章

http://www.embedded.com/products/integratedcircuits/173400008?_requestid=409058

#1


Affinity is not determined by the CPU state and can therefore not be modified by assembly (alone). You need participation of the OS. And each OS will have a specific call to do this.

亲和性不是由CPU状态决定的,因此不能通过汇编(单独)进行修改。您需要参与操作系统。每个操作系统都会有一个特定的调用来执行此操作。

What the OS will do: the OS will have a scheduler, which is in effect a program who determines which process runs when on what processor. With setting the affinity as a user, you configure this scheduler.

操作系统将执行的操作:操作系统将具有调度程序,该调度程序实际上是一个程序,用于确定在哪个处理器上运行哪个进程。通过将亲缘关系设置为用户,可以配置此调度程序。

And if you wouldn't have a OS (which the question seems to imply I think), then you're writing the scheduler yourself and you will have own control of the configuration and you will probably start with a global runqueue and for each processor (core) watch this runqueue, and retrieve processes to run from it.

如果你没有操作系统(这个问题似乎暗示我认为),那么你自己编写调度程序并且你将拥有自己的配置控制权,你可能会从全局运行队列和每个处理器开始(核心)观察此runqueue,并检索从中运行的进程。

So how does this work then? During boot, only one CPU is running. If you as the OS are ready for it, you 'boot' the other CPUs which start executing your code, and which will probably run a kind of scheduler.

那么这是如何工作的呢?在引导期间,只有一个CPU正在运行。如果您已经为操作系统做好了准备,那么您将“启动”开始执行代码的其他CPU,并且可能会运行一种调度程序。

For an example implementation, see Linux 2.6.29 arch/x86/kernel/smpboot.c function do_boot_cpu(), which brings a CPU online in several ways using APIC.

有关示例实现,请参阅Linux 2.6.29 arch / x86 / kernel / smpboot.c函数do_boot_cpu(),它使用API​​C以多种方式使CPU联机。

#2


Here's a pretty good explanation of how QNX does it. It doesn't go as far as supplying the required ASM (which would be platform dependant anyway) but it may help with the concepts:

这里有一个很好的解释QNX如何做到这一点。它没有提供所需的ASM(无论如何都是平台相关的),但它可能有助于概念:

http://www.embedded.com/columns/technicalinsights/183702309?_requestid=408789

and a range of articles from the same site

以及来自同一网站的一系列文章

http://www.embedded.com/products/integratedcircuits/173400008?_requestid=409058