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更新

最新文章

  1. [转]Linux中configure/makefile
  2. 如何在一台新电脑上配置JAVA开发环境
  3. JAVA异常处理机制的简单原理和应用
  4. Android应用更换package name以及ui refactoring error问题的有效解决
  5. valuestack,stackContext,ActionContext.之间的关系以及如何存取数值的
  6. iOS 2D绘图详解(Quartz 2D)之Bitmap
  7. Web 技术人员需知的Web 缓存知识
  8. WPF中不规则窗体与WindowsFormsHost控件的兼容问题完美解决方案
  9. ZOJ-2365 Strong Defence 贪心,BFS
  10. HDU 5215 BestCoder"杯中国大学生程序设计冠军赛” 边双连通分量取出子图+二分染色判图内奇偶环
  11. Oracle 的process和Session
  12. Swift中的as操作符
  13. centos7 nginx配置ssl证书实现https访问同时http访问
  14. 给uniGUI的表格控件uniDBGrid加上记录序号的列
  15. HTML 5 Canvas vs. SVG
  16. java 延时的几种方法方法
  17. 跟未名学Office - PPT操作:高效
  18. CentOS 65 安装vmware tools 杂记
  19. C/C++内存管理详解 ZZ
  20. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011

热门文章

  1. orw入门报告
  2. Vue学习:实现用户没有登陆时,访问后自动跳转登录页面
  3. 有趣的python库-pyttsx3
  4. Linux服务器数据备份恢复
  5. Postgresql架构体系解析
  6. sql查询多个结果字段通过逗号分隔为同一行显示、sql查询结果有符号分隔的字段拆分多行显示
  7. c++_成员函数回调
  8. 泛型stringToNumber
  9. 2022年了!还在用定时器实现动画?赶紧试试requestAnimationFrame吧!
  10. Spring全家桶(二)之SpringMVC总结