物理核与逻辑核-转 perf

 


Linux和Windows 物理CPU、物理核、逻辑核——区别、关系和查看

 cat /proc/cpuinfo命令部分输出信息的含义

physical id    物理封装的处理器的id
processor 逻辑核的id
core id 一颗处理器中的每个物理核的id
cpu cores 位于相同物理封装的处理器中的物理核的数量
siblings 位于相同物理封装的处理器中的逻辑核的数量


这个现场和intel的fae交流了一下,同一个物理核上的2个逻辑核(core 0, core 28),共享L1,L12cache,指令发射、执行电路。当同一个硬核上的2个逻辑核,只有一个在使用的时候,他的cache 命中率,IPC(instructions per cycle)都会提高,执行相同的工作任务,由于执行效率提高,cpu 利用率就会下降(当然,具体还和cpu利用率计算的方式也有关系)。

 

下面是perf的数据, core 0和core28属于同一个物理核,core6和core34属于同一个物理核,可以看到core28的ipc明显高于core6和core34的。用perf观察cache-miss的数据,也有类似结论,不在邮件里面列出了。

perf stat -C 28

946726278451      instructions              #    1.19  insns per cycle          (100.00%)

 

perf stat -C 6

101232784938      instructions              #    1.00  insns per cycle          (100.00%)

 

perf stat -C 34

43894836578      instructions              #    0.87  insns per cycle          (100.00%)

 

概念区分和查看方法

1. CPU(处理器)数量:主板插槽上(物理封装上)的CPU芯片的个数

在cat /proc/cpuinfo 命令的输出中,每颗物理CPU都有唯一id号(即 physical id,从0开始标号),CPU数量即不同 physical id 的数量。

所以,查看CPU数量的命令:

# cat /proc/cpuinfo | grep "physical id"    // 查看所有的physical id,有多少个不同physical id就有多少颗CPU

# cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l    // 查看不同physical id的数量,直接输出CPU数量

 

2. CPU物理核数(Core):一颗物理CPU中包含的内核数量(Core)

在cat /proc/cpuinfo 命令的输出中,每颗CPU里的每个物理核(核心,内核)都有id号(即 core id,从0开始标号)。相同物理封装的CPU的物理核数即不同 core id 的数量。cpu cores的值也直接表示CPU物理核数。

 所以,查看CPU物理核数的命令

# cat /proc/cpuinfo | grep "cpu cores"    // 查看cpu cores的值,即CPU物理核数

 # cat /proc/cpuinfo | grep "core id" | sort -u | wc -l    // 查看不同core id的数量,直接输出CPU物理核数(注意:输出的是一颗CPU的物理核数)

 

3. CPU逻辑核数(CPU线程数,Thread):通过超线程技术,能将一个物理核分成多个逻辑核

一般情况,一颗物理CPU可以有多个物理内核,加上intel的超线程技术(HT, Hyper-Threading)能够把一个物理处理器(核心,内核)在软件层变成两个逻辑处理器,可以使处理器在某一时刻,同步并行处理更多指令和数据(即有多个线程并行工作)。

 

在cat /proc/cpuinfo 命令的输出中,processor的值表示逻辑处理器(逻辑核)的id号,CPU逻辑核数即不同 processor 的数量。

所以,查看CPU逻辑核数的命令:

# cat /proc/cpuinfo | grep "processor" | sort -u | wc -l    // 查看不同 processor 的数量,直接输出CPU逻辑核数总数(注意:输出的是本服务器所有CPU的逻辑核的总数)

 

查看CPU是否支持超线程

命令:cat /proc/cpuinfo

若:

 siblings = cpu cores     不支持超线程 或 未启用超线程

 siblings > cpu cores     支持并已启用超线程

 “siblings”指的是一颗物理CPU有几个逻辑核,“cpu cores”指的是一颗物理CPU有几个物理核。

 

计算服务器的物理核、逻辑核的总数

服务器的CPU物理核总数 = CPU数量 × 每颗CPU的物理核数(cpu cores)

服务器的CPU逻辑核总数 = CPU数量 × 每颗CPU的逻辑核数(siblings)

 

