CPU hardware information (CPU 硬件信息) - /proc/cpuinfo
This virtual file identifies the type of processor used by your system. The following is an example of the output typical of /proc/cpuinfo
.
1. processor
Find number of Virtual Processors on Linux server.
This command returns number of virtual processors on the machine.
processor - Provides each processor with an identifying number. On systems that have one processor, only a 0 is present.
系统中逻辑处理核的编号,即逻辑处理核的 id。对于单核处理器,可认为是其 CPU 编号。对于多核处理器,可认为是物理核或者使用超线程技术虚拟的逻辑处理核的 id。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
To count the number of processing units use grep with wc
.
查看逻辑处理核的个数。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep processor | wc -l
8
The number of processors shown by /proc/cpuinfo
might not be the actual number of cores on the processor. For example a processor with 2 cores and hyperthreading would be reported as a processor with 4 cores.
2. core id
To get the actual number of cores, check the core id for unique values
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "core id"
core id : 0
core id : 1
core id : 2
core id : 3
core id : 0
core id : 1
core id : 2
core id : 3
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "core id" | uniq
core id : 0
core id : 1
core id : 2
core id : 3
core id : 0
core id : 1
core id : 2
core id : 3
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "core id" | sort
core id : 0
core id : 0
core id : 1
core id : 1
core id : 2
core id : 2
core id : 3
core id : 3
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "core id" | sort | uniq
core id : 0
core id : 1
core id : 2
core id : 3
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "core id" | sort | uniq | wc -l
4
So there are 4 different core ids. This indicates that there are 4 actual cores.
3. physical id
Find number of Physical Processors on Linux server.
This command returns number of physical processors on the machine.
physical id:物理封装的处理器的 id。
查看物理封装的处理器的个数。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "physical id"
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
strong@foreverstrong:~$
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "physical id" | sort
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
physical id : 0
strong@foreverstrong:~$
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "physical id" | sort | uniq
physical id : 0
strong@foreverstrong:~$
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
1
strong@foreverstrong:~$
4. cpu cores
Find number of cores on Linux server.
This command returns number of cores on the machine.
位于相同物理封装的处理器中的内核数量。
查看每个物理处理器中 core 的个数 (即核数)。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "cpu cores"
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "cpu cores" | uniq
cpu cores : 4
strong@foreverstrong:~$
5. siblings
位于相同物理封装的处理器中的逻辑处理器的数量。
查看位于相同物理封装的处理器中的逻辑处理器的数量。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "siblings"
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "siblings" | sort
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
strong@foreverstrong:~$ cat /proc/cpuinfo | grep "siblings" | sort | uniq
siblings : 8
strong@foreverstrong:~$
6. cpu cores - siblings
如果 cpu cores 数量和 siblings 数量一致,则没有启用超线程,否则超线程被启用。
strong@foreverstrong:~$ cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings"
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
siblings : 8
cpu cores : 4
strong@foreverstrong:~$ cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings" | sort
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
siblings : 8
strong@foreverstrong:~$ cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings" | sort | uniq
cpu cores : 4
siblings : 8
strong@foreverstrong:~$
7. Important points to note
processor - 逻辑处理器的唯一标识符。
physical id - 物理封装的唯一标识符。
cpu cores - 位于相同物理封装的处理器中的内核数量 (该逻辑处理器所处物理 CPU 的物理核数)。
siblings - 位于相同物理封装的处理器中的逻辑处理器的数量 (该逻辑处理器所处物理 CPU 包含的逻辑处理器数量)。
core id - 该逻辑处理器所处物理 CPU 的物理核 id。
-
Any CPU with the same “physical id” are threads or cores in the same physical socket.
-
“physical id” and “core id” are not necessarily consecutive but they are unique. Any CPU with the same “core id” are hyperthreads in the same core. (See “ht” flag under flags section in file
/proc/cpuinfo
) -
Hyper-threading is supported if ht is present in the CPU flags and you are using an SMP kernel. Also a 64-bit processor will have lm (“long mode”) in the flags section of cpuinfo. A 32-bit processor will not.
-
具有相同 physical id 的 CPU 是同一颗 CPU 封装的线程或者 cores。
-
具有相同 core id 的 CPU 是同一个 core 的超线程。
-
如果有两个逻辑 CPU 具有相同的 core id,那么超线程是打开的。
-
每个物理 CPU 中逻辑 CPU (可能是 cores, threads 或 both) 的个数。
-
拥有相同 physical id 的所有逻辑处理器共享同一个物理插座。每个 physical id 代表一个唯一的物理封装。
-
siblings 表示位于这一物理封装上的逻辑处理器的数量。
-
每个 core id 均代表一个唯一的处理器内核。
-
如果有一个以上逻辑处理器拥有相同的 core id 和 physical id,证明一个 core 上有多个线程,则说明系统支持超线程 (HT) 技术。
-
core id 不同的逻辑处理器 physical id 相同,则说明这是一个多内核处理器。CPU cores 条目也可以表示是否支持多内核。
-
计算公式
总物理核数 = 物理 CPU 数 * 每颗物理 CPU 的核数
总逻辑核数 = 物理 CPU 数 * 每颗物理 CPU 的核数 * 超线程数