Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determine number of CPUs

221 views
Skip to first unread message

Dave

unread,
Oct 14, 2009, 6:07:41 AM10/14/09
to
Does anyone know the best way to determine the number of CPUs on AIX,
HP-UX? (I'll extend the code to test on Tru64 and IRIX if anyone wants
to give me the info, but that is hardly high on the priority list).

The constraints are

1) It can be done from the shell.
2) It must not require root privileges
3) It gives the number of physical CPUs, rather than cores.

Finding the number of cores, and/or hardware threads would be a nice
addition, but I'm trying to improve an autoconf macro

http://www.nongnu.org/autoconf-archive/ax_count_cpus.html

which has a description of "Attempt to count the number of processors
present on the machine."

In practice, I suspect the number of cores would be a more useful value
to have, but for now at least, I'll use physical processors, as that is
what the macro implies it does. (It was undoubtedly written without
multi-core CPUs in mind). Perhaps I'll write another macros called
AX_COUNT_CORES and AX_COUNT_THREADS, but for now, I just want to fix the
above macro which is broken.

I've seen various methods on the web, but many simply do not work on the
hardware I've tried them on.

http://unix.ittoolbox.com/groups/technical-functional/hp-ux-l/command-to-determine-how-many-cpus-187381

says of HP to try

/opt/ignite/bin/print_manifest | pg

well, it does not work on my HP-UX box.

I've seen some suggestions for AIX which involve greping syslog. But one
can hardly guarantee that the admin has not disabled that.

I'm perhaps looking for the impossible, but something which will always
work, like:

$ psrinfo -p
2

does on Solaris.

--
I respectfully request that this message is not archived by companies as
unscrupulous as 'Experts Exchange' . In case you are unaware,
'Experts Exchange' take questions posted on the web and try to find
idiots stupid enough to pay for the answers, which were posted freely
by others. They are leeches.

Leo

unread,
Oct 14, 2009, 9:44:52 AM10/14/09
to
Hi,

You can use "prtconf | grep Processors" which will display the number
of processors.
you can use "lsdev -Cc processor" which will display all the
processors and id's. you can count the number of lines which gives the
total number of processors by the command "lsdev -Cc processor | wc -
l"
And you can use "bindprocessor -q" which shows the number of cores.

all the above commands can be used by a basic user. hope it helps

-LeO


On Oct 14, 11:07 am, Dave <f...@coo.com> wrote:
> Does anyone know the best way to determine the number of CPUs on AIX,
> HP-UX? (I'll extend the code to test on Tru64 and IRIX if anyone wants
> to give me the info, but that is hardly high on the priority list).
>
> The constraints are
>
> 1) It can be done from the shell.
> 2) It must not require root privileges
> 3) It gives the number of physical CPUs, rather than cores.
>
> Finding the number of cores, and/or hardware threads would be a nice
> addition, but I'm trying to improve an autoconf macro
>
> http://www.nongnu.org/autoconf-archive/ax_count_cpus.html
>
> which has a description of "Attempt to count the number of processors
> present on the machine."
>
> In practice, I suspect the number of cores would be a more useful value
> to have, but for now at least, I'll use physical processors, as that is
> what the macro implies it does. (It was undoubtedly written without
> multi-core CPUs in mind).  Perhaps I'll write another macros called
> AX_COUNT_CORES and AX_COUNT_THREADS, but for now, I just want to fix the
> above macro which is broken.
>
> I've seen various methods on the web, but many simply do not work on the
> hardware I've tried them on.
>

> http://unix.ittoolbox.com/groups/technical-functional/hp-ux-l/command...

Don Morris

unread,
Oct 14, 2009, 11:57:10 AM10/14/09
to
Dave wrote:
> Does anyone know the best way to determine the number of CPUs on AIX,
> HP-UX? (I'll extend the code to test on Tru64 and IRIX if anyone wants
> to give me the info, but that is hardly high on the priority list).
>
> The constraints are
>
> 1) It can be done from the shell.
> 2) It must not require root privileges
> 3) It gives the number of physical CPUs, rather than cores.

For HP-UX, that's not likely to be compatible across all
architectures. (PA and IPF have different commands to report
physical sockets/cpus). Scheduling units is much easier (which
may mean cores or hyperthreads within cores, etc.):

mpsched -s |grep "Processor Count"|cut -d : -f 2

should work on all supported versions of HP-UX (11.11 and higher,
in other words). (The cut part may not be perfect... I'm a C coder
at heart, not a shell scripter... but the Processor Count line is
what you want, getting that to a number should be doable).

Don


--
kernel, n:
A part of an operating system that preserves the medieval traditions
of sorcery and black art.

Rick Jones

unread,
Oct 14, 2009, 2:52:42 PM10/14/09
to
In comp.sys.hp.hpux Dave <f...@coo.com> wrote:
> Does anyone know the best way to determine the number of CPUs on AIX,
> HP-UX? (I'll extend the code to test on Tru64 and IRIX if anyone wants
> to give me the info, but that is hardly high on the priority list).

> The constraints are

