summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2010-05-27 13:32:12 +0200
committerKarel Zak2010-06-01 11:09:23 +0200
commitee32c514b5d61765a3ca6305d247b91fc8d15d0e (patch)
tree321c3f00376055c9957a439c5ce70b16dabe5fcf /lib
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 'lib')
-rw-r--r--lib/Makefile.am5
-rw-r--r--lib/cpuset.c33
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 93b79a5a7..c66deef0b 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,7 +3,10 @@ include $(top_srcdir)/config/include-Makefile.am
AM_CPPFLAGS += -DTEST_PROGRAM
noinst_PROGRAMS = test_blkdev test_ismounted test_wholedisk test_mangle \
- test_strtosize test_cpuset
+ test_strtosize
+if HAVE_CPU_SET_T
+noinst_PROGRAMS += test_cpuset
+endif
test_blkdev_SOURCES = blkdev.c
test_ismounted_SOURCES = ismounted.c
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 189c23ea3..d6cbf5d30 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -74,6 +74,39 @@ void cpuset_free(cpu_set_t *set)
CPU_FREE(set);
}
+#if !HAVE_DECL_CPU_ALLOC
+/* Please, use CPU_COUNT_S() macro. This is fallback */
+int __cpuset_count_s(size_t setsize, const cpu_set_t *set)
+{
+ int s = 0;
+ const __cpu_mask *p = set->__bits;
+ const __cpu_mask *end = &set->__bits[setsize / sizeof (__cpu_mask)];
+
+ while (p < end) {
+ __cpu_mask l = *p++;
+
+ 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;
+}
+#endif
+
/*
* Returns human readable representation of the cpuset. The output format is
* a list of CPUs with ranges (for example, "0,1,3-9").