Linux下区分物理CPU、逻辑CPU和CPU核数

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:847

基于不同指令集(ISA)的CPU产生的/proc/cpuinfo文件不一样,基于X86指令集CPU的/proc/cpuinfo文件包含如下内容:
processor  : 0
vendor_id  :GenuineIntel
cpu family  :6
model    :26
model name :Intel(R) Xeon(R) CPU E5520 @ 2.27GHz
stepping   :5
cpu MHz   :1600.000
cache size  : 8192 KB
physical id  :0
siblings    :8
core id    : 0
cpu cores   :4
apicid   :0
fpu      :yes
fpu_exception :yes
cpuid level   : 11
wp      :yes
flags      : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc ida nonstop_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr popcnt lahf_lm
bogomips   :4522.12
clflush size  :64
cache_alignment  : 64
address sizes    : 40 bits physical, 48 bits virtual
power management :
以上输出项的含义如下:
processor :系统中逻辑处理核的编号。对于单核处理器,则课认为是其CPU编号,对于多核处理器则可以是物理核、或者使用超线程技术虚拟的逻辑核
vendor_id :CPU制造商
cpu family :CPU产品系列代号
model   :CPU属于其系列中的哪一代的代号
model name:CPU属于的名字及其编号、标称主频
stepping  :CPU属于制作更新版本
cpu MHz  :CPU的实际使用主频
cache size :CPU二级缓存大小
physical id :单个CPU的标号
siblings :单个CPU逻辑物理核数
core id :当前物理核在其所处CPU中的编号,这个编号不一定连续
cpu cores :该逻辑核所处CPU的物理核数
apicid :用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续
fpu :是否具有浮点运算单元(Floating Point Unit)
fpu_exception :是否支持浮点计算异常
cpuid level :执行cpuid指令前,eax寄存器中的值,根据不同的值http://en.wikipedia.org/wiki/CPUID][color=#ff8373]cpuid指令会返回不同的内容
wp :表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)
flags :当前CPU支持的功能
http://en.wikipedia.org/wiki/Bogomips][color=#ff8373]bogomips :在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second)
clflush size :每次刷新缓存的大小单位
cache_alignment :缓存地址对齐单位
address sizes :可访问地址空间位数
power management :对能源管理的支持,有以下几个可选支持功能:
  ts:  temperature sensor
  fid:  frequency id control
  vid:  voltage id control
  ttp:  thermal trip
  tm:
  stc:
  100mhzsteps:
  hwpstate:

