CPU中央处理单元通常简称为处理器,是计算机最重要的组件之一。它执行所有类型的数据处理操作,并被视为计算机的大脑。
root@ubuntu:/home/# lscpu
Architecture: x86_64 #cpu架构
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian #小尾序
CPU(s): 1 #总共有1核
On-line CPU(s) list: 0
Thread(s) per core: 1 #每个cpu核,只能支持一个线程,即不支持超线程
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel #cpu产商 intel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Stepping: 9
CPU MHz: 3408.070
BogoMIPS: 6816.14
Hypervisor vendor: VMware
Virtualization type: full #支持cpu虚拟化技术
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0
以下为一台Vmware虚拟机
[root@localhost /]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 45 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Vendor ID: GenuineIntel
BIOS Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
BIOS Model name: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
CPU family: 6
Model: 94
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
Stepping: 3
BogoMIPS: 6384.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_ts c cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_sing le pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves arat md_clear flush_l1d arch_capabilities
Virtualization features:
Hypervisor vendor: VMware
Virtualization type: full
Caches (sum of all):
L1d: 64 KiB (2 instances)
L1i: 64 KiB (2 instances)
L2: 512 KiB (2 instances)
L3: 6 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0,1
Vulnerabilities:
Itlb multihit: KVM: Mitigation: VMX unsupported
L1tf: Mitigation; PTE Inversion
Mds: Mitigation; Clear CPU buffers; SMT Host state unknown
Meltdown: Mitigation; PTI
Mmio stale data: Mitigation; Clear CPU buffers; SMT Host state unknown
Retbleed: Mitigation; IBRS
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected
Srbds: Unknown: Dependent on hypervisor status
Tsx async abort: Not affected
[root@localhost /]#
[root@localhost /]# lscpu | grep -i 'Model name'
Model name: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
BIOS Model name: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
[root@localhost /]#
[root@localhost /]# lscpu | grep -i "Model name:" | cut -d':' -f2- -
Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
[root@localhost /]#
[root@localhost /]# lscpu | grep -i "CPU(s)"
CPU(s): 2
On-line CPU(s) list: 0,1
NUMA node0 CPU(s): 0,1
[root@localhost /]#
lscpu从文件/proc/cpuinfo中收集处理器详细信息。因此,可以cat来查看 Linux 中的 CPU 详细信息。查看/proc/cpuinfo,可以知道每个cpu信息,如每个CPU的型号,主频等。
root@ubuntu:/home/# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
stepping : 9
microcode : 0x48
cpu MHz : 3408.070
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
.....
以下为一台Vmware虚拟机
[root@localhost /]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
stepping : 3
microcode : 0xf0
cpu MHz : 3192.004
cache size : 6144 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves arat md_clear flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds mmio_stale_data retbleed
bogomips : 6384.00
clflush size : 64
cache_alignment : 64
address sizes : 45 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
stepping : 3
microcode : 0xf0
cpu MHz : 3192.004
cache size : 6144 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves arat md_clear flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds mmio_stale_data retbleed
bogomips : 6384.00
clflush size : 64
cache_alignment : 64
address sizes : 45 bits physical, 48 bits virtual
power management:
[root@localhost /]#
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
[root@localhost /]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
1
cat /proc/cpuinfo| grep "cpu cores"| uniq
[root@localhost /]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores : 2
cat /proc/cpuinfo| grep "processor"| wc -l
[root@localhost /]# cat /proc/cpuinfo| grep "processor"| wc -l
2
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
[root@localhost /]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
2 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Lshw (Hardware Lister) 是一个功能齐全的 CLI 应用程序,可提供有关 Linux 系统硬件配置的详细信息。它可以获取硬件详细信息,例如确切的内存配置、固件版本、主板配置、CPU 版本和速度、缓存配置、总线速度等。
yum install lshw lshw-gtk
lshw -class processor
[root@localhost /]# lshw -class processor
*-cpu:0
description: CPU
product: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
vendor: Intel Corp.
physical id: 1
bus info: cpu@0
version: 6.94.3
slot: CPU #000
size: 3200MHz
capacity: 4230MHz
width: 64 bits
capabilities: lm fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp x86-64 constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves arat md_clear flush_l1d arch_capabilities
configuration: cores=2 enabledcores=2 microcode=240
lshw -short -class processor
[root@localhost /]# lshw -short -class processor
H/W path Device Class Description
============================================================
/0/1 processor Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
dmidecode应用程序从 DMI表中获取系统硬件组件的详细信息。它将首先尝试从 中读取 DMI 表sysfs,然后如果sysfs访问失败则尝试直接从内存中读取。找到 DMI 表后,dmidecode 将解析该表并以人类可读的格式显示系统的硬件信息。Dmidecode 预装在大多数 Linux 操作系统中,可以直接使用。
dmidecode --type processor
[root@localhost /]# dmidecode --type processor
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.
Handle 0x0004, DMI type 4, 42 bytes
Processor Information
Socket Designation: CPU #000
Type: Central Processor
Family: Unknown
Manufacturer: GenuineIntel
ID: E3 06 05 00 FF FB 8B 1F
Version: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Voltage: 3.3 V
External Clock: Unknown
Max Speed: 30000 MHz
Current Speed: 3200 MHz
Status: Populated, Enabled
Upgrade: ZIF Socket
L1 Cache Handle: 0x0094
L2 Cache Handle: 0x0114
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 2
Core Enabled: 2
Characteristics:
64-bit capable
Multi-Core
Execute Protection