summaryrefslogtreecommitdiffstats
path: root/include/cpuset.h
diff options
context:
space:
mode:
authorKarel Zak2010-05-27 13:32:12 +0200
committerKarel Zak2010-06-01 11:09:23 +0200
commitee32c514b5d61765a3ca6305d247b91fc8d15d0e (patch)
tree321c3f00376055c9957a439c5ce70b16dabe5fcf /include/cpuset.h
parenttaskset: use libc based cpu_set_t (diff)
downloadkernel-qcow2-util-linux-ee32c514b5d61765a3ca6305d247b91fc8d15d0e.tar.gz
kernel-qcow2-util-linux-ee32c514b5d61765a3ca6305d247b91fc8d15d0e.tar.xz
kernel-qcow2-util-linux-ee32c514b5d61765a3ca6305d247b91fc8d15d0e.zip
lib: add fallback for libc (uClibc) without CPU_ALLOC
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/cpuset.h')
-rw-r--r--include/cpuset.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/cpuset.h b/include/cpuset.h
index bc7961cad..197476ed9 100644
--- a/include/cpuset.h
+++ b/include/cpuset.h
@@ -3,6 +3,51 @@
#include <sched.h>
+/*
+ * Fallback for old or obscure libcs without dynamically allocated cpusets
+ *
+ * The following macros are based on code from glibc.
+ *
+ * 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.
+ */
+#if !HAVE_DECL_CPU_ALLOC
+
+# define CPU_ZERO_S(setsize, cpusetp) \
+ do { \
+ size_t __i; \
+ size_t __imax = (setsize) / sizeof (__cpu_mask); \
+ __cpu_mask *__bits = (cpusetp)->__bits; \
+ for (__i = 0; __i < __imax; ++__i) \
+ __bits[__i] = 0; \
+ } while (0)
+
+# define CPU_SET_S(cpu, setsize, cpusetp) \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
+ |= __CPUMASK (__cpu)) \
+ : 0; })
+
+# define CPU_ISSET_S(cpu, setsize, cpusetp) \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
+ & __CPUMASK (__cpu))) != 0 \
+ : 0; })
+
+extern int __cpuset_count_s(size_t setsize, const cpu_set_t *set);
+# define CPU_COUNT_S(setsize, cpusetp) __cpuset_count_s(setsize, cpusetp)
+
+# define CPU_ALLOC_SIZE(count) \
+ ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
+# define CPU_ALLOC(count) (malloc(CPU_ALLOC_SIZE(count)))
+# define CPU_FREE(cpuset) (free(cpuset))
+
+#endif /* !HAVE_DECL_CPU_ALLOC */
+
#define cpuset_nbits(setsize) (8 * (setsize))