> 1) It can be done from the shell.
> 2) It must not require root privileges
> 3) It gives the number of physical CPUs, rather than cores.

Out of curiousity, to what purpose will the information be put?
Particularly since it seems to be to find the number of chips/sockets
rather than the number of scheduling entities.

> Finding the number of cores, and/or hardware threads would be a nice
> addition, but I'm trying to improve an autoconf macro

> http://www.nongnu.org/autoconf-archive/ax_count_cpus.html

> which has a description of "Attempt to count the number of processors
> present on the machine."

Doesn't autoconf have the ability to compile and run "test" programs?

rick jones
--
oxymoron n, Hummer H2 with California Save Our Coasts and Oceans plates
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

sjm

unread,
Oct 15, 2009, 9:59:37 AM10/15/09
to
On 14 Oct, 11:07, Dave <f...@coo.com> wrote:

> 3) It gives the number of physical CPUs, rather than cores.

Well it all depends what *you* define as a "physical CPU" and what you
are trying to achieve by that definition. In particular, IBM and Intel
offer conflicting definitions of what is a CHIP, a CPU, a PROCESSOR
and a CORE. Intel mainly make chips (as well as other stuff), so they
refer to these CHIPS as PROCESSORS, even if they have multiple CORES.
IBM mainly make systems (as well as other stuff) so they refer to
CORES as PROCESSORS, even if there is more than one PROCESSOR per
CHIP. And then you have to add that contemporary IBM chips like POWER5
can have more than one THREAD per CORE, and more than one CORE per
CHIP, and more than one CHIP per SOCKET.

So what was it that you wanted to know?

Dave

unread,
Oct 15, 2009, 2:00:08 PM10/15/09
to

Let me give you the background, as clearly I need to to avoid confusion.

1) I'm well aware there is some ambiguity in these terms. I use a Sun
T5240 which has two CPUs, 16 cores and 128 hardware threads. Depending
on how you test for 'cpus' you can get 2 or 128. (I'm not sure if there
is a way of finding the cores, so getting 16)

2) Sage

http://www.sagemath.org/

is a large maths program, which makes heavy use of programs written by
lots of people in lots of languages (C, C++, Fortran, Perl, Python) and
perhaps a few others. The basic concept of Sage is to not write a maths
package from scratch, but to make use of all the existing maths software
(some of which took many man-years to develop), and tie them all
together with a common interface (a web browser). Users write their
programs in a single language (pyton) by typing into their browser.

It uses things like ATLAS for linear algebra, maxima for calculus etc.

3) Several of the 100 or so packages in Sage make use of autoconf.

4) One package in Sage (libm4ri) makes use of this autoconf macro

http://www.nongnu.org/autoconf-archive/ax_count_cpus.html

which is supposed to count the number of CPUs. As you can see if you
read it, the macro's documentation is not exactly clear about what are
CPUs. I suspect it was written before the days of multi-core processors.

Even ignoring the fact of the ambiguity, I'm told by users of the
autoconf mailing list that the macro is badly written.

5) It would be nice to modify that macro so it counts the number of
processors fitted in a box (I'm aware too that some sockets on
motherboards can take a single or dual CPU). Then, for the good of the
community, there would a be a macro which did just this.

6) Having discussed with the author of the lib4mri, the number of cores
would be most useful to his package. Hence really we need a new macro
which determines the number of cores.

Perhaps I should just forget about that macro, and find a way of
counting the cores.

Either way, what options are available to me? The only HP-UX box I have
access to is an old single processor box, so I can't really do much
testing on that. For Solaris I have access to numerous machines, with
processors varying from 1 to 4, and cores varying from 1 to 16.

For AIX I have easy access to only one machine. I'm not sure of the spec
of that.

I know on Solaris, an admin can limit the number of CPUs in different
zones, take processors off-line.

Clearly this gets quite complex. Probably the best solution is the user
specifies how many CPUs he has in some environment variable, but an
automatic method, even if not 100% right, would be useful.

Ultimately, nobody is going to die because of a failure of this.

I believe this is one of those things that is really impossible to do
right, but if someone can tell me some commands that might be useful,
I'd be interested.

Dave

Henry

unread,
Oct 15, 2009, 3:49:04 PM10/15/09
to

lparstat ?

Dave

unread,
Oct 15, 2009, 6:51:11 PM10/15/09
to
Leo wrote:
> Hi,
>
> You can use "prtconf | grep Processors" which will display the number
> of processors.
> you can use "lsdev -Cc processor" which will display all the
> processors and id's. you can count the number of lines which gives the
> total number of processors by the command "lsdev -Cc processor | wc -
> l"
> And you can use "bindprocessor -q" which shows the number of cores.
>
> all the above commands can be used by a basic user. hope it helps
>
> -LeO

Thank you for the help on AIX. Would I be right in assuming this box has
a pair of dual core processors?

$ lsdev -Cc processor
proc0 Available 00-00 Processor
proc2 Available 00-02 Processor
$ bindprocessor -q
The available processors are: 0 1 2 3
$ prtconf | grep Processors
Number Of Processors: 2

