From owner-svn-src-stable-7@FreeBSD.ORG Sat Nov 6 15:10:31 2010 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F86F1065672; Sat, 6 Nov 2010 15:10:31 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 731B38FC15; Sat, 6 Nov 2010 15:10:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oA6FAVnY035112; Sat, 6 Nov 2010 15:10:31 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oA6FAV1I035110; Sat, 6 Nov 2010 15:10:31 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201011061510.oA6FAV1I035110@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 6 Nov 2010 15:10:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214887 - stable/7/sys/sys X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Nov 2010 15:10:31 -0000 Author: lstewart Date: Sat Nov 6 15:10:31 2010 New Revision: 214887 URL: http://svn.freebsd.org/changeset/base/214887 Log: MFC r209050 (originally committed by jhb): Add helper macros to iterate over available CPUs in the system. CPU_FOREACH(i) iterates over the CPU IDs of all available CPUs. The CPU_FIRST() and CPU_NEXT(i) macros can also be used to iterate over available CPU IDs. CPU_NEXT(i) wraps around to CPU_FIRST() rather than returning some sort of terminator. Requested by: rwatson Reviewed by: attilio Modified: stable/7/sys/sys/smp.h Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/sys/smp.h ============================================================================== --- stable/7/sys/sys/smp.h Sat Nov 6 15:04:56 2010 (r214886) +++ stable/7/sys/sys/smp.h Sat Nov 6 15:10:31 2010 (r214887) @@ -68,6 +68,44 @@ extern cpumask_t all_cpus; */ #define CPU_ABSENT(x_cpu) ((all_cpus & (1 << (x_cpu))) == 0) +/* + * Macros to iterate over non-absent CPUs. CPU_FOREACH() takes an + * integer iterator and iterates over the available set of CPUs. + * CPU_FIRST() returns the id of the first non-absent CPU. CPU_NEXT() + * returns the id of the next non-absent CPU. It will wrap back to + * CPU_FIRST() once the end of the list is reached. The iterators are + * currently implemented via inline functions. + */ +#define CPU_FOREACH(i) \ + for ((i) = 0; (i) <= mp_maxid; (i)++) \ + if (!CPU_ABSENT((i))) + +static __inline int +cpu_first(void) +{ + int i; + + for (i = 0;; i++) + if (!CPU_ABSENT(i)) + return (i); +} + +static __inline int +cpu_next(int i) +{ + + for (;;) { + i++; + if (i > mp_maxid) + i = 0; + if (!CPU_ABSENT(i)) + return (i); + } +} + +#define CPU_FIRST() cpu_first() +#define CPU_NEXT(i) cpu_next((i)) + #ifdef SMP /* * Machine dependent functions used to initialize MP support.