HomeAWS

Cách kiểm tra thông tin CPU trên Linux, centos

Like Tweet Pin it Share Share Email

Bài này sẽ hướng dẫn bạn cách xem thông tin chi tiết về CPU trên máy chủ vật lý, VPS hay server của bạn sử dụng OS dạng *UNIX/Linux. Không chỉ cung cấp cho bạn cái nhìn tổng quan về CPU, mình sẽ tìm kiếm thông tin khác như kiến trúc CPU, vendor_id, model, model name, số core CPU, tốc độ mỗi core… về cơ bản thì thông tin CPU đều nằm trong /proc/cpuinfo, tùy theo mỗi lệnh Linux hoặc tiện ích mà lấy kết quả output khác nhau từ file này thôi.

File /proc/cpuinfo

Xem thông tin CPU hệ thống của bạn bằng cách đọc file /proc/cpuinfo sử dụng nano hoặc cat như sau:

 #: nano /proc/cpuinfo hoặc #: cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
stepping        : 3
microcode       : 29
cpu MHz         : 3392.363
cache size      : 8192 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
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 ape$
bogomips        : 6784.72
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
stepping        : 3
microcode       : 29
cpu MHz         : 3392.363
cache size      : 8192 KB
physical id     : 0
siblings        : 8
core id         : 1
cpu cores       : 4
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
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 ape$
bogomips        : 6784.72
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
stepping        : 3

Để lấy các thông tin cụ thể hơn bạn có thể sử lệnh grep – một công cụ CLI dùng để tìm kiếm dữ liệu dạng plain-text cho mỗi dòng trùng với biểu thức chính quy đưa ra. Điều này giúp bạn lấy ra thông tin của vendor name, model name, số lượng processors, số lượng core …

# cat /proc/cpuinfo | grep 'vendor' | uniq
# cat /proc/cpuinfo | grep 'model name' | uniq
# cat /proc/cpuinfo | grep processor | wc -l
# cat /proc/cpuinfo | grep 'core id'

Lệnh lscpu – hiển thị thông tin kiến trúc CPU

Lệnh này sẽ in ra thông tin kiến trúc CPU từ sysfs và /proc/cpuinfo 

