Linux checks whether the server has hyperthreading enabled

1. Hyper-threading concept
"Hyper-Threading (Hyper-Threading, referred to as "HT")" technology. Hyper-threading technology is to use 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, reducing CPU idle time. 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, two threads should be executed at the same time like two CPUs. , 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 temporarily stop and give up the resource until these resources are idle before continuing. Therefore, the performance of hyperthreading is not equal to the performance of two CPUs.

2. Check whether hyperthreading is enabled

To determine whether hyperthreading is enabled, you need to confirm whether the total number of cores is the same as the total number of logical cores.
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

Method 1: Use the lscpu command to view the status of the CPU. The threads per core value is 2 in the hyperthreading state, and 1 when it is disabled.
              The threads per core indicates how many threads each core has.

Method 2: cat /proc/cpuinfo to view cpu information, the method is as follows.

CPU physical number: cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
                        or grep 'physical id' /proc/cpuinfo |sort -u|wc -l

Number of logical CPUs: cat /proc/cpuinfo| grep processor|sort|uniq|wc -l
                        or grep -c processor /proc/cpuinfo

Number of siblings: grep "siblings" /proc/cpuinfo|uniq

Number of cpu cores: grep "cpu cores" /proc/cpuinfo|uniq

* The processor entry contains a unique identifier for this logical processor.
* The physical id entry contains a unique identifier for each physical package.
* The core id entry holds a unique identifier for each core.
* The siblings entry lists the number of logical processors that reside in the same physical package.
* The cpu cores entry contains the number of cores residing in the same physical package.
* If the processor is an Intel processor, the string in the vendor id entry is GenuineIntel

If "siblings" and "cpu cores" match, hyperthreading is not supported, or hyperthreading is not turned on. If "siblings" is twice as many as "cpu cores", then hyperthreading is supported and hyperthreading is turned on. If there are two logical CPUs with the same "core id", then hyperthreading is on.

Guess you like

Origin blog.csdn.net/qq_34474071/article/details/123903839