aboutsummaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-04-03 23:29:18 +0000
committerUlrich Drepper <drepper@redhat.com>2007-04-03 23:29:18 +0000
commiteab1bdfb8ef2902e7b68352d6ce1b5d603597e36 (patch)
tree00ac9dba5b0687fd0bb056bed3d75e812a2c6a79 /posix
parent9700b0390e40c7ffaed2a74ae3285edfe6080bd3 (diff)
downloadglibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.zip
glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.tar.gz
glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.tar.bz2
* posix/Makefile (routines): Add sched_cpucount.
(tests): Add tst-cpucount. * posix/sched_cpucount.c: New file. * posix/tst-cpucount.c: New file. * posix/Versions: Export __sched_cpucount with version GLIBC_2.6.
Diffstat (limited to 'posix')
-rw-r--r--posix/Makefile4
-rw-r--r--posix/Versions3
-rw-r--r--posix/sched_cpucount.c52
-rw-r--r--posix/tst-cpucount.c27
4 files changed, 84 insertions, 2 deletions
diff --git a/posix/Makefile b/posix/Makefile
index 6c9a1bf..a146077 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -66,7 +66,7 @@ routines := \
spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
posix_madvise \
- get_child_max
+ get_child_max sched_cpucount
include ../Makeconfig
@@ -90,7 +90,7 @@ tests := tstgetopt testfnm runtests runptests \
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
- tst-getaddrinfo3 tst-fnmatch2
+ tst-getaddrinfo3 tst-fnmatch2 tst-cpucount
xtests := bug-ga2
ifeq (yes,$(build-shared))
test-srcs := globtest
diff --git a/posix/Versions b/posix/Versions
index f529ee9..1e1bda8 100644
--- a/posix/Versions
+++ b/posix/Versions
@@ -122,6 +122,9 @@ libc {
GLIBC_2.3.4 {
regexec;
}
+ GLIBC_2.6 {
+ __sched_cpucount;
+ }
GLIBC_PRIVATE {
__libc_fork; __libc_pwrite;
}
diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c
new file mode 100644
index 0000000..8404e8f
--- /dev/null
+++ b/posix/sched_cpucount.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <limits.h>
+#include <sched.h>
+
+
+int
+__sched_cpucount (cpu_set_t *setp)
+{
+ int s = 0;
+ for (unsigned int j = 0; j < __CPU_SETSIZE / __NCPUBITS; ++j)
+ {
+ __cpu_mask l = setp->__bits[j];
+ if (l == 0)
+ continue;
+
+#if LONG_BIT > 32
+ l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul);
+ l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul);
+ l = (l & 0x0f0f0f0f0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0f0f0f0f0ful);
+ l = (l & 0x00ff00ff00ff00fful) + ((l >> 8) & 0x00ff00ff00ff00fful);
+ l = (l & 0x0000ffff0000fffful) + ((l >> 16) & 0x0000ffff0000fffful);
+ l = (l & 0x00000000fffffffful) + ((l >> 32) & 0x00000000fffffffful);
+#else
+ l = (l & 0x55555555ul) + ((l >> 1) & 0x55555555ul);
+ l = (l & 0x33333333ul) + ((l >> 2) & 0x33333333ul);
+ l = (l & 0x0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0ful);
+ l = (l & 0x00ff00fful) + ((l >> 8) & 0x00ff00fful);
+ l = (l & 0x0000fffful) + ((l >> 16) & 0x0000fffful);
+#endif
+
+ s += l;
+ }
+
+ return s;
+}
diff --git a/posix/tst-cpucount.c b/posix/tst-cpucount.c
new file mode 100644
index 0000000..fe3cded
--- /dev/null
+++ b/posix/tst-cpucount.c
@@ -0,0 +1,27 @@
+#include <sched.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+ cpu_set_t c;
+
+ CPU_ZERO (&c);
+
+ for (int cnt = 0; cnt < 130; ++cnt)
+ {
+ int n = CPU_COUNT (&c);
+ if (n != cnt)
+ {
+ printf ("expected %d, not %d\n", cnt, n);
+ return 1;
+ }
+
+ CPU_SET (cnt, &c);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"