一、分解x2APIC_ID
摘自《Intel® 64 Architecture Processor Topology Enumeration》中的“Sub ID Extraction Parameters for x2APIC ID”——
SMT_ID: CPUID.(EAX=11, ECX=0):EAX[4:0] provides the width parameter to derive a SMT select mask to extract the SMT_IDs of logical processors within the same processor core. The sub leaf index (ECX=0) is architecturally defined and associated with the “SMT” level type (CPUID.(EAX=11, ECX=0):ECX[15:8] == 1)
SMT_Mask_Width = CPUID.(EAX=11, ECX=0):EAX[4:0] if CPUID.(EAX=11, ECX=0):ECX[15:8] is 1
SMT_Select_Mask = ~((-1) << SMT_Mask_Width )
SMT_ID = x2APIC_ID & SMT_Select_Mask
Core_ID: The level type associated with the sub leaf index (ECX=1) may vary across processors with different hardware multithreading capabilities. If CPUID.(EAX=11, ECX=1):ECX[15:8] is 2, it is associated with “processor core” level type. Then, CPUID.(EAX=11,ECX=1):EAX[4:0] provides the width parameter to derive a select mask of all logical processors within the same physical package. The “processor core” includes “SMT” in this case, and enumerating different cores in the package can be done by zeroing out the SMT portion of the inclusive mask derived from this.
CorePlus_Mask_Width = CPUID.(EAX=11,ECX=1):EAX[4:0] if CPUID.(EAX=11, ECX=1):ECX[15:8] is 2
CoreOnly_Select_Mask = (~((-1) << CorePlus_Mask_Width ) ) ^ SMT_Select_Mask.
Core_ID = (x2APIC_ID & CoreOnly_Select_Mask) >> SMT_Mask_Width
Pkg_ID: Within a coherent domain of the three-level topology, the upper bits of the APIC_ID (except the lower “CorePlus_Mask_Width” bits) can enumerate different physical packages in the system. In a clustered installation, software may need to consult vendor specific documentation to distinguish the topology of how many physical packages are organized within a given node.
Pkg_Select_Mask = (-1) << CorePlus_Mask_Width
Pkg_ID = (x2APIC_ID & Pkg_Select_Mask) >> CorePlus_Mask_Width
范例——
CPU #4:
CPUID 0000000B 00000001-00000002-00000100-00000003
CPUID 0000000B 00000004-00000004-00000201-00000003
简单解释一下“CPUID 0000000B”——
bits nums lv_num lv_type APICID
A_04_00 B_15_00 C_07_00 C_15_08 D_31_00
1 2 0 1 00000003
4 4 1 2 00000003
首先可以得到——
x2APIC_ID = 00000003
SMT_Mask_Width = 1
CorePlus_Mask_Width = 4
然后可以生成各个部分的掩码——
SMT_Select_Mask = ~((-1) << SMT_Mask_Width ) = 00000001
CoreOnly_Select_Mask = (~((-1) << CorePlus_Mask_Width ) ) ^ SMT_Select_Mask = 0000000E
Pkg_Select_Mask = (-1) << CorePlus_Mask_Width = FFFFFFF0
再得到各部分的子ID——
SMT_ID = x2APIC_ID & SMT_Select_Mask = 00000001
Core_ID = (x2APIC_ID & CoreOnly_Select_Mask) >> SMT_Mask_Width = 1
Pkg_ID = (x2APIC_ID & Pkg_Select_Mask) >> CorePlus_Mask_Width = 0
可以这样理解——
SMT_ID:x2APIC_ID的位域 [SMT_Mask_Width-1:0],位宽为SMT_Mask_Width。
Core_ID:x2APIC_ID的位域 [CorePlus_Mask_Width-1: SMT_Mask_Width],位宽为CorePlus_Mask_Width-SMT_Mask_Width。
Pkg_ID:x2APIC_ID的位域 [31:CorePlus_Mask_Width],位宽为32-CorePlus_Mask_Width。
注意——
**Software must not use EBX[15:0] to enumerate processor topology
of the system. This value in this field (EBX[15:0]) is only intended for
display/diagnostic purposes. The actual number of logical process