* Distinguish real vs. virtual CPUs?
@ 2005-03-22 1:27 Dan Maas
2005-03-22 1:56 ` Dave Jones
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Dan Maas @ 2005-03-22 1:27 UTC (permalink / raw)
To: linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Distinguish real vs. virtual CPUs?
2005-03-22 1:27 Distinguish real vs. virtual CPUs? Dan Maas
@ 2005-03-22 1:56 ` Dave Jones
2005-03-22 11:55 ` Dr. David Alan Gilbert
2005-03-22 15:02 ` not for amd " Tom Vier
2005-03-22 2:01 ` Daniel Andersen
2005-03-22 2:12 ` J.A. Magallon
2 siblings, 2 replies; 6+ messages in thread
From: Dave Jones @ 2005-03-22 1:56 UTC (permalink / raw)
To: Dan Maas; +Cc: linux-kernel
On Mon, Mar 21, 2005 at 08:27:26PM -0500, Dan Maas wrote:
> 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).
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Distinguish real vs. virtual CPUs?
2005-03-22 1:56 ` Dave Jones
@ 2005-03-22 11:55 ` Dr. David Alan Gilbert
2005-03-22 15:02 ` not for amd " Tom Vier
1 sibling, 0 replies; 6+ messages in thread
From: Dr. David Alan Gilbert @ 2005-03-22 11:55 UTC (permalink / raw)
To: Dave Jones, Dan Maas, linux-kernel
* Dave Jones (davej@redhat.com) 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 : 3
>
> Which 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 |_______/
^ permalink raw reply [flat|nested] 6+ messages in thread
* not for amd Re: Distinguish real vs. virtual CPUs?
2005-03-22 1:56 ` Dave Jones
2005-03-22 11:55 ` Dr. David Alan Gilbert
@ 2005-03-22 15:02 ` Tom Vier
1 sibling, 0 replies; 6+ messages in thread
From: Tom Vier @ 2005-03-22 15:02 UTC (permalink / raw)
To: linux-kernel
On Mon, Mar 21, 2005 at 08:56:03PM -0500, Dave Jones wrote:
> 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 : 0
vendor_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 : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_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 : 1
vendor_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 : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_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
--
Tom Vier <tmv@comcast.net>
DSA Key ID 0x15741ECE
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Distinguish real vs. virtual CPUs?
2005-03-22 1:27 Distinguish real vs. virtual CPUs? Dan Maas
2005-03-22 1:56 ` Dave Jones
@ 2005-03-22 2:01 ` Daniel Andersen
2005-03-22 2:12 ` J.A. Magallon
2 siblings, 0 replies; 6+ messages in thread
From: Daniel Andersen @ 2005-03-22 2:01 UTC (permalink / raw)
To: Dan Maas; +Cc: linux-kernel
Dan Maas wrote:
> 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
> -
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
--
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Distinguish real vs. virtual CPUs?
2005-03-22 1:27 Distinguish real vs. virtual CPUs? Dan Maas
2005-03-22 1:56 ` Dave Jones
2005-03-22 2:01 ` Daniel Andersen
@ 2005-03-22 2:12 ` J.A. Magallon
2 siblings, 0 replies; 6+ messages in thread
From: J.A. Magallon @ 2005-03-22 2:12 UTC (permalink / raw)
To: Dan Maas; +Cc: linux-kernel
On 03.22, Dan Maas wrote:
> 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...
> 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).
>
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-03-22 15:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-22 1:27 Distinguish real vs. virtual CPUs? Dan Maas
2005-03-22 1:56 ` Dave Jones
2005-03-22 11:55 ` Dr. David Alan Gilbert
2005-03-22 15:02 ` not for amd " Tom Vier
2005-03-22 2:01 ` Daniel Andersen
2005-03-22 2:12 ` J.A. Magallon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox