是否有一个`x86`指令告诉指令正在运行在哪个核心?
当我执行cat / proc内/ cpuinfo
,我看到8个内核,用的ID从 0
到 7
。
When I cat /proc/cpuinfo
, I see 8 cores, with ID's from 0
to 7
.
有一个 86
指令,将报告该指令本身运行的核心中的核心ID?
Is there an x86
instruction that will report the core id of the core that the instruction itself is running on?
我看了看 CPUID
但这似乎并没有返回 COREID
下的任何参数设置。
I looked at cpuid
but that does not seem to return coreid
under any parameter setting.
的英特尔®64和IA-32架构软件开发人员手册卷3A:系统编程指南,第1部分的,部分的 8.4.5确定逻辑处理器在MP系统的名单,其中包括:
The Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3A: System Programming Guide, Part 1, section 8.4.5 Identifying Logical Processors in an MP System lists, among others:
这APIC ID由CPUID.0BH报道:EDX [31:0]
This APIC ID is reported by CPUID.0BH:EDX[31:0]
请注意,这并不直接等同于linux内核的编号。在内核中有,你可以阅读 x86_cpu_to_apicid
表。当然,内核也知道code正在执行什么CPU,而不必咨询APIC:
Note that this doesn't directly equate to the linux kernel's numbering. In the kernel there is an x86_cpu_to_apicid
table that you can read. Of course the kernel also knows what cpu the code is executing on, without having to consult the APIC:
* smp_processor_id(): get the current CPU ID.
*
* if DEBUG_PREEMPT is enabled then we check whether it is
* used in a preemption-safe way. (smp_processor_id() is safe
* if it's used in a preemption-off critical section, or in
* a thread that is bound to the current CPU.)