Linux/CPU

Linux/CPU

CLI

# 显示系统 CPU 的所有逻辑(logical)核心。(1个超线程的物理核心会显示为2个逻辑核心)
cat /proc/cpuinfo

Linux kernel / scheduler 能够通过 BIOS / UEFI 提供的 ACPI 等机制获取到系统的 CPU 拓扑信息:

awk '/^domain/ { print $1, $2; } /^cpu/ { print $1; }' /proc/schedstat

例如:

对于1个 cat /proc/cpuinfo 显示 40 个核心(processor 0-39) "Intel(R) Xeon(R) Silver 4210 CPU @ 2.20GHz" 的系统

[root@hostname]# awk '/^domain/ { print $1, $2; } /^cpu/ { print $1; }' /proc/schedstat 
cpu0
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00100001
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu1
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00200002
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu2
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00400004
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu3
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00800008
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu4
domain0 00000000,00000000,00000000,00000000,00000000,00000000,01000010
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu5
domain0 00000000,00000000,00000000,00000000,00000000,00000000,02000020
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu6
domain0 00000000,00000000,00000000,00000000,00000000,00000000,04000040
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu7
domain0 00000000,00000000,00000000,00000000,00000000,00000000,08000080
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu8
domain0 00000000,00000000,00000000,00000000,00000000,00000000,10000100
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu9
domain0 00000000,00000000,00000000,00000000,00000000,00000000,20000200
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu10
domain0 00000000,00000000,00000000,00000000,00000000,00000000,40000400
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu11
domain0 00000000,00000000,00000000,00000000,00000000,00000000,80000800
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu12
domain0 00000000,00000000,00000000,00000000,00000000,00000001,00001000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu13
domain0 00000000,00000000,00000000,00000000,00000000,00000002,00002000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu14
domain0 00000000,00000000,00000000,00000000,00000000,00000004,00004000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu15
domain0 00000000,00000000,00000000,00000000,00000000,00000008,00008000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu16
domain0 00000000,00000000,00000000,00000000,00000000,00000010,00010000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu17
domain0 00000000,00000000,00000000,00000000,00000000,00000020,00020000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu18
domain0 00000000,00000000,00000000,00000000,00000000,00000040,00040000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu19
domain0 00000000,00000000,00000000,00000000,00000000,00000080,00080000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu20
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00100001
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu21
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00200002
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu22
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00400004
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu23
domain0 00000000,00000000,00000000,00000000,00000000,00000000,00800008
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu24
domain0 00000000,00000000,00000000,00000000,00000000,00000000,01000010
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu25
domain0 00000000,00000000,00000000,00000000,00000000,00000000,02000020
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu26
domain0 00000000,00000000,00000000,00000000,00000000,00000000,04000040
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu27
domain0 00000000,00000000,00000000,00000000,00000000,00000000,08000080
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu28
domain0 00000000,00000000,00000000,00000000,00000000,00000000,10000100
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu29
domain0 00000000,00000000,00000000,00000000,00000000,00000000,20000200
domain1 00000000,00000000,00000000,00000000,00000000,00000000,3ff003ff
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu30
domain0 00000000,00000000,00000000,00000000,00000000,00000000,40000400
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu31
domain0 00000000,00000000,00000000,00000000,00000000,00000000,80000800
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu32
domain0 00000000,00000000,00000000,00000000,00000000,00000001,00001000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu33
domain0 00000000,00000000,00000000,00000000,00000000,00000002,00002000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu34
domain0 00000000,00000000,00000000,00000000,00000000,00000004,00004000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu35
domain0 00000000,00000000,00000000,00000000,00000000,00000008,00008000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu36
domain0 00000000,00000000,00000000,00000000,00000000,00000010,00010000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu37
domain0 00000000,00000000,00000000,00000000,00000000,00000020,00020000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu38
domain0 00000000,00000000,00000000,00000000,00000000,00000040,00040000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff
cpu39
domain0 00000000,00000000,00000000,00000000,00000000,00000080,00080000
domain1 00000000,00000000,00000000,00000000,00000000,000000ff,c00ffc00
domain2 00000000,00000000,00000000,00000000,00000000,000000ff,ffffffff

以上显示了所有40个逻辑 CPU 核心所属的拓扑架构。这是一个3层的 CPU 拓扑:

domain0 <-- 某个物理 CPU 核心
domain1 <-- 某颗 CPU
domain2 <-- 整个这个系统

可以看出这是个多路 CPU 的服务器,安装了 2路 Intel(R) Xeon(R) Silver 4210 CPU;每个 CPU 是 10核20线程。

0 路物理 CPU 对应逻辑核心: cpu0-9, cpu20-29
1 路物理 CPU 对应逻辑核心: cpu10-19, cpu30-39

cpu0 和 cpu20 对应同一个 CPU 物理核心的2个超线程逻辑核心(这两个逻辑 cpu 的 domain0, domain1, domain2 均完全相同),其它以此类推。

这种多路 CPU 服务器一般属于 NUMA (Non-uniform memory access, 非均匀访存模型) 系统。即不同路的 CPU 访问不同位置插槽内存的成本(延迟)有差异。

参考资料:


Last update: 2022-09-02 06:31:35 UTC