diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-04-03 23:29:18 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-04-03 23:29:18 +0000 |
commit | eab1bdfb8ef2902e7b68352d6ce1b5d603597e36 (patch) | |
tree | 00ac9dba5b0687fd0bb056bed3d75e812a2c6a79 /posix | |
parent | 9700b0390e40c7ffaed2a74ae3285edfe6080bd3 (diff) | |
download | glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.tar glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.tar.gz glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.tar.bz2 glibc-eab1bdfb8ef2902e7b68352d6ce1b5d603597e36.zip |
* 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/Makefile | 4 | ||||
-rw-r--r-- | posix/Versions | 3 | ||||
-rw-r--r-- | posix/sched_cpucount.c | 52 | ||||
-rw-r--r-- | posix/tst-cpucount.c | 27 |
4 files changed, 84 insertions, 2 deletions
diff --git a/posix/Makefile b/posix/Makefile index 6c9a1bf0c3..a1460776bf 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 f529ee9d8e..1e1bda8b7b 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 0000000000..8404e8f3c0 --- /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 0000000000..fe3cded732 --- /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" |