【转载】如何用Linux的命令正确识别cpu的个数和核数

如何在Linux下cpu的个数和核数呢?googel了一下,网上总结的很多办法都是错的或者混淆视听,没办法,靠自己了。 
判断依据: 
1.具有相同core id的cpu是同一个core的超线程。 
2.具有相同physical id的cpu是同一颗cpu封装的线程或者cores。 
英文版: 
1.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. 
2.Any cpu with the same physical id are threads or cores in the same physical socket. 
以自己的惠普DL380G6为例说明: 
①物理cpu个数: 
[root@localhost ~]# cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l 

②每个物理cpu中core的个数(即核数) 
[root@localhost ~]# cat /proc/cpuinfo | grep "cpu cores" | uniq 
cpu cores : 4 
③每个物理cpu中逻辑cpu(可能是core、threads或both)的个数 
[root@localhost ~]# cat /proc/cpuinfo | grep "siblings" | uniq 
siblings : 8 
# cat /proc/cpuinfo | grep "core" 
core id : 0 
cpu cores : 4 
core id : 0 
cpu cores : 4 
core id : 2 
cpu cores : 4 
core id : 2 
cpu cores : 4 
core id : 1 
cpu cores : 4 
core id : 1 
cpu cores : 4 
core id : 3 
cpu cores : 4 
core id : 3 
cpu cores : 4 
core id : 0 
cpu cores : 4 
core id : 0 
cpu cores : 4 
core id : 2 
cpu cores : 4 
core id : 2 
cpu cores : 4 
core id : 1 
cpu cores : 4 
core id : 1 
cpu cores : 4 
core id : 3 
cpu cores : 4 
core id : 3 
cpu cores : 4 
※这款服务器的cpu蛮强悍的,难怪在许多linux命令中,如iostat中显示有16个cpu之多,这里也请大家注意区分物理cpu和逻辑cpu的区别,不要混淆了。最后能过查询服务器清单发现此款服务器用的cpu是英特尔至强[email protected],四核(Gainestown),二级缓存8MB,正好通过结果验证以上命令

猜你喜欢

转载自lobert.iteye.com/blog/1927468