A deep dive into /proc/cpuinfo
Background knowledge
/proc/cpuinfo is a read only file, which shows each logic CPU with a unique processor number. A logical CPU can be a hyperthreading sibling, a shared core in multi-core, or a separate physical CPU. We can use the following command line to display the detail information:
cat /proc/cpuinfo
- CPU performs basic arithmetic, logic, controlling and input/output operation specified by the instructions. principal components of a CPU include:
- ALU(arithmetic logic unit): perform arithmetic and logic operations
- registers: supply operands to the ALU and stores the results of ALU operations
- control unit: orchestrate the fetching from memory and the execution of instructions by directing the coordinated operations of the ALU, registers and other components.
logic CPU is the CPU can be seen by the operating system, but it does not exist physically. For example, in the following graph, even this CPU/processor only has four cores, since each core supports two thread running simultaneously, the operating system just treats it as 8-logic-CPU.
-
Processor is PART of the CPU, more specifically, the processing unit and control unit of the CPU. But generally, when can use processor and CPU interchangeably.
-
As the picture shown above, one CPU core can support running multiple threads simultaneously, which tricks the operating system into seeing two CPUs for each actual core. Hyper-threading allows the two logical CPU cores to shared physical execution resources.
-
Core is the basic computation unit of the CPU, A CPU may have one or more cores. A single core runs a single program context, maintaining the correct program state, registers and correct execution order, and performs the operations through ALUs.
To further distinguish between CPU and core, core is one function unit on CPU, CPU includes more components than cores. For example, CPU contains interconnect that connects the cores to the outside world, and usually also a large “last-level” shared cache, also, CPU needs a memory controller to talk to the memory, I/O controller, etc.,
- CPUs sharing cache will be called siblings.
- Modern CPU can contain multiple cores, modern system can contains multiple CPUs, which is called multi-core-multi-processor system. CPUs are installed on CPU sockets( a socket is a slot where the physical CPU capsules are placed. )
- Each core on a CPU has its own L1 data cache and instruction cache, and a unified L2 cache. Cores on the same CPU share the same L3 cache.
- Considering a multi-core-multi-processor system with 2 sockets ( which means can install one CPU into each socket ), each sockets having 24 cores with hyper threading. In this case operating system will see total 96 (logical) CPUs numbered from 0 to 95. Socket 1 will have CPUs 0-47 and socket 2 will have CPUs 47-95, then CPUs 0-47 are sibling, CPUs 47-95 are sibling.
examples to understand the /proc/cpuinfo
common arguments:
- processor: the unique ID for each logical CPU/processor
- model name: common name of the physical processor
- cache size: the amount of L2 cache available to each logical CPU/processor
- physical id: the ID of the physically existing processor
- core id: the ID of the physically existing core
- cpu cores: the number of physically existing cores
example1: single processor, 1 core, no hyperthreading
In this example, because there is only one processor and one core, there is no core id, siblings, physical id, etc.,
example2: single processor, 1 core, hyperthreading is enabled
In this example, because we have hyperthreading enabled, so operating will see two logical CPUs, and given each logical CPU a unique processor ID (as shown in the picture, which is 0 and 1, respectively.)
But because they belong to the same physical processor, so the physical ids are both 0.
The two logical CPUs share the cache, so the sibling number is 2.
The L2 cache for each core is 1024KB (shared by the two hyperthreads).
The only one core is labeled with 0.
The number of cores is 1.
example3: single socket quad core, hyperthreading disabled
In this example, we can see that we have 4 logical CPUs (since hyperthreading is disabled, each core represents a CPU). So we have processors numbered from 0 to 3.
They all belong to a physical processor, so the physical id is 0.
Each core has L2 cache of size 6144 KB.
The four cores shared the L3 cache, so sibling is 4.
Each core is labeled with a unique core id too, numbered from 0 to 3.
There are 4 cpu cores.
example4: Dual single core, hyperthreading enabled
In this example, the cores are located on separate processors. That is, we have two CPUs, and each CPU contains one core, each core is enabled with hyper threads.
So we have 2*2 = 4 logical CPU/processors.
The two CPUs are labeled with unique physical ID 0 and 3 (can also be labeled with 0 and 1).
Because cores on different CPU do not share the same L3 cache, so for each CPU, the number of sibling is 2 (the number of logical CPUs).
Because there is only one core on each CPU, so on their own CPU, the core id is 0.
Every CPU has one core, so cpu cores is 1.