SoFunction
Updated on 2025-03-10

Shell realizes the identification of the number of physical CPUs and core numbers

How to identify the number of physical CPUs, how many cores, is it hyperthreaded or multi-core

Judgment basis:

1. The cpu with the same core id is a hyperthread of the same core.
2. CPUs with the same physical id are threads or cores encapsulated by the same CPU.

English version:

id and core id are not necessarily consecutive but they are unique. Any cpu with the same core id are hyperthreads in the same core.
cpu with the same physical id are threads or cores in the same physical socket.

Example:

LunarPages CPU information:

Copy the codeThe code is as follows:

processor        : 0
vendor_id        : GenuineIntel
cpu family        : 15
model                : 4
model name        : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz                : 3000.881
cache size        : 2048 KB
physical id        : 0
siblings        : 2
core id                : 0
cpu cores        : 1
fdiv_bug        : no
hlt_bug                : no
f00f_bug        : no
coma_bug        : no
fpu                : yes
fpu_exception        : yes
cpuid level        : 5
wp                : yes
flags                : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips        : 6006.73
processor        : 1
vendor_id        : GenuineIntel
cpu family        : 15
model                : 4
model name        : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz                : 3000.881
cache size        : 2048 KB
physical id        : 0
siblings        : 2
core id                : 0
cpu cores        : 1
fdiv_bug        : no
hlt_bug                : no
f00f_bug        : no
coma_bug        : no
fpu                : yes
fpu_exception        : yes
cpuid level        : 5
wp                : yes
flags                : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips        : 5999.40
processor        : 2
vendor_id        : GenuineIntel
cpu family        : 15
model                : 4
model name        : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz                : 3000.881
cache size        : 2048 KB
physical id        : 3
siblings        : 2
core id                : 3
cpu cores        : 1
fdiv_bug        : no
hlt_bug                : no
f00f_bug        : no
coma_bug        : no
fpu                : yes
fpu_exception        : yes
cpuid level        : 5
wp                : yes
flags                : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips        : 5999.08
processor        : 3
vendor_id        : GenuineIntel
cpu family        : 15
model                : 4
model name        : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz                : 3000.881
cache size        : 2048 KB
physical id        : 3
siblings        : 2
core id                : 3
cpu cores        : 1
fdiv_bug        : no
hlt_bug                : no
f00f_bug        : no
coma_bug        : no
fpu                : yes
fpu_exception        : yes
cpuid level        : 5
wp                : yes
flags                : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips        : 5999.55

Displays 4 logical CPUs. Through physical id  , the first two logical CPUs are the same, and the last two are the same, so there are two physical CPUs. The core ids of the first two are the same, and the core ids of the last two are the same, which means that both CPUs are single-core. That is to say, two single-core CPUs have enabled hyperthreading technology.

It can be preliminarily judged through the parameters of Intel's CPU that are used are two Xeon Pentium 4 CPUs, which is a bit bad. . . .

How to get CPU details:

linux command: cat /proc/cpuinfo

Use commands to determine how many physical CPUs, how many cores, etc.
Number of logical CPUs:

Copy the codeThe code is as follows:

# cat /proc/cpuinfo | grep “processor” | wc -l

Number of physical CPUs:
Copy the codeThe code is as follows:

# cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l

Number of Cores in each physical CPU:
Copy the codeThe code is as follows:

# cat /proc/cpuinfo | grep “cpu cores” | wc -l

Is it a hyperthreading?

If there are two logical CPUs with the same "core id", then the hyperthread is open.
The number of logical CPUs (maybe core, threads or both) in each physical CPU:

Copy the codeThe code is as follows:

# cat /proc/cpuinfo | grep “siblings”

Other features:

Currently, Intel's new multi-core CPU will display specific model numbers at the back, for example:

Copy the codeThe code is as follows:

model name        : Intel(R) Xeon(R) CPU           X3230  @ 2.66GHz

The instructions are Xeon 3230 CPUs, and the specific numbers of the model are mostly Pentium CPUs.
Many host manufacturers are cheating people, using Pentium CPUs, but they are said to be multi-core CPUs.

Data seen by the probe:

Type: Intel(R) Xeon(TM) CPU 2.80GHz Cache: 1024 KB
Type: Intel(R) Xeon(TM) CPU 2.80GHz Cache: 1024 KB
Type: Intel(R) Xeon(TM) CPU 2.80GHz Cache: 1024 KB
Type: Intel(R) Xeon(TM) CPU 2.80GHz Cache: 1024 KB

There is no specific model, and the cache is 1M. It is generally a Pentium series CPU or an Intel fake dual-core CPU. The specific one needs to be judged based on what is mentioned above. The new multi-core CPU can be seen in specific models.

In addition, the multi-core xeon CPUs generally have low main frequency, and only a few high-end CPU models reaching 2.8 and 3.0. Generally, host manufacturers will not use such a good one.