Know the CPU

# Total number of cores = number of physical CPUs X number of cores per physical CPU
# Total number of logical CPUs = number of physical CPUs X number of cores per physical CPU X number of hyperthreads

How to determine whether to enable
        Hyper-Threading (Hyper-Threading, "HT") technology. Hyper-threading technology uses special hardware instructions to simulate two logical cores into two physical chips, so that a single processor can use thread-level parallel computing, which is compatible with multi-threaded operating systems and software, and reduces the idle time of the CPU. Improved CPU operating efficiency.
        Hyper-threading technology is to execute multiple programs on one CPU at the same time and share the resources in one CPU. In theory, it needs to execute two threads at the same time like two CPUs. Although using hyper-threading technology can execute two threads at the same time , But it is not like two real CPUs, each CPU has independent resources. When two threads both need a certain resource at the same time, one of them should be temporarily stopped and the resources should be surrendered until these resources are idle. Therefore, the performance of hyperthreading is not equal to the performance of two CPUs.

How to check how many processors are there and whether they are multi-core? Is it hyperthreading?


The CPU status can be queried by the following methods:
1. The number of logical CPUs:
grep -c processor /proc/cpuinfo
2. The number of physical CPUs:
grep'physical id' /proc/cpuinfo |sort -u|wc -l


"Siblings" refers to a physical CPU has several logical CPUs
grep'siblings' /proc/cpuinf


"Cpu cores" refers to how many cores a physical CPU has
grep'cpu cores' /proc/cpuinfo


If "siblings" and "cpu cores" are the same, it means that hyperthreading is not supported or hyperthreading is not enabled.
If "siblings" is twice the "cpu cores", it means that hyperthreading is supported and hyperthreading is turned on.
#Under normal circumstances, multi-core hyperthreading, each core has two logical processing units, two threads share the resources of one core

Is it hyperthreading?
If there are two logical CPUs with the same "core id", then hyperthreading is turned on.


View of cpu core processor in Linux server


$ grep -E 'processor|core id' /proc/cpuinfo
processor    : 0
core id        : 0
processor    : 1
core id        : 0
processor    : 2
core id        : 1
processor    : 3
core id        : 1
processor    : 4
core id        : 2
processor    : 5
core id        : 2
processor    : 6
core id        : 3
processor    : 7
core id        : 3
processor    : 8
core id        : 4
processor    : 9
core id        : 4
processor    : 10
core id        : 5
processor    : 11
core id        : 5
processor    : 12
core id        : 6
processor    : 13
core id        : 6
processor    : 14
core id        : 7
processor    : 15
core id        : 7
processor    : 16
core id        : 8
processor    : 17
core id        : 8
processor    : 18
core id        : 9
processor    : 19
core id        : 9
processor    : 20
core id        : 10
processor    : 21
core id        : 10
processor    : 22
core id        : 11
processor    : 23
core id        : 11

You can see through the above command

The core id is repeated, indicating that hyperthreading is enabled.


The latter uses the command
dmidecode
to obtain information about the hardware under the Linux system
dmidecode -t 4 | grep -E'Socket Designation|Count'
    Socket Designation: CPU 0
    Core Count: 12
    Thread Count: 2
#It can be concluded that there is a physical CPU (the socket of the CPU is identified as CPU 0). This physical CPU has 12 cores, and each core has 2 hyperthreads.
Or:
$ lscpu | grep -E'^Thread|^Core|^Socket|^CPU\('
CPU(s): 24
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 1

You can get:
CPU(s) is the number of hyperthreads
Socket(s) is the number of physical CPUs
Core(s) per socket: each physical cpu has 12 cores
Thread(s) per core: each core has 2 hyperthreads

Guess you like

Origin blog.csdn.net/Doudou_Mylove/article/details/107757260