1. 可以从 /proc/cpuinfo 中获取CPU的一些信息

[root@xyy8 dev]# cat /proc/cpuinfo      

processor       : 0                     -- 逻辑CPU id

vendor_id       : GenuineIntel

cpu family      : 6

model           : 26

model name      : Intel(R) Xeon(R) CPU           E5504 @ 2.00GHz

stepping        : 5

cpu MHz         : 1995.000

cache size      : 4096 KB

physical id     : 16                       -- 物理CPU id

siblings        : 1

core id         : 255

cpu cores       : 1

fpu             : yes

fpu_exception   : yes

cpuid level     : 11

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm pni monitor ds_cpl est tm2 cx16 xtpr popcnt lahf_lm

bogomips        : 3993.24

clflush size    : 64

cache_alignment : 64

address sizes   : 40 bits physical, 48 bits virtual

power management:


processor       : 1

vendor_id       : GenuineIntel

cpu family      : 6

model           : 26

model name      : Intel(R) Xeon(R) CPU           E5504 @ 2.00GHz

stepping        : 5

cpu MHz         : 1596.000

cache size      : 4096 KB

physical id     : 0

siblings        : 1

core id         : 255

cpu cores       : 1

fpu             : yes

fpu_exception   : yes

cpuid level     : 11

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm pni monitor ds_cpl est tm2 cx16 xtpr popcnt lahf_lm

bogomips        : 3990.05

clflush size    : 64

cache_alignment : 64

address sizes   : 40 bits physical, 48 bits virtual

power management:

……


2. 获取物理CPU个数

[root@xyy8 dev]# cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

8


3. 获取逻辑CPU个数

[root@xyy8 dev]# cat /proc/cpuinfo | grep "processor" | wc -l


4. 每个物理CPU中Core的个数:每个相同的physical id都有其对应的core id。如core id分别为1、2、3、4,则表示是Quad-Core CPU,若core id分别是1、2,则表示是Dual-Core。

[root@xyy8 dev]# cat /proc/cpuinfo | grep "cpu cores" | wc -l

8


5. 每个物理CPU中逻辑CPU(可能是core, threads或both)的个数:


  # cat /proc/cpuinfo | grep "siblings"


它既可能是cores的个数,也可能是core的倍数。当它和core的个数相等时,表示每一个core就是一个逻辑CPU,若它是core的2倍时,表示每个core又enable了超线程(Hyper-Thread)。

比如:一个双核的启用了超线程的物理cpu,其core id分别为1、2,但是sibling是4,也就是如果有两个逻辑CPU具有相同的"core id",那么超线程是打开的。


综上所述:实际我们所说的双核,四核是看物理cpu的个数。


dmesg | grep -i 'cpu' 测试过多台机器,发现有的不出结果。


也可参考:

http://linux.chinaunix.net/techdoc/system/2009/11/28/1146668.shtml



2010-01-08