1. cpu 拓扑
Node -> Socket -> Core -> Processor
- Node :一组 CPU 。每个Node由一个或多个(物理)CPU组成,并且有独立的本地内存、I/O等资源。
- Socket:插槽。一组 CPU 的封装,一般一颗“4 核 8 线程” 代表一个 Socket。
- Core:核心。这里是 PC 机的 “4 核 8 线程” 的
4核
。 - Processor :线程。这里是 PC 机的 “4 核 8 线程” 的
8线程
。
cpu 拓扑查看
node 查看
numactl --hardware
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 20 21 22 23 24 25 26 27 28 29
node 0 size: 65410 MB
node 0 free: 314 MB
node 1 cpus: 10 11 12 13 14 15 16 17 18 19 30 31 32 33 34 35 36 37 38 39
node 1 size: 65536 MB
node 1 free: 5202 MB
node distances:
node 0 1
0: 10 21
1: 21 10
查看有几个Socket
grep 'physical id' /proc/cpuinfo | awk -F: '{print $2 | "sort -un"}'
0
1
查看每个Socket有几个Processor
grep 'physical id' /proc/cpuinfo | awk -F: '{print $2}' | sort | uniq -c
20 0
20 1
查看Socket对应那几个Processor
awk -F: '{
if ($1 ~ /processor/) {
gsub(/ /,"",$2);
p_id=$2;
} else if ($1 ~ /physical id/){
gsub(/ /,"",$2);
s_id=$2;
arr[s_id]=arr[s_id] " " p_id
}
}
END{
for (i in arr)
print arr[i];
}' /proc/cpuinfo | cut -c2-
0 1 2 3 4 5 6 7 8 9 20 21 22 23 24 25 26 27 28 29
10 11 12 13 14 15 16 17 18 19 30 31 32 33 34 35 36 37 38 39
查看Core
/proc/cpuinfo文件中的cpu cores表明一个socket中有几个cores,例如:
cat /proc/cpuinfo | grep 'core' | sort -u
core id : 0
core id : 1
core id : 10
core id : 11
core id : 12
core id : 2
core id : 3
core id : 4
core id : 8
core id : 9
cpu cores : 10
查看Processor
grep 'processor' /proc/cpuinfo | wc -l
40
信息汇总
#!/bin/bash
# Simple print cpu topology
# Author: kodango
function get_nr_processor()
{
grep '^processor' /proc/cpuinfo | wc -l
}
function get_nr_socket()
{
grep 'physical id' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}' | wc -l
}
function get_nr_siblings()
{
grep 'siblings' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}'
}
function get_nr_cores_of_socket()
{
grep 'cpu cores' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}'
}
echo '===== CPU Topology Table ====='
echo
echo '+--------------+---------+-----------+'
echo '| Processor ID | Core ID | Socket ID |'
echo '+--------------+---------+-----------+'
while read line; do
if [ -z "$line" ]; then
printf '| %-12s | %-7s | %-9s |\n' $p_id $c_id $s_id
echo '+--------------+---------+-----------+'
continue
fi
if echo "$line" | grep -q "^processor"; then
p_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
if echo "$line" | grep -q "^core id"; then
c_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
if echo "$line" | grep -q "^physical id"; then
s_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
done < /proc/cpuinfo
echo
awk -F: '{
if ($1 ~ /processor/) {
gsub(/ /,"",$2);
p_id=$2;
} else if ($1 ~ /physical id/){
gsub(/ /,"",$2);
s_id=$2;
arr[s_id]=arr[s_id] " " p_id
}
}
END{
for (i in arr)
printf "Socket %s:%s\n", i, arr[i];
}' /proc/cpuinfo
echo
echo '===== CPU Info Summary ====='
echo
nr_processor=`get_nr_processor`
echo "Logical processors: $nr_processor"
nr_socket=`get_nr_socket`
echo "Physical socket: $nr_socket"
nr_siblings=`get_nr_siblings`
echo "Siblings in one socket: $nr_siblings"
nr_cores=`get_nr_cores_of_socket`
echo "Cores in one socket: $nr_cores"
let nr_cores*=nr_socket
echo "Cores in total: $nr_cores"
if [ "$nr_cores" = "$nr_processor" ]; then
echo "Hyper-Threading: off"
else
echo "Hyper-Threading: on"
fi
echo
echo '===== END ====='
汇总结果:
===== CPU Topology Table =====
+--------------+---------+-----------+
| Processor ID | Core ID | Socket ID |
+--------------+---------+-----------+
| 0 | 0 | 0 |
+--------------+---------+-----------+
| 1 | 1 | 0 |
+--------------+---------+-----------+
| 2 | 2 | 0 |
+--------------+---------+-----------+
| 3 | 3 | 0 |
+--------------+---------+-----------+
| 4 | 4 | 0 |
+--------------+---------+-----------+
| 5 | 8 | 0 |
+--------------+---------+-----------+
| 6 | 9 | 0 |
+--------------+---------+-----------+
| 7 | 10 | 0 |
+--------------+---------+-----------+
| 8 | 11 | 0 |
+--------------+---------+-----------+
| 9 | 12 | 0 |
+--------------+---------+-----------+
| 10 | 0 | 1 |
+--------------+---------+-----------+
| 11 | 1 | 1 |
+--------------+---------+-----------+
| 12 | 2 | 1 |
+--------------+---------+-----------+
| 13 | 3 | 1 |
+--------------+---------+-----------+
| 14 | 4 | 1 |
+--------------+---------+-----------+
| 15 | 8 | 1 |
+--------------+---------+-----------+
| 16 | 9 | 1 |
+--------------+---------+-----------+
| 17 | 10 | 1 |
+--------------+---------+-----------+
| 18 | 11 | 1 |
+--------------+---------+-----------+
| 19 | 12 | 1 |
+--------------+---------+-----------+
| 20 | 0 | 0 |
+--------------+---------+-----------+
| 21 | 1 | 0 |
+--------------+---------+-----------+
| 22 | 2 | 0 |
+--------------+---------+-----------+
| 23 | 3 | 0 |
+--------------+---------+-----------+
| 24 | 4 | 0 |
+--------------+---------+-----------+
| 25 | 8 | 0 |
+--------------+---------+-----------+
| 26 | 9 | 0 |
+--------------+---------+-----------+
| 27 | 10 | 0 |
+--------------+---------+-----------+
| 28 | 11 | 0 |
+--------------+---------+-----------+
| 29 | 12 | 0 |
+--------------+---------+-----------+
| 30 | 0 | 1 |
+--------------+---------+-----------+
| 31 | 1 | 1 |
+--------------+---------+-----------+
| 32 | 2 | 1 |
+--------------+---------+-----------+
| 33 | 3 | 1 |
+--------------+---------+-----------+
| 34 | 4 | 1 |
+--------------+---------+-----------+
| 35 | 8 | 1 |
+--------------+---------+-----------+
| 36 | 9 | 1 |
+--------------+---------+-----------+
| 37 | 10 | 1 |
+--------------+---------+-----------+
| 38 | 11 | 1 |
+--------------+---------+-----------+
| 39 | 12 | 1 |
+--------------+---------+-----------+
Socket 0: 0 1 2 3 4 5 6 7 8 9 20 21 22 23 24 25 26 27 28 29
Socket 1: 10 11 12 13 14 15 16 17 18 19 30 31 32 33 34 35 36 37 38 39
===== CPU Info Summary =====
Logical processors: 40
Physical socket: 2
Siblings in one socket: 20
Cores in one socket: 10
Cores in total: 20
Hyper-Threading: on