summaryrefslogtreecommitdiff
path: root/src/conf
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-05-13 00:44:35 -0400
committerRich Felker <dalias@aerifal.cx>2012-05-13 00:44:35 -0400
commit9a7fac7934975338449b63eb4d0409b472251dfa (patch)
treea6d8ac1a26c7b33bebd6aaf189de1624c89c0d42 /src/conf
parente68c51ac46a9f273927aef8dcebc89912ab19ece (diff)
downloadmusl-9a7fac7934975338449b63eb4d0409b472251dfa.tar.gz
musl-9a7fac7934975338449b63eb4d0409b472251dfa.tar.bz2
musl-9a7fac7934975338449b63eb4d0409b472251dfa.tar.xz
musl-9a7fac7934975338449b63eb4d0409b472251dfa.zip
let sysconf accurately report # of cpus available
i've been trying out openmp and it seems like it won't be much use without this...
Diffstat (limited to 'src/conf')
-rw-r--r--src/conf/sysconf.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c
index 07072ccf..d6691df8 100644
--- a/src/conf/sysconf.c
+++ b/src/conf/sysconf.c
@@ -6,6 +6,7 @@
#define VER (-2)
#define OFLOW (-3)
+#define CPUCNT (-4)
#define RLIM(x) (-32768|(RLIMIT_ ## x))
long sysconf(int name)
@@ -94,8 +95,8 @@ long sysconf(int name)
[_SC_THREAD_PRIO_INHERIT] = -1,
[_SC_THREAD_PRIO_PROTECT] = -1,
[_SC_THREAD_PROCESS_SHARED] = VER,
- [_SC_NPROCESSORS_CONF] = -1,
- [_SC_NPROCESSORS_ONLN] = -1,
+ [_SC_NPROCESSORS_CONF] = CPUCNT,
+ [_SC_NPROCESSORS_ONLN] = CPUCNT,
[_SC_PHYS_PAGES] = -1,
[_SC_AVPHYS_PAGES] = -1,
[_SC_ATEXIT_MAX] = -1,
@@ -220,6 +221,13 @@ long sysconf(int name)
} else if (values[name] == OFLOW) {
if (name == _SC_ARG_MAX) return ARG_MAX;
if (name == _SC_SEM_VALUE_MAX) return SEM_VALUE_MAX;
+ } else if (values[name] == CPUCNT) {
+ unsigned char set[128] = {1};
+ int i, cnt;
+ __syscall(SYS_sched_getaffinity, 0, sizeof set, set);
+ for (i=cnt=0; i<sizeof set; i++)
+ for (; set[i]; set[i]&=set[i]-1, cnt++);
+ return cnt;
} else if (values[name] < OFLOW) {
long lim[2];
__syscall(SYS_getrlimit, values[name]&16383, lim);