How to Check How Many CPUs, Cores, and Threads a Linux Virtual Machine Has

ARTIFICIAL INTELLIGENCE

In this article, I will share some methods that may be useful if you want to identify or verify the physical/virtual resources of a Linux machine.

One way to obtain system information is through analyzing the system logs during boot, which can be done by running the command:

# dmesg

For example, by running the following command:

# dmesg | grep CPU

you can retrieve information related to the CPU, for example, in my case, the output is something like this:

[    0.000000] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.000000] setup_percpu: NR_CPUS:5120 nr_cpumask_bits:8 nr_cpu_ids:8 nr_node_ids:1
[    0.000000] PERCPU: Embedded 38 pages/cpu @ffff88127fc00000 s118784 r8192 d28672 u262144
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.000000] RCU restricting CPUs from NR_CPUS=5120 to nr_cpu_ids=8.
[    0.442795] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.444051] MDS: Mitigation: Clear CPU buffers
[    0.502490] smpboot: CPU0: Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz (fam: 06, model: 4f, stepping: 01)
[    0.504954] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.506320] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.507649] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.509178] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.510535] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.511800] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.513260] x86/cpu: Activated the Intel User Mode Instruction Prevention (UMIP) CPU feature
[    0.514228] Brought up 8 CPUs

from which you can see the type of CPU, the number of cores, the processor speed, and other useful information.

A second method is to use the command:

# lscpu

which results in something like this:

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:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
Stepping:              1
CPU MHz:               2199.998
BogoMIPS:              4399.99
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:            32K
L2 cache:              4096K
L3 cache:              16384K
NUMA node0 CPU(s):     0-7
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 rep_good nopl xtopology eagerfpu 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 ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid r
tm rdseed adx smap xsaveopt arat umip md_clear spec_ctrl intel_stibp arch_capabilities

or you can check the architecture directly by reading the proc files:

As with the `dmesg` command, you can filter the output to get the most relevant information by running the following command:

# cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l

This will allow you to retrieve information about the physical cores present on the system.

Another useful command is:

# dmidecode

dmidecode is a tool that retrieves the content of a computer’s DMI table in a human-readable format. The DMI table contains a description of the system’s hardware components, as well as other useful information like serial numbers and BIOS revision.

Se vuoi farmi qualche richiesta o contattarmi per un aiuto riempi il seguente form

    Comments