From eab1bdfb8ef2902e7b68352d6ce1b5d603597e36 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 3 Apr 2007 23:29:18 +0000 Subject: [PATCH] * 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. --- ChangeLog | 8 ++++++++ posix/Makefile | 4 ++-- posix/Versions | 3 +++ posix/sched_cpucount.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ posix/tst-cpucount.c | 27 ++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 posix/sched_cpucount.c create mode 100644 posix/tst-cpucount.c diff --git a/ChangeLog b/ChangeLog index 8461b53..a5ed042 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-04-03 Ulrich Drepper + + * 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. + 2007-03-27 Jakub Jelinek * posix/fnmatch.c (STRUCT): Define. 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 +#include + + +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 +#include + +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" -- 2.7.4