Do you know if the format of the output has been stable over the various
AIX releases, so it can be parsed and used in scripts which will work on
most AIX releases?

Can anyone come up with similar data for HP-UX?


Just out of interest I'll add for a Solaris box with two CPUs, each with
8 cores, and each core having 4 hardware threads (i.e. 128 threads)
kirkby@t2:[~] $ psrinfo
0 on-line since 08/14/2009 09:24:31
1 on-line since 08/14/2009 09:24:33
2 on-line since 08/14/2009 09:24:33
etc. so

kirkby@t2:[~] $ psrinfo | wc -l
128

means it has 128 threads.

kirkby@t2:[~] $ psrinfo -p
2

means there are two physical processors. I do not know how to get the
number of cores, which is probably the most useful thing actually.

Dave

Michael Kraemer

unread,
Oct 16, 2009, 2:14:56 AM10/16/09
to
Dave schrieb:

> Leo wrote:
>
>> Hi,
>>
>> You can use "prtconf | grep Processors" which will display the number
>> of processors.
>> you can use "lsdev -Cc processor" which will display all the
>> processors and id's. you can count the number of lines which gives the
>> total number of processors by the command "lsdev -Cc processor | wc -
>> l"
>> And you can use "bindprocessor -q" which shows the number of cores.
>>
>> all the above commands can be used by a basic user. hope it helps
>>
>> -LeO
>
>
> Thank you for the help on AIX. Would I be right in assuming this box has
> a pair of dual core processors?
>
> $ lsdev -Cc processor
> proc0 Available 00-00 Processor
> proc2 Available 00-02 Processor
> $ bindprocessor -q
> The available processors are: 0 1 2 3
> $ prtconf | grep Processors
> Number Of Processors: 2
>
> Do you know if the format of the output has been stable over the various
> AIX releases, so it can be parsed and used in scripts which will work on
> most AIX releases?

Well, almost, but not quite.
Releases earlier than 4.3 apparently lack the latter two commands,
but I presume those are not your targets anyway.
The proc0/1 naming scheme seems to depend on whether one has
a true single processor system or a crippled dual-core one
(the IntelliStation example below).
On Power5 and above, with AIX 5.3 and above, SMT
might be enabled, which gives twice as many "threads" than you have cores,
but it's not clear whether this is an advantage for your app.
So the pragmatic approach might be to assume single core for
everything below AIX 5.1 (4.3?) and go with prtconf for
the CPU count.

Here's a collection what I get on some of my systems:

AIX 5.1, 43P-240:
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors
proc0 Available 00-00 Processor
proc1 Available 00-01 Processor


The available processors are: 0 1

Number Of Processors: 2

AIX 4.2, 25T
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors
proc0 Available 00-00 Processor
ksh: bindprocessor: not found.
ksh: prtconf: not found.

AIX 5.2, IntelliStation 275
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors
proc1 Available 00-01 Processor


The available processors are: 0

Number Of Processors: 1

AIX 5.2, p510
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors


proc0 Available 00-00 Processor
proc2 Available 00-02 Processor

The available processors are: 0 1

Number Of Processors: 2

AIX 5.3, p505Q, SMT enabled
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors


proc0 Available 00-00 Processor
proc2 Available 00-02 Processor

proc4 Available 00-04 Processor
proc6 Available 00-06 Processor
The available processors are: 0 1 2 3 4 5 6 7
/usr/sbin/prtconf[156]: /usr/lib/boot/bin/dmpdt_chrp: cannot execute
Number Of Processors: 4

AIX 6.1, power 520, SMT enabled
$ lsdev -Cc processor; bindprocessor -q; prtconf | grep Processors


proc0 Available 00-00 Processor
proc2 Available 00-02 Processor

proc4 Available 00-04 Processor
proc6 Available 00-06 Processor
The available processors are: 0 1 2 3 4 5 6 7
Number Of Processors: 4

Message has been deleted

John F. Carr

unread,
Oct 19, 2009, 6:18:14 PM10/19/09
to
In article <4ad7...@212.67.96.135>, Dave <f...@coo.com> wrote:
>4) One package in Sage (libm4ri) makes use of this autoconf macro
>
>http://www.nongnu.org/autoconf-archive/ax_count_cpus.html
>[...]

>
>6) Having discussed with the author of the lib4mri, the number of cores
>would be most useful to his package. Hence really we need a new macro
>which determines the number of cores.

I checked the libm4ri source and I don't see the CPU count being used.
Have you tried removing the autoconf fragment?

Anyway, this sounds like a job for a runtime call rather than
an autoconf macro. The source uses OpenMP. Doesn't OMP (or
any similar package) figure out the CPU count for itself at runtime?

autoconf is usually the wrong tool, but especially so when you want
to ask about the machine where you intend to run instead of the machine
where you are compiling.

--
John Carr (j...@mit.edu)

Dave

unread,
Oct 20, 2009, 8:16:23 AM10/20/09
to

Very good point you have there. I'll contact the author about that, as it does
seem silly to test this at compile time.

0 new messages