[root@dev ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 60
Model name:            Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
Stepping:              3
CPU MHz:               3392.363
BogoMIPS:              6784.72
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0-7

Lệnh cpuid – hiển thị x86 CPU

Lệnh này sẽ lấy thông tin đầy đủ về (những) CPU thu thập được từ chỉ thị CPUID và đưa ra mô hình chính xác của x86 CPU.

# sudo apt install cpuid #Debian/Ubuntu systems
# sudo yum install cpuid #RHEL/CentOS systems 
# sudo dnf install cpuid #Fedora 22+

Cách sử dụng

# cpuid

CPU 0:
   vendor_id = "GenuineIntel"
   version information (1/eax):
      processor type  = primary processor (0)
      family          = Intel Pentium Pro/II/III/Celeron/Core/Core 2/Atom, AMD Athlon/Duron, Cyrix M2, VIA C3 (6)
      model           = 0xd (13)
      stepping id     = 0x7 (7)
      extended family = 0x0 (0)
      extended model  = 0x2 (2)
      (simple synth)  = Intel Core i7-3800/3900 (Sandy Bridge-E C2) / Xeon E5-1600/2600/4600 (Sandy Bridge-E C2/M1), 32nm
   miscellaneous (1/ebx):
      process local APIC physical ID = 0x0 (0)
      cpu count                      = 0x0 (0)
      CLFLUSH line size              = 0x8 (8)
      brand index                    = 0x0 (0)
   brand id = 0x00 (0): unknown
   feature information (1/edx):
      x87 FPU on chip                        = true
      virtual-8086 mode enhancement          = true
      debugging extensions                   = true
      page size extensions                   = true
      time stamp counter                     = true
      RDMSR and WRMSR support                = true
      physical address extensions            = true
      machine check exception                = true
      CMPXCHG8B inst.                        = true
      APIC on chip                           = true
      SYSENTER and SYSEXIT                   = true
      memory type range registers            = true
      PTE global bit                         = true
      machine check architecture             = true
      conditional move/compare instruction   = true
      page attribute table                   = true
      page size extension                    = true
      processor serial number                = false
      CLFLUSH instruction                    = true
      debug store                            = false
      thermal monitor and clock ctrl         = false
      MMX Technology                         = true
      FXSAVE/FXRSTOR                         = true
      SSE extensions                         = true
      SSE2 extensions                        = true
      self snoop                             = true
      hyper-threading / multi-core supported = false
      therm. monitor                         = false
      IA64                                   = false
      pending break event                    = false

Lệnh dmidecode – Hiển thị thông tin phần cứng Linux

Công cụ dmidecode có thể lấy thông tin phần cứng trên bất kỳ OS Linux nào. Nó lấy nội dung bảng DMI (a.k.a SMBIOS) trích xuất ra định dạng mà chúng ta dễ dàng đọc. SMBIOS định nghĩa các loại DMI khác nhau, với việc tìm kiếm thông tin COU thì sử dụng option “processor” như bên dưới.

# dmidecode --type processor
# dmidecode 2.12
SMBIOS 2.7 present.

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
	Socket Designation: CPU Socket #0
	Type: Central Processor
	Family: Xeon MP
	Manufacturer: GenuineIntel
	ID: C2 06 02 00 FF FB EB BF
	Signature: Type 0, Family 6, Model 44, Stepping 2
	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 (FXSAVE and FXSTOR instructions supported)
		SSE (Streaming SIMD extensions)
		SSE2 (Streaming SIMD extensions 2)
		SS (Self-snoop)
		HTT (Multi-threading)
		TM (Thermal monitor supported)
		PBE (Pending break enabled)
	Version: Not Specified
	Voltage: 3.3 V
	External Clock: 355 MHz
	Max Speed: 2133 MHz
	Current Speed: 2133 MHz
	Status: Populated, Enabled
	Upgrade: Other
	L1 Cache Handle: Not Provided
	L2 Cache Handle: Not Provided
	L3 Cache Handle: Not Provided
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified

Công cụ Inxi – Hiển thị thông tin hệ thống Linux

Inxi là một script sử dụng CLI mạnh mẽ dành cho cả console và IRC (Internet Relay Chat). Để sử dụng bạn cần cài đặt như sau:

# sudo apt install inxi #Debian/Ubuntu systems
# sudo yum install inxi #RHEL/CentOS systems 
# sudo dnf install inxi #Fedora 22+

Để hiển thị thông tin CPU đầy đủ bao gồm mỗi tốc độ xung nhịp và tốc độ CPU tối đa (nếu có) bạn sử dụng option -C như sau:

# inxi -C
CPU(s):    2 6 core Intel Xeon E5-2620 v3s (-MT-MCP-SMP-) cache: 30720 KB
           clock speeds: max: 2399 MHz 1: 2399 MHz 2: 2399 MHz 3: 2399 MHz 4: 2399 MHz 5: 2399 MHz 6: 2399 MHz
           7: 2399 MHz 8: 2399 MHz 9: 2399 MHz 10: 2399 MHz 11: 2399 MHz 12: 2399 MHz 13: 2399 MHz 14: 2399 MHz
           15: 2399 MHz 16: 2399 MHz 17: 2399 MHz 18: 2399 MHz 19: 2399 MHz 20: 2399 MHz 21: 2399 MHz
           22: 2399 MHz 23: 2399 MHz 24: 2399 MHz

Công cụ lshw – List Hardware Configuration

lshw là công cụ đơn giản để thu thập thông tin về phần cứng của máy tính. Bạn có thể sử dụng option -C CPU để chọn lớp phần cứng CPU trong trường hợp này.

# lshw -C CPU
  *-cpu:0
       description: CPU
       product: Xeon
       vendor: Intel Corp.
       vendor_id: GenuineIntel
       physical id: 400
       bus info: cpu@0
       version: Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
       slot: CPU1
       size: 2400MHz
       capacity: 4GHz
       width: 64 bits
       clock: 3705MHz
       capabilities: x86-64 fpu fpu_exception wp 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 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 dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm cqm_llc cqm_occup_llc
       configuration: cores=6 enabledcores=6 threads=12

Sử dụng hwinfo

hwinfo được sử dụng để trích xuất thông tin phần cứng hiện tại, để hiển thị thông tin CPU ta sử dụng lệnh sau:

# hwinfo --cpu

Sử dụng nproc – hiển thị số lượng processors

Lệnh nproc để hiển thị số đơn vị processor trong máy tính của bạn, sử dụng như sau:

# nproc
24

Hy vọng bài viết hữu ích cho bạn

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *