Understand physical CPU and logical CPU

This is a shorthand article about the actual meaning of physical and logical CPUs and the differences between them.

First of all, the term CPU is used very vaguely and imprecisely on the Internet. It is often used to refer to processors, cores, or hardware threads. But generally speaking, Cores is a more accurate corresponding name for CPU.

Let us first look at a few terms:

  • Processor is a physical chip mounted on the system socket, which contains one or more CPUs used to implement Cores or Hardware Thread.
  • Core is an independent CPU instance located on a multi-core processor. Using the core to extend the processor is called chip-level multiprocessing.
  • Hardware Thread is a CPU architecture that supports simultaneous execution of multiple threads on each core, and each thread runs as an independent CPU instance. This extension method is called multithreading.
    Insert picture description here
    Now that we know the required terminology, physical CPU means the actual physical core on the processor. Whether the multi-threading of the core is enabled does not affect the number of physical CPUs on the processor. In short, the physical CPU corresponds to the actual physical cores (Cores) on the processor. The single processor shown in the figure above has 4 physical cores.
    Logical CPU refers to the ability of each core to do 2 or more tasks at the same time. This is achieved by enabling hyperthreading on the core. Each physical core can be divided into multiple logical cores by enabling hyperthreading. In the above figure, although there are only 4 physical cores, by enabling hyperthreading on each core, the system will treat them as 8 logical CPUs.

The above figure corresponds to the following detailed description:

1 processor (Processor), 4 physical cores (Cores), 8 logical cores. In other words-1P4C-each core has 2 threads.

You can use the following command to check these details in the system: lscpuInsert picture description here
Below is the relevant information I got from the above output [1P2C-2 threads per core, 4 logical CPUs].
CPU socket(s): 1 --> 1 processor
Core(s) per socket: 2 --> 2 cores (total 2)
Thread(s) per core: 2 --> dual-threaded
CPU(s) ): 4 --> A total of 4 logical CPUs
4 Logical CPUs is arrived by --> 2 Cores X 2 Threaded
For clarity, let’s give another example:

Insert picture description here
Here is the above output : [2P8C - with 2 threads per core, 16 Logical CPUs]
Sockets : 2 --> 2 processors
Cores per socket : 4 --> 4 Cores per processor (2X4=8Total cores)
Threads per core : 2 --> 2 Threaded
CPUs : 16 – > 16 Logical CPUs
16 Logical CPUs is arrived by – > 2 Processors X 4 Cores/processor X 2 Threads/core

I hope to help you!

Recommend your own Linux, C/C++ technology exchange group: [960994558] I have compiled some good learning books, interview questions from big companies, and popular technology teaching video materials to share in it (including C/C++, Linux, Nginx, ZeroMQ, MySQL, Redis, fastdfs, MongoDB, ZK, streaming media, CDN, P2P, K8S, Docker, TCP/IP, coroutine, DPDK, etc.), you can add it yourself if you need it! ~
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_52622200/article/details/113867101