Hi,
I'm trying to find out the number of CPUs online on a Dec Alpha.
Following the suggestions of others last week, I'm using the
getsysinfo()
system call. While I've had some success using this command, finding
out
such information as the CPU type and speed, I seem to be getting
nonsense
in attempting to find the number of CPUs online.
Please note, I do not want to use psradm or similar command on the
command
line.
I'm trying to read the cpu_state structure,
/usr/include/machine/hal_sysinfo.h
struct cpu_state {
int cs_cpu_slots; /* max # CPUs supported by this
acrchitecture */
int cs_primary; /* Current primary processor */
cpuset_t cs_primary_eligible; /* CPU can be primary */
cpuset_t cs_configured; /* CPUs with kernel structs allocated
*/
cpuset_t cs_powered; /* CPU slots currently powered up */
cpuset_t cs_present; /* CPUs marked as "present" by
firmware */
cpuset_t cs_available; /* CPUs marked as "available" by
firmware */
cpuset_t cs_running; /* CPUs currently running (online) */
cpuset_t cs_binding; /* CPUs that have threads bound to
them */
cpuset_t cs_ex_binding; /* CPUs that have threads exclusively
bound */
cpuset_t cs_hwc_registered; /* CPU is registered with HWC */
cpuset_t cs_interrupt_enabled; /* CPU is able to take
interrupts */
long cs_future[5]; /* Future expansion -
sizeof(cpu_state)=128 */
};
but while some values in it seem sensible, others such as cs_running,
which is supposed to have the number of CPUs online, has junk in it.
Or at least I've not succeeded in making sense of it. I think the
problem
might be that the type of the elements in the structure are mainly of
type
cpuset_t, which is a void *, but my effors to get this number out have
been
unsuccesful.
Here's the numbers in that structure, as given by dbx. Below that is
the
code I used.
(dbx) print cpu_state_buffer
struct {
cs_cpu_slots = 1
cs_primary = 0
cs_primary_eligible = (nil)
cs_configured = 0x3ff800069c4
cs_powered = 0x120001e40
cs_present = 0x3ff8000ff34
cs_available = 0x1400292a8
cs_running = 0x3ff800100a4
cs_binding = (nil)
cs_ex_binding = 0x14000ddc8
cs_hwc_registered = 0x3ffc0080050
cs_interrupt_enabled = 0xffffffffffffffff
cs_future = {
[0] 5368765672
[1] 0
[2] 0
[3] 4831843840
[4] 0
}
}
Here's the essense of my code. It's not line for line what I have, but
it should give the idea.
#include <sys/sysinfo.h>
#include <machine/hal_sysinfo.h>
main()
{
char *mhz, *cpu_type;
int cpuid;
struct cpu_state cpu_state_buffer;
struct cpu_info cpu_info_buffer;
cpu_type = (char *) malloc(100);
mhz = (char *) malloc(100);
/* Read the CPU id - it returns 56 on my Dec Alpha. Not quite sure
what that means. */
getsysinfo(GSI_CPU,(caddr_t)&cpuid,sizeof(cpuid),0,0);
sprintf(cpu_type,"%d",cpuid);
/* Find the speed of the CPU using GSI_CPU_INFO - this is working
okay, reporting 599 MHz */
getsysinfo(GSI_CPU_INFO,(caddr_t)&cpu_info_buffer,sizeof(cpu_info_buffer),0,0);
sprintf(mhz,"%d",(int) cpu_info_buffer.mhz);
/* Find the state of the CPUs using GSI_CPU_STATE - this is giving
junk
at least for some of the parts of the structure. */
getsysinfo(GSI_CPU_STATE,(caddr_t)&cpu_state_buffer,sizeof(cpu_state_buffer),0,
0);
num_cpus=(int) cpu_state_buffer.cs_running;
}
The return value from getsysinfo() is one, as expected, since I've
requested one item to be stored in the buffer.
--
Dr. David Kirkby,
Senior Research Fellow,
Department of Medical Physics,
University College London,
11-20 Capper St, London, WC1E 6JA.
Tel: 020 7679 6408 Fax: 020 7679 6269
Internal telephone: ext 46408
e-mail davek_at_medphys.ucl.ac.uk
Received on Sat Jun 07 2003 - 01:11:38 NZST