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: SUMMARY: Can I determine the number of cpus via system call? Date: Wed, 04 Jun 2003 10:11:34 +0100 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <3EDDB7C6.91F4F306@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 1054717786 8966 80.91.224.249 (4 Jun 2003 09:09:46 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 4 Jun 2003 09:09:46 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Wed Jun 04 11:09:44 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 19NUH9-0002KH-00 for ; Wed, 04 Jun 2003 11:09:43 +0200 Original-Received: (qmail 11356 invoked by uid 5); 4 Jun 2003 09:11:47 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 11347 invoked by uid 49493); 4 Jun 2003 09:11:47 -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(-2.9/5.0):. Processed in 0.519259 secs); 04 Jun 2003 09:11:47 -0000 Original-Received: from unknown (HELO emroute1.cind.ornl.gov) (160.91.4.119) by 0 with SMTP; 4 Jun 2003 09:11:46 -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 <0HFY00F9W9JLJ8@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 04 Jun 2003 05:11:46 -0400 (EDT) Original-Received: from mta06-svc.ntlworld.com (mta06-svc.ntlworld.com [62.253.162.46]) by emroute1.cind.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HFY0015Y9JDWA@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 04 Jun 2003 05:11:39 -0400 (EDT) Original-Received: from ntlworld.com ([62.255.40.100]) by mta06-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20030604091135.LRVS12018.mta06-svc.ntlworld.com@ntlworld.com> for ; Wed, 04 Jun 2003 10:11:35 +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:4424 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:4424 Thanks to everyone (too many to mention you all) who answered my question about how to find the number of active cpus in a system via a system call from C. I obviously did not make myself too clear, as 95% of the responses, gave me commands to use at the command line - psrinfo, psradmin which I knew of, hwmgr which I did not. However, some people did suggest the use of 'getsysinfo' which was what I was looking for. Ralf Anoil said: > "getsysinfo" will do the job. There are several 'ops' (first argument > to 'getsysinfo') to retrieve different characteristics of the system. > See the manual page. Below is a program to determine the numbers of cpus > in the machine. 'GSI_CPU_STATE' will give you the active cpus. > Note that there are differences between Tru64 V4 und V5 regarding the > returned structures. Rald even gave me a program to determine the number of cpus in a system - see below, although I will determine the state of the cpus using GSI_CPU_STATE, rather than just the total number, since I'm testing some multi-threaded code and want to see how well it performs as the number of cpus is increased. The only problem is my Dec Alpha can only take one CPU!! However, I do have other machines that have 4 cpus at my disposal and wanted to write the code so that it was portable. Dr. Thomas Blinn has pointed out that getsysinfo() is unique to Tru64 UNIX. Ferens D.M. said: > On GS160, GS320 You can use sysman for viewing, powering on and off > cpus. With sysman You also can directly off and on power on cpu. Unfortunately, I don't have this sort of hardware to play with. There seems to be a problem getting this information in a portable way (which is what I ideally wanted). Linux appears to have no sensible way of finding the information that works across different versions of Linux, Solaris has processor_info(), Tru64 has getsysinfo(). I don't know about other commercial UNIX variants (AIX, IRIX, HP-UX etc.). Thanks everyone. Here's Ralf's code. #include #include #include int main( int argc, char *argv[] ) { int start = 0; int buffer; getsysinfo( GSI_CPUS_IN_BOX, (char *)&buffer, 4, 0, 0); printf("cpus = %d\n",buffer); return 0; } -- 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