From dd47c5d857f749662d9c025244d4df72aba0c67b Mon Sep 17 00:00:00 2001 From: Hasso Tepper Date: Thu, 21 Feb 2008 12:47:54 +0000 Subject: [PATCH] Add _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN variables to the sysconf(3). These are nonstandard, but implemented in many systems. --- lib/libc/gen/sysconf.3 | 11 +++++++++-- lib/libc/gen/sysconf.c | 7 ++++++- sys/sys/unistd.h | 5 ++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3 index f3268155af..7838f7cd2c 100644 --- a/lib/libc/gen/sysconf.3 +++ b/lib/libc/gen/sysconf.3 @@ -31,9 +31,9 @@ .\" .\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD: src/lib/libc/gen/sysconf.3,v 1.8.2.6 2001/12/14 18:33:51 ru Exp $ -.\" $DragonFly: src/lib/libc/gen/sysconf.3,v 1.5 2006/05/26 19:39:36 swildner Exp $ +.\" $DragonFly: src/lib/libc/gen/sysconf.3,v 1.6 2008/02/21 12:47:54 hasso Exp $ .\" -.Dd April 19, 1994 +.Dd February 21, 2008 .Dt SYSCONF 3 .Os .Sh NAME @@ -158,6 +158,10 @@ otherwise \-1. .It Li _SC_2_UPE Return 1 if the system supports the User Portability Utilities Option, otherwise \-1. +.It Li _SC_NPROCESSORS_CONF +The number of processors configured. +.It Li _SC_NPROCESSORS_ONLN +The number of processors online. .El .Sh RETURN VALUES If the call to @@ -192,6 +196,9 @@ Except for the fact that values returned by may change over the lifetime of the calling process, this function conforms to .St -p1003.1-88 . +.Pp +_SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are nonstandard, but implemented +in many systems. .Sh HISTORY The .Fn sysconf diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 876be4adb8..9c35c676d4 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)sysconf.c 8.2 (Berkeley) 3/20/94 - * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.4 2005/11/13 00:07:42 swildner Exp $ + * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.5 2008/02/21 12:47:54 hasso Exp $ */ #include @@ -286,6 +286,11 @@ sysconf(int name) mib[1] = CTL_P1003_1B_TIMER_MAX; goto yesno; #endif /* _P1003_1B_VISIBLE */ + case _SC_NPROCESSORS_CONF: + case _SC_NPROCESSORS_ONLN: + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + goto yesno; yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) return (-1); diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index e41779e2df..1646fd259e 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -32,7 +32,7 @@ * * @(#)unistd.h 8.2 (Berkeley) 1/7/94 * $FreeBSD: src/sys/sys/unistd.h,v 1.22.2.2 2000/08/22 01:46:30 jhb Exp $ - * $DragonFly: src/sys/sys/unistd.h,v 1.8 2007/03/01 01:46:53 corecode Exp $ + * $DragonFly: src/sys/sys/unistd.h,v 1.9 2008/02/21 12:47:54 hasso Exp $ */ #ifndef _SYS_UNISTD_H_ @@ -201,6 +201,9 @@ #endif /* _P1003_1B_VISIBLE */ +#define _SC_NPROCESSORS_CONF 57 +#define _SC_NPROCESSORS_ONLN 58 + #ifndef _POSIX_SOURCE /* * rfork() options. -- 2.11.4.GIT