From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Dr. David Kirkby" Newsgroups: gmane.os.tru64.managers Subject: Problem finding number of CPUs online. Date: Sat, 07 Jun 2003 02:10:56 +0100 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <3EE13BA0.28203D7C@ntlworld.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1054948136 30881 80.91.224.249 (7 Jun 2003 01:08:56 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 7 Jun 2003 01:08:56 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Sat Jun 07 03:08:53 2003 Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.22.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 19OSCS-00081X-00 for ; Sat, 07 Jun 2003 03:08:52 +0200 Original-Received: (qmail 24079 invoked by uid 5); 7 Jun 2003 01:11:08 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 24070 invoked by uid 49493); 7 Jun 2003 01:11:07 -0000 Original-Received: from drkirkby@ntlworld.com by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.54. spamassassin: 2.50-cvs. Clear:SA:0(0.6/5.0):. Processed in 0.472394 secs); 07 Jun 2003 01:11:07 -0000 Original-Received: from unknown (HELO emroute1.cind.ornl.gov) (160.91.4.119) by 0 with SMTP; 7 Jun 2003 01:11:07 -0000 Original-Received: from emroute1.cind.ornl.gov (localhost [127.0.0.1]) by emroute1.cind.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HG300F0G7AFSK@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 06 Jun 2003 21:11:06 -0400 (EDT) Original-Received: from mta05-svc.ntlworld.com (mta05-svc.ntlworld.com [62.253.162.45]) by emroute1.cind.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HG300K6X7AB2Z@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 06 Jun 2003 21:11:01 -0400 (EDT) Original-Received: from ntlworld.com ([62.255.96.20]) by mta05-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20030607011057.TVBP16933.mta05-svc.ntlworld.com@ntlworld.com> for ; Sat, 07 Jun 2003 02:10:57 +0100 Original-To: "tru64-unix-managers@ornl.gov" X-Mailer: Mozilla 4.78 [en] (X11; U; SunOS 5.9 sun4u) X-Accept-Language: en Xref: main.gmane.org gmane.os.tru64.managers:4462 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:4462 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 #include 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@medphys.ucl.ac.uk