查看服务器物理CPU数和CPU核数的原理比较简单,检查/proc/cpuinfo文件即可。
例如,我的cpu信息:
# cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 5
model name : AMD Athlon(tm) II X4 640 Processor
stepping: 3
cpu MHz : 3480.119
cache size : 512 KB
physical id : 0
siblings: 4
core id : 0
cpu cores : 4
apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow constant_tsc nonstop_tsc pni cx16 popcnt lahf_lm extapic altmovcr8 abm sse4a misalignsse
bogomips: 6960.23
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate [8]
processor : 1
vendor_id : AuthenticAMD
cpu family : 16
model : 5
model name : AMD Athlon(tm) II X4 640 Processor
stepping: 3
cpu MHz : 3480.119
cache size : 512 KB
physical id : 0
siblings: 4
core id : 1
cpu cores : 4
apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow constant_tsc nonstop_tsc pni cx16 popcnt lahf_lm extapic altmovcr8 abm sse4a misalignsse
bogomips: 6969.48
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate [8]
processor : 2
vendor_id : AuthenticAMD
cpu family : 16
model : 5
model name : AMD Athlon(tm) II X4 640 Processor
stepping: 3
cpu MHz : 3480.119
cache size : 512 KB
physical id : 0
siblings: 4
core id : 2
cpu cores : 4
apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow constant_tsc nonstop_tsc pni cx16 popcnt lahf_lm extapic altmovcr8 abm sse4a misalignsse
bogomips: 6973.84
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate [8]
processor : 3
vendor_id : AuthenticAMD
cpu family : 16
model : 5
model name : AMD Athlon(tm) II X4 640 Processor
stepping: 3
cpu MHz : 3480.119
cache size : 512 KB
physical id : 0
siblings: 4
core id : 3
cpu cores : 4
apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow constant_tsc nonstop_tsc pni cx16 popcnt lahf_lm extapic altmovcr8 abm sse4a misalignsse
bogomips: 6967.36
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate [8]
其中:
processor行表示的CPU核的ID,该行的总数便是CPU核数
physical id行表示的则是物理CPU的ID,该行的ID号有哪几种,便有几颗物理CPU
如果是批量查询可以这样做:
# cat /proc/cpuinfo |grep '^physical'|sort |uniq
physical id : 0
# cat /proc/cpuinfo |grep processor
processor : 0
processor : 1
processor : 2
processor : 3