[笔记] 分解多核CPU的x2APIC_ID(或APIC_ID)中的各个子字段

本文详细介绍了如何分解x2APIC_ID和APIC_ID以获取SMT_ID、Core_ID和Pkg_ID。通过CPUID指令和位宽计算,展示了如何从这些ID中提取出处理器的SMT、核心和封装信息,从而理解多核CPU的拓扑结构。
摘要由CSDN通过智能技术生成

一、分解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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值