Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Feb 2015 21:03:24 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r278474 - head/sys/sys
Message-ID:  <201502092103.t19L3OAn013792@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502092103.t19L3OAn013792>