Distinguish real vs. virtual CPUs?
Is there a canonical way for user-space software to determine how many real CPUs are present in a system (as opposed to HyperThreaded or otherwise virtual CPUs)?
We have an application that for performance reasons wants to run one process per CPU. However, on a HyperThreaded system /proc/cpuinfo lists two CPUs, and running two processes in this case is the wrong thing to do. (Hyperthreading ends up degrading our performance, perhaps due to cache or bus contention).
Please CC replies.
Thanks,
Dan Maas
Quoted 9 lines · Dan Maas
Is there a canonical way for user-space software to determine how many real CPUs are present in a system (as opposed to HyperThreaded or otherwise virtual CPUs)?
We have an application that for performance reasons wants to run one process per CPU. However, on a HyperThreaded system
/proc/cpuinfolists two CPUs, and running two processes in this case is the wrong thing to do. (Hyperthreading ends up degrading our performance, perhaps due to cache or bus contention).
Compare the 'physical id' fields of /proc/cpuinfo, and count how many unique values you get.
Ie, on my dual+ht, I see..
physical id : 0
physical id : 0
physical id : 3
physical id : 3
Which indicates 2 real CPUs split in two.
Dave
Quoted 10 lines · * Dave Jones ([email protected]) wrote:
Compare the 'physical id' fields of
/proc/cpuinfo, and count how many unique values you get.
Ie, on my dual+ht, I see..physical id : 0
physical id : 0
physical id : 3
physical id : 3Which indicates 2 real CPUs split in two.
Is this guarenteed to be safe on all architectures? Parsing /proc/cpuinfo accross different architectures can be a bit hairy; I'm thinking when non-x86 start to have multiple hardware threads people might want to do the same thing.
Dave
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux on Alpha,68K| Happy \ \ gro.gilbert @ treblig.org | MIPS,x86,ARM,SPARC,PPC & HPPA | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
not for amd Re: Distinguish real vs. virtual CPUs?
In reply to Dave JonesQuoted 2 lines · Dave Jones
Compare the 'physical id' fields of
/proc/cpuinfo, and count how many unique values you get.
It doesn't work for opteron, at least. These are in two sockets, but the phys id is the same.
processor : 0vendor_id : AuthenticAMD
cpu family : 15
model : 5
model name : AMD Opteron(tm) Processor 244
stepping : 8
cpu MHz : 1792.493
cache size : 1024 KB
physical id : 0
siblings : 1fdiv_bug : nohlt_bug : nof00f_bug : nocoma_bug : no
fpu : yesfpu_exception : yes
cpuid level : 1
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 pni syscall nx mmxext lm 3dnowext 3dnow
bogomips : 3514.36
processor : 1vendor_id : AuthenticAMD
cpu family : 15
model : 5
model name : AMD Opteron(tm) Processor 244
stepping : 10
cpu MHz : 1792.493
cache size : 1024 KB
physical id : 0
siblings : 1fdiv_bug : nohlt_bug : nof00f_bug : nocoma_bug : no
fpu : yesfpu_exception : yes
cpuid level : 1
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 pni syscall nx mmxext lm 3dnowext 3dnow
bogomips : 3571.71
Signature · 2 lines
Tom Vier <[email protected]> DSA Key ID 0x15741ECE
Quoted 10 lines · Dan Maas
Is there a canonical way for user-space software to determine how many real CPUs are present in a system (as opposed to HyperThreaded or otherwise virtual CPUs)?
We have an application that for performance reasons wants to run one process per CPU. However, on a HyperThreaded system
/proc/cpuinfolists two CPUs, and running two processes in this case is the wrong thing to do. (Hyperthreading ends up degrading our performance, perhaps due to cache or bus contention).
Quoted 5 lines
Please CC replies.
Thanks,
Dan Maas
-
The simplest thing to do would be to boot with the "noht" parameter.
Or you can use "schedtool" (google or freshmeat) to set the CPU-affinity at runtime to avoid HyperThreading the processes.
Daniel Andersen
Quoted 4 lines · Dan Maas
Is there a canonical way for user-space software to determine how many real CPUs are present in a system (as opposed to HyperThreaded or otherwise virtual CPUs)?
This is 2xXeonHT, is, 4 cpus on 2 packages:
cat /proc/cpuinfo:
processor : 0
...
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
processor : 1
...
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
processor : 2
...
physical id : 3
siblings : 2
core id : 3
cpu cores : 1
processor : 3
...
physical id : 3
siblings : 2
core id : 3
cpu cores : 1
So something like:
cat /proc/cpuinfo | grep 'core id' | uniq | wc -l
would give you the number of packages or 'real cpus'. Then you have to choose which ones are unrelated. Usually evens are siblings of odds, but I won't trust on it...
Quoted 6 lines
We have an application that for performance reasons wants to run one process per CPU. However, on a HyperThreaded system
/proc/cpuinfolists two CPUs, and running two processes in this case is the wrong thing to do. (Hyperthreading ends up degrading our performance, perhaps due to cache or bus contention).
I always hear people about HT 'degrading' performance. Obviously you don't get a 200%, but it is always better than 100%. With my simulation code, in which I did not anything special for HT (it uses my 4 cpus as 'real' ones), I usually get a 125-130% gain. So the theoretical performance loos true. Your application behaviour has to be really nasty to run slower with 2 threads on an HT-P4 that with one thread.
Hope this helps.
--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandrakelinux release 10.2 (Cooker) for i586
Linux 2.6.11-jam6 (gcc 3.4.3 (Mandrakelinux 10.2 3.4.3-6mdk)) #1