【无标题】查看Linux系统CPU信息

CPU中央处理单元通常简称为处理器,是计算机最重要的组件之一。它执行所有类型的数据处理操作,并被视为计算机的大脑。

1、检查 CPU 信息,查看的是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 /]# 

1.1、显示lscpu在 Linux 中使用的特定 CPU 信息

  • lscpu会输出 CPU 的完整信息。可以用grep搜索指定的字段信息,例如model name
[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 /]# 
  • 你还可以找到其他 CPU 详细信息,例如CPU 核心数,如下所示:
[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 /]# 

2、在 Linux 中使用/proc/cpuinfo文件查找 CPU 信息

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 /]# 
  • 总核数 = 物理CPU个数 × 每颗物理CPU的核数
  • 总逻辑CPU数 = 物理CPU个数 × 每颗物理CPU的核数 × 超线程数

2.1、通过如下命令,可以查看物理CPU相关信息。

  • 查看物理CPU个数。
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
[root@localhost /]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
1
  • 查看每个物理CPU中core的个数,即CPU核数。
cat /proc/cpuinfo| grep "cpu cores"| uniq
[root@localhost /]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores       : 2
  • 查看逻辑CPU的个数。
cat /proc/cpuinfo| grep "processor"| wc -l
[root@localhost /]# cat /proc/cpuinfo| grep "processor"| wc -l
2
  • 查看CPU型号。
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

3、查看处理器信息

Lshw (Hardware Lister) 是一个功能齐全的 CLI 应用程序,可提供有关 Linux 系统硬件配置的详细信息。它可以获取硬件详细信息,例如确切的内存配置、固件版本、主板配置、CPU 版本和速度、缓存配置、总线速度等。

  • 它预装在大多数 Linux 发行版上。如果需要安装可以执行下面的命令。
yum install lshw lshw-gtk
  • 要查看处理器信息lshw
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
  • 如果你只想显示处理器型号,使用-short参数。
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

4、使用获取处理器详细信息dmidecode

dmidecode应用程序从 DMI表中获取系统硬件组件的详细信息。它将首先尝试从 中读取 DMI 表sysfs,然后如果sysfs访问失败则尝试直接从内存中读取。找到 DMI 表后,dmidecode 将解析该表并以人类可读的格式显示系统的硬件信息。Dmidecode 预装在大多数 Linux 操作系统中,可以直接使用。

  • 使用dmidecode 获取CPU详细信息。
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

你可能感兴趣的:(Linux,linux,ubuntu,运维)