Closed Bug 25981 Opened 25 years ago Closed 24 years ago

Need a function to return the number of CPUs

Categories

(NSPR :: NSPR, enhancement, P3)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: larryh)

Details

We should add a function that returns the
number of CPUs in the system.

Right now, one can obtain this information by
calling the private function PR_GetThreadAffinityMask()
and then counting the number of 1's in the returned
mask.  However, this is a private function and
moreover this function is not implemented in the
pthreads version.

We can either add a new function or add a new
command option to PR_GetSystemInfo().
Severity: normal → enhancement
Status: NEW → ASSIGNED
Adding an option to PR_GetSystemInfo should be fine.

The precise meaning of "number of cpus" should be made clear. For example, the 
number of processors available to run user applications may be different from 
the number of physical processors online.
Reassigned to larryh as a NSPR 4.1 feature.
Status: ASSIGNED → NEW
QA Contact: srinivas → wtc
Target Milestone: --- → 4.1
Forgot to click on "reassign".
Assignee: wtc → larryh
Status: NEW → ASSIGNED
Checking in parts:

Checking in pr/include/prsystem.h;
/cvsroot/mozilla/nsprpub/pr/include/prsystem.h,v  <--  prsystem.h
new revision: 3.5; previous revision: 3.4
done
Checking in pr/src/misc/prsystem.c;
/cvsroot/mozilla/nsprpub/pr/src/misc/prsystem.c,v  <--  prsystem.c
new revision: 3.7; previous revision: 3.6
done
Checking in pr/tests/system.c;
/cvsroot/mozilla/nsprpub/pr/tests/system.c,v  <--  system.c
new revision: 3.3; previous revision: 3.2
done

Fix my OS/2 implementation using fix inspired by Skip Nizinski 
<snizinski@us.ibm.com>. Thanks for the help, Skip

Checking in prsystem.c;
/cvsroot/mozilla/nsprpub/pr/src/misc/prsystem.c,v  <--  prsystem.c
new revision: 3.8; previous revision: 3.7
I changed _SC_NPROC_CONF to _SC_NPROC_ONLN (we want the number
of online processors).  Made the code compile on HP-UX 10 and
SINIX.
/cvsroot/mozilla/nsprpub/pr/src/misc/prsystem.c, revision 3.9

I found that sysconf(_SC_NPROC_ONLN) (and _SC_NPROC_CONF too)
fails with EINVAL on SINIX-Z 5.42 and SINIX-N 5.43.  I don't
know why.  So I backed out the SINIX (aka RELIANTUNIX) stuff.
/cvsroot/mozilla/nsprpub/pr/src/misc/prsystem.c, revision 3.10
Ops, my linux compile died because a missing #endif in #ifndef ... (version
3.8):

#if defined(OS2)
#define INCL_DOS
#include <os2.h>
/* define the required constant if it is not already defined in the headers */
#ifndef QSV_NUMPROCESSORS
#define QSV_NUMPROCESSORS 26
#endif
ADD AN #endif HERE OR WE'RE IN TROUBLE ... 
added missing #endif
marking as fixed.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Hans Lambermont <hans@blender.nl> pointed out that
BSD-derived systems (BSD/OS, FreeBSD, NetBSD, OpenBSD,
and MacOS X) use sysctl() to get the number of processors.
/cvsroot/mozilla/nsprpub/pr/src/misc/prsystem.c, revision 3.14
Hard code the returned value to 1 for MacOS.
You need to log in before you can comment on or make changes to this bug.