From patchwork Mon Oct 20 17:03:46 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Travis X-Patchwork-Id: 5100 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 69C2ADEAB2 for ; Tue, 21 Oct 2008 04:10:55 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from relay.sgi.com (relay1.sgi.com [192.48.171.29]) by ozlabs.org (Postfix) with ESMTP id 5F8E7DDF00 for ; Tue, 21 Oct 2008 04:03:26 +1100 (EST) Received: from polaris-admin.engr.sgi.com (polaris-admin.engr.sgi.com [192.102.97.111]) by relay1.corp.sgi.com (Postfix) with ESMTP id 91F808F8114; Mon, 20 Oct 2008 10:03:23 -0700 (PDT) Received: by polaris-admin.engr.sgi.com (Postfix, from userid 5508) id 6EFAC517CAFC; Mon, 20 Oct 2008 10:03:23 -0700 (PDT) Message-Id: <20081020170323.335697000@polaris-admin.engr.sgi.com> References: <20081020170319.539427000@polaris-admin.engr.sgi.com> User-Agent: quilt/0.46-1 Date: Mon, 20 Oct 2008 10:03:46 -0700 From: Mike Travis To: Ingo Molnar , Rusty Russell Subject: [PATCH 27/35] cpumask: to_cpumask() Content-Disposition: inline; filename=cpumask:to_cpumask.patch Cc: davej@codemonkey.org.uk, Jeremy Fitzhardinge , Jes Sorensen , IA64 , S390 , peterz@infradead.org, Jack Steiner , linux-kernel@vger.kernel.org, Eric Dumazet , PowerPC , Andi Kleen , Thomas Gleixner , Yinghai Lu , "H. Peter Anvin" , SPARC , Andrew Morton , David Miller X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org There are times when we really want a static cpumask. Yet we don't want to expose the struct cpumask definition, to avoid casual on-stack usage and assignment. So this macro allows you to do DECLARE_BITMAP(map, CONFIG_NR_CPUS); then use to_cpumask() to turn it into a cpumask as needed. Ugly? Yes, but as we move to fewer static cpumasks these calls vanish. From: Rusty Russell Signed-off-by: Rusty Russell Signed-off-by: Mike Travis --- include/linux/cpumask.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- linux-2.6.28.orig/include/linux/cpumask.h +++ linux-2.6.28/include/linux/cpumask.h @@ -57,6 +57,9 @@ * CPU_MASK_NONE Initializer - no bits set * unsigned long *cpumask_bits(mask) Array of unsigned long's in mask * + * struct cpumask *to_cpumask(const unsigned long[]) + * Convert a bitmap to a cpumask. + * * ------------------------------------------------------------------------ * * int cpumask_scnprintf(buf, len, mask) Format cpumask for printing @@ -362,6 +365,17 @@ static inline void cpumask_copy(struct c #define cpumask_any(srcp) cpumask_first(srcp) #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2)) +/* Used for static bitmaps of CONFIG_NR_CPUS bits. Must be a constant to use + * as an initializer. */ +#define to_cpumask(bitmap) \ + ((struct cpumask *)(1 ? (bitmap) \ + : (void *)sizeof(__check_is_bitmap(bitmap)))) + +static inline int __check_is_bitmap(const unsigned long *bitmap) +{ + return 1; +} + /* * Special-case data structure for "single bit set only" constant CPU masks. *