CPU-related concepts: physical cpu number, core number, logical cpu number, 12-core 20-thread instance analysis

0. The reason for writing this blog

  • When learning multithreading, you need to understand the concepts of CPU and threads, but the concepts given on the Internet confuse me in actual operation.
  • The difference between this article and other articles is that it explains why the number of logical CPUs is not twice the number of cores (this is the case with newer processors), and can answer the questions of non-computer professionals.

For the query method of CPU information, please refer to the second part of this article

Draw key points:

大核支持超线程,小核不支持超线程,同时含有大小核的处理器不能简单地用核数乘2得到逻辑CPU的个数!!!

See 1.2 and 1.3 for the analysis process

1. Physical CPU, core, logical CPU concept

The number of cores and threads of a CPU depends on the specific make, model, and generation.
Both numbers continue to increase for both AMD and Intel chips, with newer CPUs typically having more physical cores than older CPUs.

The concept of CPU is relatively easy to confuse, and the CPU visible to the macroscopic naked eye can also be called a processor .

  • Processor
    • The physical chip installed on the motherboard socket (Socket), usually also called CPU
  • CPU core (Core)
    • It is a physical element (that is, a visible and palpable entity) located inside the processor (Processor) to handle complex computing tasks. The number of chipsets that can be calculated on a single CPU, such as dual-core, quad-core, etc.
  • CPU thread (Thread)
    • It is a virtual component (that is, at the logical level, only visible to the operating system), also known as a logical core (logical processor) (logical CPU) , which represents the number of threads that your CPU core can support, helping the CPU to process more efficiently Task. If the core supports hyper-threading technology, one core can function as two cores. Each thread runs as an independent CPU instance.

1.1 How the kernel works

The following diagram shows how the kernel works:
insert image description here

1.2 Hyperthreading

We all know that the processor (Processor) is the brain of the entire system. The more cores and threads, the better the CPU performance, because multiple tasks can be organized and processed faster and simultaneously.
Hyper-threading (Hyper-threading) is a technology proposed by Intel to "trick" the operating system into thinking that there are additional cores.
So if your processor is quad-core and supports hyper-threading, your OS will think there are: 1 CPU, 4 physical cores, 8 logical cores.
If hyperthreading is not supported, then it is: 1 CPU, 4 physical cores, 4 logical cores. See the figure below for details:
insert image description here

Note that not all CPUs have two threads per core, and some CPUs have P cores and E cores, which means that some cores support hyperthreading, while others do not.

therefore! ! !

The following formula isNot rigorous, there is no way to explainlarge and small nucleiIn the case of large and small cores, I will introduce them in the following chapters:

The total number of cores = the number of physical CPUs × the number of cores of each physical CPU.
The total number of logical CPUs = the number of physical CPUs × the number of cores of each physical CPU × the number of hyperthreads

1.3 What are big and small kernels

Although previous Intel desktop CPUs have been branded with multiple cores, they are similar in many ways.
However, with the introduction of the 12th Generation Intel Alder Lake CPUs , the processor has a new feature, that is, it has two cores at the same time: Performance Cores + Efficient Cores, referred to as P cores and E cores. , which is the big (P) small (E) core mentioned on the Chinese website .

The advent of the Alder Lake CPU means that we have to get used to using new methods or indicators to distinguish processors. The previous 12-core processor means that it has 12 cores, and for the 12th Gen Intel CPU, these 12 cores may have (8+4) or 8P+4E or 8C4c (C, big core, c, small core) such annotations.
The P core provides hyperthreading, so each P core has 2 threads, and the E core only supports single thread.

And my computer configuration is: 1 physical CPU, 12 cores (8 + 4), 20 logical CPUs
that is

Total number of cores = Number of physical CPUs x (Number of P cores per physical CPU + Number of E cores per physical CPU) 12
= 1 x (8 + 4)
Total number of logical CPUs = Number of physical CPUs x (Number of each physical CPU The number of P cores of the physical CPU x 2 + the number of E cores of each physical CPU x 1)
20 = 1 x (8 x 2 + 4 x 1)

2. How to query CPU information

2.1 Method of querying CPU information under Windows

Under Windows, open the task manager, select Performance —> select CPU, and you can see the CPU information. The CPU shown in the figure below is Intel Core i7-4790, which has 4 physical cores and 8 logical processors. , indicating that the CPU supports Intel's Hyper-Threading Technology.
insert image description here

2.2 How to query CPU information under Linux

Method 1: lscpu overall view

Order:

lscpu

My result is as shown below, 1 physical CPU, 12 cores, 20 logical CPUs
insert image description here

Method 2: View separately

Reference: [cpu concept] the concept of the number of physical cpus, the number of cores, and the number of logical cpus

View the number of physical CPUs:

cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l

Check how many cores the CPU has:

cat /proc/cpuinfo |grep "cores"|uniq

View the number of logical CPUs:

cat /proc/cpuinfo |grep "processor"|wc -l

3. Reference

参考链接:
How Many CPU Cores & Threads Do You have? [How To Check]
P-Cores vs E-Cores & Intel’s New CPUs

Guess you like

Origin blog.csdn.net/weixin_45910027/article/details/130526456