CPU信息中flags各项含义:
fpu: Onboard (x87) Floating Point Unit
vme: Virtual Mode Extension
de: Debugging Extensions
pse: Page Size Extensions
tsc: Time Stamp Counter: support for RDTSC and WRTSC instructions
msr: Model-Specific Registers
pae: Physical Address Extensions: ability to access 64GB of memory; only 4GB can be accessed at a time though
mce: Machine Check Architecture
cx8: CMPXCHG8 instruction
apic: Onboard Advanced Programmable Interrupt Controller
sep: Sysenter/Sysexit Instructions; SYSENTER is used for jumps to kernel memory during system calls, and SYSEXIT is used for jumps: back to the user code
mtrr: Memory Type Range Registers
pge: Page Global Enable
mca: Machine Check Architecture
cmov: CMOV instruction
pat: Page Attribute Table
pse36: 36-bit Page Size Extensions: allows to map 4 MB pages into the first 64GB RAM, used with PSE.
pn: Processor Serial-Number; only available on Pentium 3
clflush: CLFLUSH instruction
dtes: Debug Trace Store
acpi: ACPI via MSR
mmx: MultiMedia Extension
fxsr: FXSAVE and FXSTOR instructions
sse: Streaming SIMD Extensions. Single instruction multiple data. Lets you do a bunch of the same operation on different pieces of input: in a single clock tick.
sse2: Streaming SIMD Extensions-2. More of the same.
selfsnoop: CPU self snoop
acc: Automatic Clock Control
IA64: IA-64 processor Itanium.
ht: HyperThreading. Introduces an imaginary second processor that doesn’t do much but lets you run threads in the same process a bit quicker.
nx: No Execute bit. Prevents arbitrary code running via buffer overflows.
pni: Prescott New Instructions aka. SSE3
vmx: Intel Vanderpool hardware virtualization technology
svm: AMD “Pacifica” hardware virtualization technology
lm: “Long Mode,” which means the chip supports the AMD64 instruction set
tm: “Thermal Monitor” Thermal throttling with IDLE instructions. Usually hardware controlled in response to CPU temperature.
tm2: “Thermal Monitor 2″ Decrease speed by reducing multipler and vcore.
est: “Enhanced SpeedStep”
根据以上内容,我们则可以很方便的知道当前系统关于CPU、CPU的核数、CPU是否启用超线程等信息。
[size=14px]查询系统具有多个物理CPU:[size=14px]cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l ----physical id决定物理CPU的个数
查询系统具有多少个逻辑核:cat /proc/cpuinfo | grep "processor" | wc -l -----processor决定逻辑CPU的核数
[size=14px]查询系统CPU的物理核数:cat /proc/cpuinfo | grep "cpu cores" | uniq ------cpu cores决定CPU的物理核数
[size=14px]查询系统CPU是否启用超线程:cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings" | sort | uniq
[color=#0b050]输出举例:
[color=#0b050]     cpu cores : 6
    siblings  : 6
[color=#0b050]如果cpu cores数量和siblings数量一致,则没有启用超线程,否则超线程被启用。

判断依据:
1.具有相同core id的 cpu是同一个core的超线程。
2.具有相同physical id的cpu是同一颗cpu封装的线程或者cores。
英文版:
1.Physical id and core id are not necessarily consecutive but they are
unique. Any cpu with the same core id are hyperthreads in the same core.
2.Any cpu with the same physical id are threads or cores in the same physical socket.

实例:
LunarPages的CPU信息:
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.00GHz
stepping : 3
cpu MHz : 3000.881
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc
pni monitor ds_cpl cid xtpr
bogomips : 6006.73
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.00GHz
stepping : 3
cpu MHz : 3000.881
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc
pni monitor ds_cpl cid xtpr
bogomips : 5999.40
processor : 2
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.00GHz
stepping : 3
cpu MHz : 3000.881
cache size : 2048 KB
physical id : 3
siblings : 2
core id : 3
cpu cores : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc
pni monitor ds_cpl cid xtpr
bogomips : 5999.08
processor : 3
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.00GHz
stepping : 3
cpu MHz : 3000.881
cache size : 2048 KB
physical id : 3
siblings : 2
core id : 3
cpu cores : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc
pni monitor ds_cpl cid xtpr
bogomips : 5999.55

processor从0--3 ----显示4个逻辑CPU
physical id只有(0,3) ----[color=#0b050]所以物理CPU有两个
physical id : 0对应的cpu cores 为1,physical id : 3对应的cpu cores 为1 [color=#0b050] -----两个物理CPU都是单[color=#0b050]核
[color=#0b050]明显cpu core和siblings不等,所以启用了超线程技术

siblings指的是一个物理CPU有几个逻辑CPU
cpu cores指的是一个物理CPU有几个核
如果“siblings”是“cpu cores”的两倍,则说明支持超线程,并且超线程已打开。

一般情况建议oracle开的并行度总和不超过cpu总核数的一半

如何获得CPU的详细信息:
linux 命令:cat /proc/cpuinfo
用命令判断几个物理CPU,几个核等:
逻辑CPU个数:
# cat /proc/cpuinfo | grep “processor” | wc -l
物理CPU个数:
# cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l
每个物理CPU中Core的个数:
# cat /proc/cpuinfo | grep “cpu cores” | wc -l
是否为超线程?
如果有两个逻辑CPU具有相同的”core id”,那么超线程是打开的。
每个物理CPU中逻辑CPU(可能是core, threads或both)的个数:
# cat /proc/cpuinfo | grep “siblings”
其他特征:
目前intel新的多核心cpu都会在后面显示具体的型号数字,例如:
model name : Intel(R) Xeon(R) CPU X3230 @ 2.66GHz
说明是 Xeon 3230的cpu,而不显示型号的具体数字的,大部分都是奔腾的CPU
很多主机商都骗人,用奔腾的cpu,却说是多核心的CPU。
探针看到的数据:
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
没有具体的型号,缓存1M,一般都是奔腾系列的cpu,或者是intel假双核的cpu,具体要根据上面说的去判断。新的多核心cpu都能看到具体的型号。
另外多核心的xeon的CPU,一般主频都不高,达到2.8和3.0的只有很少的几个高端CPU型号,一般主机商不会用这么好的。

一些操作 系统的最新版本已经更新了 /proc/cpuinfo 文件,以支持多路平台。如果您的系统中的 /proc/cpuinfo 文件能够正确地反映出处理器信息,那么就不需要执行上述步骤。反之,可采用本文中的信息进行解释。
/proc/cpuinfo 文件包含系统上每个处理器的数据段落。/proc/cpuinfo 描述中有 6
个条目适用于多 内核和超线程(HT)技术检查:processor, vendor id, physical id, siblings, core
id 和 cpu cores。
processor 条目包括这一逻辑处理器的唯一标识符。
physical id 条目包括每个物理封装的唯一标识符。
core id 条目保存每个内核的唯一标识符。
siblings 条目列出了位于相同物理封装中的逻辑处理器的数量。
cpu cores 条目包含位于相同物理封装中的内核数量。

如果处理器为英特尔处理器,则 vendor id 条目中的字符串是 GenuineIntel。
1.拥有相同 physical id 的所有逻辑处理器共享同一个物理插座。每个 physical id 代表一个唯一的物理封装。
2.Siblings 表示位于这一物理封装上的逻辑处理器的数量。它们可能支持也可能不支持超线程(HT)技术。
3.每个 core id 均代表一个唯一的处理器内核。带有相同 core id 的逻辑处理器均位于同一个处理器内核上。
4.如果有一个以上逻辑处理器拥有相同的 core id 和 physical id,则说明系统支持超线程(HT)技术。
5.如果有两个或两个以上的逻辑处理器拥有相同的 physical id,但是 core id 不同,则说明这是一个多内核处理器。cpu cores 条目也可以表示是否支持多内核。

例如,如果系统包含两个物理封装,每个封装中又包含两个支持超线程(HT)技术的处理器内核,则 /proc/cpuinfo 文件将包含此数据

processor

0

1

2

3

4

5

6

7

physical id

0

1

0

1

0

1

0

1

core id

0

2

1

3

0

2

1

3

siblings

4

4

4

4

4

4

4

4

cpu cores

2

2

2

2

2

2

2

2

1.此例说明逻辑处理器 0 和 4 驻留在物理封装 0 的内核 0 上。这就表示逻辑处理器 0 和 4 支持超线程(HT)技术。
2.相同的工作可用于封装 0 内核 1 上的逻辑处理器 2 和 6,封装 1 内核 2 上的逻辑处理器 1 和 5,以及封装 1 内核 3 上的逻辑处理器 3 和 7。
3.此系统支持超线程(HT)技术,因为两个逻辑处理器共享同一个内核。
4.有两种方式可以确定是否支持多内核:
a.由于内核 0 和 1 存在于封装 0 上,而内核 2 和 3 存在于封装 1 上,所以这是一个多内核系统。
b.此外,cpu cores 条目为 2,也说明有两个内核驻留在物理封装中。这是一个多路系统,因为有两个封装。

值得注意的是 physical id 和 core id 的编号可能是也可能不是连续的。系统上有两个物理封装并不罕见,如上例 physical id 等于 0 和 3

由于IE浏览器升级禁用了alt+x快捷键,请用alt+q快捷键来快速进入写说说入口

正在加载中...

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】