Footsteps on my way !
perl/linux/测序分析

linux查看有几个cpu几个核心几个线程

Linux系统中,提供了proc文件系统显示系统的软硬件信息。如果想了解系统中CPU的提供商和相关配置信息,则可以通过/proc/cpuinfo文件得到。本文章针对该文件进行简单的总结。

基于不同指令集(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寄存器中的值,根据不同的值cpuid指令会返回不同的内容
wp             :表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)
flags          :当前CPU支持的功能
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”

判断依据:
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.

/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 表示位于这一物理封装上的逻辑处理器的数量。
3.每个 core id 均代表一个唯一的处理器内核。
4.如果有一个以上逻辑处理器拥有相同的 core id 和 physical id,证明一个core上有多个线程,则说明系统支持超线程(HT)技术。
5.core id不同的逻辑处理器physical id相同,则说明这是一个多内核处理器。cpu cores 条目也可以表示是否支持多内核。

判断CPU是否64位,检查cpuinfo中的flags区段,看是否有lm标识。
Are the processors 64-bit?   
A 64-bit processor will have lm (“long mode”) in the flags section of cpuinfo. A 32-bit processor will not.

根据以上内容,我们则可以很方便的知道当前系统关于CPU、CPU的核数、CPU是否启用超线程等信息。

1. 查看机器的物理CPU个数
#cat /proc/cpuinfo |grep “physical id”|sort |uniq|wc -l

2. 查看逻辑CPU的个数
#cat /proc/cpuinfo |grep “processor”|wc -l

3. 查看CPU是几核(查询系统CPU的物理核数)
#cat /proc/cpuinfo |grep “cpu cores”|uniq

4. 查看CPU的主频
#cat /proc/cpuinfo |grep MHz|uniq

5. 查询系统CPU是否启用超线程:(如果有两个逻辑CPU具有相同的”core id”,那么超线程是打开的。或者siblings数目比cpu cores数目大。)

#cat /proc/cpuinfo | grep -e “cpu cores”  -e “siblings” | sort | uniq

输出举例:

cpu cores    : 6
siblings     : 6

如果cpu cores数量和siblings数量一致,则没有启用超线程,否则超线程被启用。

查询系统CPU的个数:cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l

# cat /proc/cpuinfo | grep flags | grep ‘ lm ‘ | wc -l

8

(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)

# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

8 Intel(R) Xeon(R) CPU E5410 @ 2.33GHz

(看到有8个逻辑CPU, 也知道了CPU型号)

查询系统CPU是否支持某项功能,则根以上类似,输出结果进行sort, uniq和grep就可以得到结果。

# uname -a

Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux

(查看当前操作系统内核信息)

# cat /etc/issue | grep Linux

Red Hat Enterprise Linux AS release 4 (Nahant Update 5)

(查看当前操作系统发行版信息)

# getconf LONG_BIT

32

(说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)

 

【本文整合于一下资料】

  1. http://blog.sina.com.cn/s/blog_4bde3c5101015gbr.html
  2. http://www.cnblogs.com/wuzhiwu/archive/2011/10/09/cpuinfo_analyze.html
  3. http://www.zxsdw.com/index.php/archives/842/#

【推荐资料】

1,http://www.unixresources.net/linux/clf/program/archive/00/00/66/13/661380.html#article666843

该参考资料为使用cpuid指令实际获取CPU信息代码,值得了解技术人士参阅

2,http://www.richweb.com/cpu_info

该参考资料列举了单核CPU情况下的cpuinfo文件、多核CPU使用超线程和不使用超线程的cpuinfo文件以及多个多核CPU情况下的cpuinfo文件,值得一看

 

分享到:更多 ()

评论 3

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    Você tem um fabuloso blog de graças.

    sikis izle7年前 (2016-05-08)回复
  2. #0

    Nice post. I be taught one thing tougher on totally different blogs everyday. It should always be stimulating to read content material from other writers and observe a little bit something from their store. I抎 prefer to make use of some with the content on my weblog whether or not you don抰 mind. Natually I抣l offer you a hyperlink on your internet blog. Thanks for sharing.

    michael kors handbags7年前 (2016-08-10)回复
  3. #0

    This really answered my downside, thanks!

    michael kors handbags7年前 (2016-08-13)回复