/ proc File System - Viewing CPU Basic Information

Keywords: Linux

  • /proc/cpuinfo
  • /proc/stat

/proc/cpuinfo

I. Basic concepts

CPU: Central Processor Unit

CPU Core: The core becomes the core, which is an important part of the CPU. All CPU computations, acceptance/storage commands, and processing data are executed by the core

Multi-core CPU: CPU chips contain multiple processor cores (i.e. core)

Number of threads: If a CPU core can

Physical CPU: CPU on the slot in the actual server

2. Analysis of/proc/cpuinfo

1. /proc/cpuinfo parsing

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 63
model name  : Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz         #CPU model
stepping    : 2
cpu MHz     : 2400.008
cache size  : 15360 KB                                          #CPU Level 2 Cache Size
physical id : 0                                                 #Physical CPU
siblings    : 12                                                #Number of core threads per CPU
core id     : 0                                                 #Core number
cpu cores   : 6                                                 #CPU core number
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 15
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid
bogomips    : 4800.01
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 63
model name  : Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
stepping    : 2
cpu MHz     : 2400.008
cache size  : 15360 KB
physical id : 0
siblings    : 12
core id     : 1
cpu cores   : 6
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 15
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid
bogomips    : 4800.01
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

...........

2. Analysis of Linux Physics, Core Number and Logical CPU Number
- Look at how many physical CPUs there are (a section with different physical IDS indicates how many physical CPUs there are)

cat /proc/cpuinfo | grep 'physical id' | sort | uniq

  • Viewing the Number of Cores in a CPU

    cat /proc/cpuinfo | grep "cores" | sort | uniq

  • View the number of logical CPU s

    cat /proc/cpuinfo | grep "processor" | wc -l

Note: Number of logical CPUs = Number of physical CPUs x CPU core x 2 (if hyperthreading)

  • View the number of CPU core threads

    cat /proc/cpuinfo | grep 'siblings' | sort |uniq


If the CPU model is Xeon E5 series, this series is six core, twelve threads, that is, hyperthreading (generally only one thread in a core). Suppose there are two physical CPUs. Then the number of logical CPUs is 2 x 6 x 2=24. So this machine is a 24-core machine. Determine whether hyperthreading is supported: - If "siblings" and "cpu cores" are identical, hyperthreading is not supported, or the hyperthreading is not open. - If "siblings" is twice as much as "cpu cores", then hyperthreading is supported and hyperthreading is open. - If two logical CPU s have the same "core id", then the hyperthreading is open. First example:
[root@c14a002 proc]# cat /proc/cpuinfo | grep 'physical id' | sort | uniq
physical id     : 0
physical id     : 1

[root@c14a002 proc]# cat /proc/cpuinfo | grep "cores" | sort | uniq
cpu cores       : 6

[root@c14a002 proc]# cat /proc/cpuinfo | grep "processor" | uniq | wc -l
24
In this example, there are two physical CPUs, with a single core of 6 and a logical CPU of 24. Judging from this, the CPU model supports multiple threads. ** Note: Hyperthreading is normally open by default ** Look at another example:
[root@c05a001 ~]# cat /proc/cpuinfo | grep 'physical id' | sort | uniq
physical id     : 0
physical id     : 1
[root@c05a001 ~]# 
[root@c05a001 ~]#  cat /proc/cpuinfo | grep "cores" | sort | uniq
cpu cores       : 4
[root@c05a001 ~]# 
[root@c05a001 ~]# cat /proc/cpuinfo | grep "processor" | sort | uniq
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
In this example, there are two physical CPUs, with a single core of 4 and a logical CPU of 8. It can be concluded that the CPU model does not support multi-threading. You can also search for CPU models to see if hyperthreading is supported:

cat /proc/cpuinfo | grep "name" | uniq

model name      : Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz

/proc/stat

In this file, I focused on cpu usage.

cat /proc/stat | grep 'cpu'

cpu  2491 0 3534 5376465 3597 17 654 0 0
cpu0 477 0 883 1343654 1674 2 27 0 0
cpu1 338 0 588 1344917 320 0 543 0 0
cpu2 1475 0 878 1342636 1230 15 60 0 0
cpu3 200 0 1183 1345256 373 0 22 0 0
  • The first line is the total CPU utilization. The remaining lines (cpuN) are the utilization of each processor

  • Column 1: CPU Core

  • Column 2: user, running time in user mode
  • Column 3: CPU time consumed by processes with negative nice, nice values
  • Column 4: system, running time in the core state
  • Column 5: idle,
  • Column 6: iowait
  • Column 7: irq
  • Column 8: softirq
  • Column 9: stealstolen
  • Column 10:guest

    Write a cpu usage monitoring program:
    cpu usage monitoring script

Posted by dalex on Tue, 26 Mar 2019 15:18:28 -0700