aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--posix/Makefile4
-rw-r--r--posix/Versions3
-rw-r--r--posix/sched_cpualloc.c27
-rw-r--r--posix/sched_cpufree.c27
-rw-r--r--posix/tst-cpuset.c82
-rw-r--r--sysdeps/unix/sysv/linux/bits/sched.h57
7 files changed, 200 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 9048743..59fbdab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-07-29 Ulrich Drepper <drepper@redhat.com>
+
+ * posix/Makefile (routines): Add sched_cpualloc and sched_cpufree.
+ (tests): Add tst-cpuset.
+ * posix/sched_cpualloc.c: New file.
+ * posix/sched_cpufree.c: New file.
+ * posix/tst-cpuset.c: New file.
+ * posix/Versions: Export __sched_cpualloc and __sched_cpufree for
+ GLIBC_2.7.
+ * sysdeps/unix/sysv/linux/bits/sched.h: Define __CPU_*_S macros.
+ * posix/sched.h: Define old CPU_* macros in temers of __CPU_*_S
+ macros. Define CPU_*_S macros.
+
2007-07-28 Ulrich Drepper <drepper@redhat.com>
* posix/getconf.c (vars): Add missing _SC_LEVEL4_CACHE_LINESIZE
diff --git a/posix/Makefile b/posix/Makefile
index 010ab2d..1a1d2bc 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 sched_cpucount
+ get_child_max sched_cpucount sched_cpualloc sched_cpufree
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-cpucount
+ tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset
xtests := bug-ga2
ifeq (yes,$(build-shared))
test-srcs := globtest
diff --git a/posix/Versions b/posix/Versions
index 1e1bda8..f73ff4a 100644
--- a/posix/Versions
+++ b/posix/Versions
@@ -125,6 +125,9 @@ libc {
GLIBC_2.6 {
__sched_cpucount;
}
+ GLIBC_2.7 {
+ __sched_cpualloc; __sched_cpufree;
+ }
GLIBC_PRIVATE {
__libc_fork; __libc_pwrite;
}
diff --git a/posix/sched_cpualloc.c b/posix/sched_cpualloc.c
new file mode 100644
index 0000000..2642a80
--- /dev/null
+++ b/posix/sched_cpualloc.c
@@ -0,0 +1,27 @@
+/* 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 <sched.h>
+#include <stdlib.h>
+
+
+cpu_set_t *
+__sched_cpualloc (size_t count)
+{
+ return malloc (CPU_ALLOC_SIZE (count));
+}
diff --git a/posix/sched_cpufree.c b/posix/sched_cpufree.c
new file mode 100644
index 0000000..dd4c613
--- /dev/null
+++ b/posix/sched_cpufree.c
@@ -0,0 +1,27 @@
+/* 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 <sched.h>
+#include <stdlib.h>
+
+
+void
+__sched_cpufree (cpu_set_t *set)
+{
+ free (set);
+}
diff --git a/posix/tst-cpuset.c b/posix/tst-cpuset.c
new file mode 100644
index 0000000..d736793
--- /dev/null
+++ b/posix/tst-cpuset.c
@@ -0,0 +1,82 @@
+#include <sched.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+ int result = 0;
+
+ cpu_set_t s1;
+ cpu_set_t s2;
+ cpu_set_t s3;
+
+ CPU_ZERO (&s1);
+ CPU_SET (0, &s1);
+
+ CPU_ZERO (&s2);
+ CPU_SET (0, &s2);
+ CPU_SET (1, &s2);
+
+ CPU_AND (&s3, &s1, &s2);
+ if (! CPU_EQUAL (&s3, &s1))
+ {
+ puts ("result of CPU_AND wrong");
+ result = 1;
+ }
+
+ CPU_OR (&s3, &s1, &s2);
+ if (! CPU_EQUAL (&s3, &s2))
+ {
+ puts ("result of CPU_OR wrong");
+ result = 1;
+ }
+
+ CPU_XOR (&s3, &s1, &s2);
+ if (CPU_COUNT (&s3) != 1)
+ {
+ puts ("result of CPU_XOR wrong");
+ result = 1;
+ }
+
+ cpu_set_t *vs1 = CPU_ALLOC (2048);
+ cpu_set_t *vs2 = CPU_ALLOC (2048);
+ cpu_set_t *vs3 = CPU_ALLOC (2048);
+ size_t vssize = CPU_ALLOC_SIZE (2048);
+
+ CPU_ZERO_S (vssize, vs1);
+ CPU_SET_S (0, vssize, vs1);
+
+ CPU_ZERO_S (vssize, vs2);
+ CPU_SET_S (0, vssize, vs2);
+ CPU_SET_S (2047, vssize, vs2);
+
+ CPU_AND_S (vssize, vs3, vs1, vs2);
+ if (! CPU_EQUAL_S (vssize, vs3, vs1))
+ {
+ puts ("result of CPU_AND_S wrong");
+ result = 1;
+ }
+
+ CPU_OR_S (vssize, vs3, vs1, vs2);
+ if (! CPU_EQUAL_S (vssize, vs3, vs2))
+ {
+ puts ("result of CPU_OR_S wrong");
+ result = 1;
+ }
+
+ CPU_XOR_S (vssize, vs3, vs1, vs2);
+ if (CPU_COUNT_S (vssize, vs3) != 1)
+ {
+ puts ("result of CPU_XOR_S wrong");
+ result = 1;
+ }
+
+ CPU_FREE (vs1);
+ CPU_FREE (vs2);
+ CPU_FREE (vs3);
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index d3c21ae..b19822c 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -118,27 +118,62 @@ typedef struct
} cpu_set_t;
/* Access functions for CPU masks. */
-# define __CPU_ZERO(cpusetp) \
+# define __CPU_ZERO_S(setsize, cpusetp) \
do { \
- unsigned int __i; \
+ size_t __i; \
+ size_t __imax = (setsize) / sizeof (__cpu_mask); \
cpu_set_t *__arr = (cpusetp); \
- for (__i = 0; __i < sizeof (cpu_set_t) / sizeof (__cpu_mask); ++__i) \
+ for (__i = 0; __i < __imax; ++__i) \
__arr->__bits[__i] = 0; \
} while (0)
-# define __CPU_SET(cpu, cpusetp) \
- ((cpusetp)->__bits[__CPUELT (cpu)] |= __CPUMASK (cpu))
-# define __CPU_CLR(cpu, cpusetp) \
- ((cpusetp)->__bits[__CPUELT (cpu)] &= ~__CPUMASK (cpu))
-# define __CPU_ISSET(cpu, cpusetp) \
- (((cpusetp)->__bits[__CPUELT (cpu)] & __CPUMASK (cpu)) != 0)
+# define __CPU_SET_S(cpu, setsize, cpusetp) \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? ((cpusetp)->__bits[__CPUELT (__cpu)] |= __CPUMASK (__cpu)) : 0; })
+# define __CPU_CLR_S(cpu, setsize, cpusetp) \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? ((cpusetp)->__bits[__CPUELT (__cpu)] &= ~__CPUMASK (__cpu)) : 0; })
+# define __CPU_ISSET_S(cpu, setsize, cpusetp) \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? (((cpusetp)->__bits[__CPUELT (__cpu)] & __CPUMASK (__cpu))) != 0 : 0; })
+
+# define __CPU_COUNT_S(setsize, cpusetp) \
+ __sched_cpucount (setsize, cpusetp)
+
+# define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
+ ({ cpu_set_t *__arr1 = (cpusetp1); \
+ cpu_set_t *__arr2 = (cpusetp2); \
+ size_t __imax = (setsize) / sizeof (__cpu_mask); \
+ size_t __i; \
+ for (__i = 0; __i < __imax; ++__i) \
+ if (__arr1->__bits[__i] != __arr2->__bits[__i]) \
+ break; \
+ __i == __imax; })
+
+# define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
+ ({ cpu_set_t *__dest = (destset); \
+ cpu_set_t *__arr1 = (srcset1); \
+ cpu_set_t *__arr2 = (srcset2); \
+ size_t __imax = (setsize) / sizeof (__cpu_mask); \
+ size_t __i; \
+ for (__i = 0; __i < __imax; ++__i) \
+ __dest->__bits[__i] = __arr1->__bits[__i] op __arr2->__bits[__i]; \
+ __dest; })
+
+# define __CPU_ALLOC_SIZE(count) \
+ ((((count) + __NCPUBITS - 1) / __NCPUBITS) * 8)
+# define __CPU_ALLOC(count) __sched_cpualloc (count)
+# define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
__BEGIN_DECLS
extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
__THROW;
+extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
+extern void __sched_cpufree (cpu_set_t *__set) __THROW;
__END_DECLS
-# define __CPU_COUNT(cpusetp) \
- __sched_cpucount (sizeof (cpu_set_t), cpusetp)
#endif