linux cpu info

本文详细解读Linux系统下/proc/cpuinfo文件,提供如何获取CPU核心数、型号、供应商等信息的方法,并展示不同指令集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 :[8]

 

以上输出项的含义如下:

 

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 :对能源经管的支撑

 

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 ute 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是否启用超线程等信息。

 

查询体系具有几许个逻辑核:cat /proc/cpuinfo | grep "processor" | wc -l

 

查询体系CPU的物理核数:cat /proc/cpuinfo | grep "cpu cores" | uniq

 

查询体系CPU是否启用超线程: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

 

查询体系CPU是否支撑某项功能,则根以上类似,输出成果进行sort, uniq和grep就可以获得成果。

 

【/proc/cpuinfo内容举例】

 

1,Intel(R) Xeon(R) X5355

 

processor  : 0
vendor_id  : GenuineIntel
cpu famil  : 6
model     : 15
model name  : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping   : 7
cpu MHz   : 2666.766
cache size : 4096 KB
physical id : 0
siblings   : 4
core id    : 0
cpu cores  : 4
fpu      : yes
fpu_exception  : yes
cpuid level   : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5338.26
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor    : 1
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 1
siblings    : 4
core id        : 0
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.75
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 2
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 0
siblings    : 4
core id        : 2
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.67
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 3
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 1
siblings    : 4
core id        : 2
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.68
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 4
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 0
siblings    : 4
core id        : 1
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.67
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 5
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 1
siblings    : 4
core id        : 1
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.68
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 6
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 0
siblings    : 4
core id        : 3
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.69
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 7
vendor_id    : GenuineIntel
cpu family    : 6
model        : 15
model name    : Intel(R) Xeon(R) CPU           X5355  @ 2.66GHz
stepping    : 7
cpu MHz        : 2666.766
cache size    : 4096 KB
physical id    : 1
siblings    : 4
core id        : 3
cpu cores    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
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 lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr dca lahf_lm
bogomips    : 5333.68
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

 

2, Intel(R) Core(TM) i7 930 @ 2.80GHz

 

processor	: 0

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 1

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 2

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 3

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 4

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 5

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 6

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:



processor	: 7

vendor_id	: GenuineIntel

cpu family	: 6

model		: 26

model name	: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz

stepping	: 5

cpu MHz		: 2807.024

cache size	: 8192 KB

fpu		: yes

fpu_exception	: yes

cpuid level	: 11

wp		: yes

flags		: fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm ida

bogomips	: 5614.04

clflush size	: 64

cache_alignment	: 64

address sizes	: 36 bits physical, 48 bits virtual

power management:

 

【推荐材料】

 

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文件,值得一看

Linux系统中,查看CPU相关信息是一个常见的需求,尤其在系统监控、性能调优和故障排查中尤为重要。Linux提供了多种命令行工具和系统文件来获取详细的CPU信息。 ### 查看CPU基本信息 要查看CPU的基本信息,例如型号、核心数、线程数等,可以使用 `lscpu` 命令: ```bash lscpu ``` 该命令会输出CPU架构、型号名称、核心数、线程数等信息,适用于快速了解系统的CPU配置。 若需要更详细的CPU硬件信息,可以查看 `/proc/cpuinfo` 文件: ```bash cat /proc/cpuinfo ``` 该文件包含每个逻辑CPU的详细信息,如处理器型号、频率、缓存、物理ID等,适用于需要深入分析的场景。 ### 查看CPU利用率 要实时查看CPU的利用率,可以使用 `top` 命令: ```bash top ``` 在输出界面中,第三行的 `%Cpu(s)` 字段显示了CPU的总体使用情况,包括用户态、系统态、空闲等状态的百分比。 对于更友好的交互式界面,可以使用 `htop`(需安装): ```bash htop ``` `htop` 提供了彩色的界面和更直观的条形图显示CPU利用率,适合可视化监控。 若需要查看每个进程的CPU使用情况,可以使用 `pidstat` 命令: ```bash pidstat -u ``` 该命令会列出每个进程的CPU使用率,包括用户态和内核态的使用情况,适用于性能分析和资源占用追踪。 ### 查看CPU频率 查看当前CPU频率可以使用 `cpufreq-info`(需安装)或 `laptop_mode` 工具包中的脚本: ```bash cpufreq-info ``` 此外,也可以直接读取系统文件: ```bash cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ``` 该命令将显示当前CPU的运行频率(单位为kHz)。 ### 查看CPU温度 虽然不属于CPU本身的信息,但在监控系统健康状态时,CPU温度也是重要指标。可以通过 `lm-sensors` 工具查看: ```bash sensors ``` 执行该命令后,会显示包括CPU在内的各个硬件温度传感器的读数。 ### 示例脚本:获取CPU利用率 以下是一个简单的Bash脚本,用于获取当前CPU的总利用率: ```bash #!/bin/bash # 获取第一次CPU使用情况 read cpu a b c d e f g h < /proc/stat sleep 1 # 获取第二次CPU使用情况 read cpu2 a2 b2 c2 d2 e2 f2 g2 h2 < /proc/stat # 计算总使用时间 total1=$((a + b + c + d + e + f + g + h)) total2=$((a2 + b2 + c2 + d2 + e2 + f2 + g2 + h2)) # 计算空闲时间 idle1=$((d)) idle2=$((d2)) # 计算使用率 diff_total=$((total2 - total1)) diff_idle=$((idle2 - idle1)) cpu_usage=$((100 * (diff_total - diff_idle) / diff_total)) echo "CPU Usage: ${cpu_usage}%" ``` 该脚本通过两次读取 `/proc/stat` 文件并计算差值来得出CPU利用率。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值