summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2015-02-09 21:03:23 +0000
committerjhb <jhb@FreeBSD.org>2015-02-09 21:03:23 +0000
commitdbdaac6f208389f7cacab9fe319360b0f6e9095e (patch)
tree10fd6f8c5d3a008dd9724d177805fe95f87a6d69
parent0754f0eac9d97737274d7b77cb519abb250362b3 (diff)
downloadFreeBSD-src-dbdaac6f208389f7cacab9fe319360b0f6e9095e.zip
FreeBSD-src-dbdaac6f208389f7cacab9fe319360b0f6e9095e.tar.gz
Use __builtin_popcnt() to implement a BIT_COUNT() operation for bitsets and
use this to implement CPU_COUNT() to count the number of CPUs in a cpuset. MFC after: 2 weeks
-rw-r--r--sys/sys/bitset.h10
-rw-r--r--sys/sys/cpuset.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h
index e6c4dc3..9871c24 100644
--- a/sys/sys/bitset.h
+++ b/sys/sys/bitset.h
@@ -176,4 +176,14 @@
__bit; \
})
+#define BIT_COUNT(_s, p) __extension__ ({ \
+ __size_t __i; \
+ int __count; \
+ \
+ __count = 0; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ __count += __builtin_popcount((p)->__bits[__i]); \
+ __count; \
+})
+
#endif /* !_SYS_BITSET_H_ */
diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h
index d3d60e7..9ccba58 100644
--- a/sys/sys/cpuset.h
+++ b/sys/sys/cpuset.h
@@ -60,6 +60,7 @@
#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(CPU_SETSIZE, d, s)
#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(CPU_SETSIZE, f, t)
#define CPU_FFS(p) BIT_FFS(CPU_SETSIZE, p)
+#define CPU_COUNT(p) BIT_COUNT(CPU_SETSIZE, p)
/*
* Valid cpulevel_t values.
OpenPOWER on IntegriCloud