Linux和Windows查看CPU信息

  • linux系统: cat /proc/cpuinfo 或 lscpu
  • Windows系统:ctrl + alt + delete 打开“任务管理器”-->“性能”

 

============================== 分割线 ==================================

实际操作——分别在 CentOS 和 Windows10 查看CPU信息

1、CentOS(1 CPU四核四线程):

[root@localhost ~]# cat /proc/cpuinfo

processor : 0             # 逻辑核 id号

vendor_id : GenuineIntel

cpu family : 6

model : 61

model name : Intel Core Processor (Broadwell)

stepping : 2

microcode : 0x1

cpu MHz : 2095.146

cache size : 16384 KB

physical id : 0             # 物理CPU id号

siblings : 4                 # 该逻辑核所在的物理CPU的逻辑核数

core id : 0                  # 物理核 id号

cpu cores : 4             # 该逻辑核所在的物理CPU的物理核数

apicid : 0

initial apicid : 0

fpu : yes

fpu_exception : yes

cpuid level : 13

wp : yes

flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap xsaveopt arat

bogomips : 4190.29

clflush size : 64

cache_alignment : 64

address sizes : 46 bits physical, 48 bits virtual

power management:

 

processor : 1

vendor_id : GenuineIntel

cpu family : 6

model : 61

model name : Intel Core Processor (Broadwell)

stepping : 2

microcode : 0x1

cpu MHz : 2095.146

cache size : 16384 KB

physical id : 0

siblings : 4

core id : 1

cpu cores : 4

apicid : 1

initial apicid : 1

fpu : yes

fpu_exception : yes

cpuid level : 13

wp : yes

flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap xsaveopt arat

bogomips : 4190.29

clflush size : 64

cache_alignment : 64

address sizes : 46 bits physical, 48 bits virtual

power management:

 

processor : 2

vendor_id : GenuineIntel

cpu family : 6

model : 61

model name : Intel Core Processor (Broadwell)

stepping : 2

microcode : 0x1

cpu MHz : 2095.146

cache size : 16384 KB

physical id : 0

siblings : 4

core id : 2

cpu cores : 4

apicid : 2

initial apicid : 2

fpu : yes

fpu_exception : yes

cpuid level : 13

wp : yes

flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap xsaveopt arat

bogomips : 4190.29

clflush size : 64

cache_alignment : 64

address sizes : 46 bits physical, 48 bits virtual

power management:

 

processor : 3

vendor_id : GenuineIntel

cpu family : 6

model : 61

model name : Intel Core Processor (Broadwell)

stepping : 2

microcode : 0x1

cpu MHz : 2095.146

cache size : 16384 KB

physical id : 0

siblings : 4

core id : 3

cpu cores : 4

apicid : 3

initial apicid : 3

fpu : yes

fpu_exception : yes

cpuid level : 13

wp : yes

flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap xsaveopt arat

bogomips : 4190.29

clflush size : 64

cache_alignment : 64

address sizes : 46 bits physical, 48 bits virtual

power management:

 

[root@localhost ~]# lscpu

Architecture: x86_64

CPU op-mode(s): 32-bit, 64-bit

Byte Order: Little Endian

CPU(s): 4

On-line CPU(s) list: 0-3

Thread(s) per core: 1           # 每个物理核的线程数(逻辑核数)

Core(s) per socket: 4           # 每个颗物理CPU的物理核数

Socket(s): 1                         # 物理CPU插槽数

NUMA node(s): 1

Vendor ID: GenuineIntel

CPU family: 6

Model: 61

Model name: Intel Core Processor (Broadwell)

Stepping: 2

CPU MHz: 2095.146

BogoMIPS: 4190.29

Hypervisor vendor: KVM

Virtualization type: full

L1d cache: 32K

L1i cache: 32K

L2 cache: 4096K

L3 cache: 16384K

NUMA node0 CPU(s): 0-3

Flags: fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap xsaveopt arat

 

2、 Windows10(1 CPU两核四线程):

ctrl + alt + delete 打开“任务管理器”,点击“性能”

 

完~

2019.12.06更新

posted on   爱新觉罗玄烨  阅读(214)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2021-12-14 ASAN运行选项

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示