A deep dive into /proc/cpuinfo

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

  1. 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. logic CPU

  1. 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.

  2. 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.

  3. 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.,

  1. CPUs sharing cache will be called siblings.
  1. 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. )
  2. 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.cache
  3. 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:

  1. processor: the unique ID for each logical CPU/processor
  2. model name: common name of the physical processor
  3. cache size: the amount of L2 cache available to each logical CPU/processor
  4. physical id: the ID of the physically existing processor
  5. core id: the ID of the physically existing core
  6. cpu cores: the number of physically existing cores

example1: single processor, 1 core, no hyperthreading

ex1
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

ex2
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

ex3.1ex3.2
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

ex4.1
ex4.2
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值