Updated and re-posting again now that we're clear of the ABI lock
for h2k9.


----- Forwarded message from Brad <b...@comstyle.com> -----

Date: Sat, 14 Nov 2009 19:17:06 -0500
From: Brad <b...@comstyle.com>
To: tech@openbsd.org
Subject: Add support for sysconf(3) _SC_NPROCESSORS_CONF /
        _SC_NPROCESSORS_ONLN
User-Agent: Mutt/1.5.20 (2009-06-14)

The following diff adds support for sysconf(3) for the variables
_SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN.

Implemented by AIX/Tru64/Solaris/Linux/FreeBSD/NetBSD.


I have run into this being used by 3 programs in ports so far.


Index: lib/libc/shlib_version
===================================================================
RCS file: /cvs/src/lib/libc/shlib_version,v
retrieving revision 1.120
diff -u -p -r1.120 shlib_version
@@ -1,4 +1,4 @@
 major=53
-minor=0
+minor=1
 # note: If changes were made to include/thread_private.h or if system
 # calls were added/changed then libpthread must also be updated.
Index: lib/libc/gen/sysconf.3
===================================================================
RCS file: /cvs/src/lib/libc/gen/sysconf.3,v
retrieving revision 1.25
diff -u -p -r1.25 sysconf.3
--- lib/libc/gen/sysconf.3      25 Jun 2008 17:45:07 -0000      1.25
+++ lib/libc/gen/sysconf.3      14 Nov 2009 23:33:51 -0000
@@ -168,6 +168,10 @@ functions.
 The maximum length of a login name.
 .It Li _SC_THREAD_SAFE_FUNCTIONS
 The level of support for thread-safe (re-entrant) functions.
+.It Li _SC_NPROCESSORS_CONF
+The number of processors configured.
+.It Li _SC_NPROCESSORS_ONLN
+The number of processors online (capable of running processes).
 .El
 .Sh RETURN VALUES
 If the call to
@@ -202,6 +206,11 @@ The
 .Fn sysconf
 function conforms to
 .St -p1003.1-88 .
+The constants
+.Li _SC_NPROCESSORS_CONF
+and
+.Li _SC_NPROCESSORS_ONLN
+are not part of the standard, but are provided by many systems.
 .Sh HISTORY
 The
 .Fn sysconf
Index: lib/libc/gen/sysconf.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/sysconf.c,v
retrieving revision 1.10
diff -u -p -r1.10 sysconf.c
--- lib/libc/gen/sysconf.c      25 Jun 2008 14:54:44 -0000      1.10
+++ lib/libc/gen/sysconf.c      14 Nov 2009 23:22:38 -0000
@@ -238,6 +238,15 @@ yesno:             if (sysctl(mib, namelen, &value,
                return (vmtotal.t_free);
        }
 
+       case _SC_NPROCESSORS_CONF:
+               mib[0] = CTL_HW;
+               mib[1] = HW_NCPU;
+               break;
+       case _SC_NPROCESSORS_ONLN:
+               mib[0] = CTL_HW;
+               mib[1] = HW_NCPU;
+               break;
+
        default:
                errno = EINVAL;
                return (-1);
Index: sys/sys/unistd.h
===================================================================
RCS file: /cvs/src/sys/sys/unistd.h,v
retrieving revision 1.16
diff -u -p -r1.16 unistd.h
--- sys/sys/unistd.h    22 Aug 2008 14:39:21 -0000      1.16
+++ sys/sys/unistd.h    29 Dec 2009 02:42:13 -0000
@@ -142,6 +142,8 @@
 
 #define        _SC_PHYS_PAGES          500
 #define        _SC_AVPHYS_PAGES        501
+#define        _SC_NPROCESSORS_CONF    502
+#define        _SC_NPROCESSORS_ONLN    503
 
 /* configurable system strings */
 #define        _CS_PATH                 1

----- End forwarded message -----

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Reply via email to