mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-05 17:11:06 +00:00
* 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.
This commit is contained in:
parent
9700b0390e
commit
eab1bdfb8e
@ -1,3 +1,11 @@
|
|||||||
|
2007-04-03 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* 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 <jakub@redhat.com>
|
2007-03-27 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* posix/fnmatch.c (STRUCT): Define.
|
* posix/fnmatch.c (STRUCT): Define.
|
||||||
|
@ -66,7 +66,7 @@ routines := \
|
|||||||
spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
|
spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
|
||||||
spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
|
spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
|
||||||
posix_madvise \
|
posix_madvise \
|
||||||
get_child_max
|
get_child_max sched_cpucount
|
||||||
|
|
||||||
include ../Makeconfig
|
include ../Makeconfig
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ tests := tstgetopt testfnm runtests runptests \
|
|||||||
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
|
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
|
||||||
tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
|
tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
|
||||||
tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
|
tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
|
||||||
tst-getaddrinfo3 tst-fnmatch2
|
tst-getaddrinfo3 tst-fnmatch2 tst-cpucount
|
||||||
xtests := bug-ga2
|
xtests := bug-ga2
|
||||||
ifeq (yes,$(build-shared))
|
ifeq (yes,$(build-shared))
|
||||||
test-srcs := globtest
|
test-srcs := globtest
|
||||||
|
@ -122,6 +122,9 @@ libc {
|
|||||||
GLIBC_2.3.4 {
|
GLIBC_2.3.4 {
|
||||||
regexec;
|
regexec;
|
||||||
}
|
}
|
||||||
|
GLIBC_2.6 {
|
||||||
|
__sched_cpucount;
|
||||||
|
}
|
||||||
GLIBC_PRIVATE {
|
GLIBC_PRIVATE {
|
||||||
__libc_fork; __libc_pwrite;
|
__libc_fork; __libc_pwrite;
|
||||||
}
|
}
|
||||||
|
52
posix/sched_cpucount.c
Normal file
52
posix/sched_cpucount.c
Normal file
@ -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;
|
||||||
|
}
|
27
posix/tst-cpucount.c
Normal file
27
posix/tst-cpucount.c
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user