Linux-2.查看硬件信息-cpu

Linux查看CPU
cat /proc/cpuinfo

[root@10-222 /]# cat /proc/cpuinfo
processor       : 0                           #邏輯處理器標識
vendor_id       : GenuineIntel       #cpu供應商ID
cpu family      : 6                                
model           : 30
model name      : Intel(R) Xeon(R) CPU           X3470  @ 2.93GHz
stepping        : 5
cpu MHz         : 2926.061
cache size      : 8192 KB
physical id     : 0                # 物理處理器標識
siblings        : 8                # 表示位於這一物理封裝上的邏輯處理器的數量。它們可能支持也可能不支持超線程(HT)技術。    
core id         : 0                # 處理器內核標識
cpu cores       : 4                # 單個物理處理器裏的內核數
apicid          : 0
initial apicid  : 0
fdiv_bug        : no      #浮點除bug不支持
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
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 pbe nx rdtscp lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm ida
                                        # lm - long mode 64位支持 lm則是64bit;vmx - INTEL 虛擬化支持;svm - AMD 虛擬化支持
                                        # ht - 超線程
bogomips        : 5856.80
clflush size    : 64
power management:
======================================

physical id 物理處理器標識
cpu cores 位於相同物理封裝的處理器中的內核數量。
processor 邏輯處理器標識
core id 處理器內核標識(具有相同core id的cpu是同一個core的超線程。)
apicid 中斷處理器標識
Siblings 表示位於這一物理封裝上的邏輯處理器的數量。它們可能支持也可能不支持超線程(HT)技術。位於相同物理封裝的處理器中的邏輯處理器的數量。

=======================================
# 總核數 = 物理CPU個數 X 每顆物理CPU的核數
# 總邏輯CPU數 = 物理CPU個數 X 每顆物理CPU的核數 X 超線程數

查看有幾個物理CPU(physical id 物理封裝的處理器的id。)
判斷物理CPU的個數可以查看physical id 的值,相同則爲同一個物理
-----------------------------------------
#cat /proc/cpuinfo | grep 'physical id' | uniq -c
      4 physical id      : 0
      4 physical id      : 1
(表示有2個物理CPU)


實例:
查看有幾個物理CPU
# cat /proc/cpuinfo | grep 'physical id' | uniq -c
      8 physical id      : 0
這臺服務器有1個物理CPU

# 查看每個物理CPU中core的個數(即核數)
----------------------------------------
cat /proc/cpuinfo| grep "cpu cores"| sort -u
cpu cores    : 4
這臺服務器cpu是4核

# 查看邏輯CPU的個數(processor 邏輯處理器的id)
------------------------------------------------
cat /proc/cpuinfo| grep "processor"| wc -l
8
這臺服務有8個邏輯cpu (應該是上面的公司 邏輯cup= 1 *4  爲4個, 但現在是8個,說明是超線程)

具有相同core id的cpu是同一個core的超線程。
進行驗證
[root@10-222 ~]# cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 1
core id         : 2
core id         : 3
core id         : 0
core id         : 1
core id         : 2
core id         : 3
所以這裏是1個物理CPU,有4核,支持超線程,所有顯示邏輯cpu是8

支持64位
# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
   8
(結果大於0, 說明支持64bit計算. lm指long mode, 支持lm則是64bit)

同樣的原理cat /proc/cpuinfo | grep "要查的信息"   
cpu 的型號,cpu MHz ,都可以查詢  只加個過濾管道 grep


雖然採用超線程技術能同時執行兩個線程,但它並不象兩個真正的CPU那樣,每個CPU都具有獨立的資源。
當兩個線程都同時需要某一個資源時,其中一個要暫時停止,並讓出資源,直到這些資源閒置後才能繼續。
因此超線程的性能並不等於兩顆CPU的性能。


再完整看cpu詳細信息, 不過大部分我們都不關心而已.
[root@10-222 ~]#dmidecode  | grep  'Processor Information' -B 1 -A 54
Handle 0x0400, DMI type 4, 40 bytes
Processor Information
        Socket Designation: CPU1  #關注
        Type: Central Processor
        Family: Xeon     #關注
        Manufacturer: Intel
        ID: E5 06 01 00 FF FB EB BF  #關注,保修可能要用
        Signature: Type 0, Family 6, Model 30, Stepping 5
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (Fast floating-point save and restore)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Hyper-threading technology)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Xeon(R) CPU           X3470  @ 2.93GHz  #關注
        Voltage: 1.2 V
        External Clock: 4800 MHz
        Max Speed: 3600 MHz      #關注
        Current Speed: 2933 MHz  #關注
        Status: Populated, Enabled
        Upgrade: <OUT OF SPEC>
        L1 Cache Handle: 0x0700
        L2 Cache Handle: 0x0701
        L3 Cache Handle: 0x0702
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Core Count: 4   #關注
        Core Enabled: 4 #關注
        Thread Count: 8 #關注
        Characteristics:
                64-bit capable

裏面還有很多概念沒有說,在後面的文章中介紹
例如:物理cpu,邏輯cpu,線程,超線程,以及cpu的緩存,命中率,中斷等的,以及他們之間的關係,

以上個人一點點總結和理解,水平不高,文筆水平很爛,請各位大大見諒。
可以一起交流學習。

  我的QQ:610851588
  可以加入我建的羣(現在羣人很少,希望慢慢多起來)
  Linux  羣:183932302
  Python ,shell 交流羣:469094734

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章