Author: jhb Date: Mon Feb 9 21:03:23 2015 New Revision: 278474 URL: https://svnweb.freebsd.org/changeset/base/278474
Log: 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 Modified: head/sys/sys/bitset.h head/sys/sys/cpuset.h Modified: head/sys/sys/bitset.h ============================================================================== --- head/sys/sys/bitset.h Mon Feb 9 21:00:56 2015 (r278473) +++ head/sys/sys/bitset.h Mon Feb 9 21:03:23 2015 (r278474) @@ -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_ */ Modified: head/sys/sys/cpuset.h ============================================================================== --- head/sys/sys/cpuset.h Mon Feb 9 21:00:56 2015 (r278473) +++ head/sys/sys/cpuset.h Mon Feb 9 21:03:23 2015 (r278474) @@ -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. _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"