From owner-svn-src-projects@FreeBSD.ORG Thu Jul 29 02:05:06 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9DD631065675; Thu, 29 Jul 2010 02:05:06 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8D0408FC22; Thu, 29 Jul 2010 02:05:06 +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 o6T256bH097503; Thu, 29 Jul 2010 02:05:06 GMT (envelope-from jeff@svn.freebsd.org) Received: (from jeff@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6T256ix097500; Thu, 29 Jul 2010 02:05:06 GMT (envelope-from jeff@svn.freebsd.org) Message-Id: <201007290205.o6T256ix097500@svn.freebsd.org> From: Jeff Roberson Date: Thu, 29 Jul 2010 02:05:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210580 - projects/ofed/head/sys/ofed/include/linux X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2010 02:05:06 -0000 Author: jeff Date: Thu Jul 29 02:05:06 2010 New Revision: 210580 URL: http://svn.freebsd.org/changeset/base/210580 Log: - Use correct types for 'mask'. - Define non-long ffs/fls macros. - Correct set/clr bit offsets. - Add bitmap_empty(). - Use howmany and not roundup2 in BITS_TO_LONGS. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/ofed/include/linux/bitops.h projects/ofed/head/sys/ofed/include/linux/types.h Modified: projects/ofed/head/sys/ofed/include/linux/bitops.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/bitops.h Thu Jul 29 01:15:26 2010 (r210579) +++ projects/ofed/head/sys/ofed/include/linux/bitops.h Thu Jul 29 02:05:06 2010 (r210580) @@ -34,7 +34,19 @@ #define BITS_PER_LONG 32 #endif #define BIT_MASK(n) (~0UL >> (BITS_PER_LONG - (n))) -#define BITS_TO_LONGS(n) roundup2((n), BITS_PER_LONG) +#define BITS_TO_LONGS(n) howmany((n), BITS_PER_LONG) + +static inline int +__ffs(int mask) +{ + return (ffs(mask) - 1); +} + +static inline int +__fls(int mask) +{ + return (fls(mask) - 1); +} static inline int __ffsl(long mask) @@ -51,7 +63,7 @@ __flsl(long mask) static inline unsigned long find_first_bit(unsigned long *addr, unsigned long size) { - int mask; + long mask; int bit; for (bit = 0; size >= BITS_PER_LONG; @@ -73,7 +85,7 @@ find_first_bit(unsigned long *addr, unsi static inline unsigned long find_first_zero_bit(unsigned long *addr, unsigned long size) { - int mask; + long mask; int bit; for (bit = 0; size >= BITS_PER_LONG; @@ -95,7 +107,7 @@ find_first_zero_bit(unsigned long *addr, static inline unsigned long find_last_bit(unsigned long *addr, unsigned long size) { - int mask; + long mask; int offs; int bit; int pos; @@ -121,7 +133,7 @@ find_last_bit(unsigned long *addr, unsig static inline unsigned long find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset) { - int mask; + long mask; int offs; int bit; int pos; @@ -157,7 +169,7 @@ static inline unsigned long find_next_zero_bit(unsigned long *addr, unsigned long size, unsigned long offset) { - int mask; + long mask; int offs; int bit; int pos; @@ -194,7 +206,7 @@ bitmap_zero(unsigned long *addr, int siz { int len; - len = BITS_TO_LONGS(size) * sizeof(*addr); + len = BITS_TO_LONGS(size) * sizeof(long); memset(addr, 0, len); } @@ -204,16 +216,19 @@ bitmap_fill(unsigned long *addr, int siz int tail; int len; - len = BITS_TO_LONGS(size) * sizeof(*addr); + len = BITS_TO_LONGS(size) * sizeof(long); memset(addr, 0xff, len); tail = size & (BITS_PER_LONG - 1); - if (tail) - addr[len - 1] = ((unsigned long)-1) >> (BITS_PER_LONG - tail); + if (tail) { + len /= sizeof(long); + addr[len - 1] = ((unsigned long)-1L) >> (BITS_PER_LONG - tail); + } } static inline int bitmap_full(unsigned long *addr, int size) { + long mask; int tail; int len; int i; @@ -223,21 +238,44 @@ bitmap_full(unsigned long *addr, int siz if (addr[i] != (unsigned long)-1) return (0); tail = size & (BITS_PER_LONG - 1); - if (tail) - if (addr[i] != ((unsigned long)-1) >> (BITS_PER_LONG - tail)) + if (tail) { + mask = ((unsigned long)-1L) >> (BITS_PER_LONG - tail); + if ((addr[i] & mask) != mask) return (0); + } + return (1); +} + +static inline int +bitmap_empty(unsigned long *addr, int size) +{ + long mask; + int tail; + int len; + int i; + + len = size / BITS_PER_LONG; + for (i = 0; i < len; i++) + if (addr[i] != 0) + return (0); + tail = size & (BITS_PER_LONG - 1); + if (tail) { + mask = ((unsigned long)-1L) >> (BITS_PER_LONG - tail); + if ((addr[i] & mask) != 0) + return (0); + } return (1); } #define NBINT (NBBY * sizeof(int)) #define set_bit(i, a) \ - atomic_set_int((volatile int *)(a)[(i)/NBINT], (i) % NBINT) + atomic_set_int((volatile int *)&(a)[(i)/NBINT], 1 << (i) % NBINT) #define clear_bit(i, a) \ - atomic_clear_int((volatile int *)(a)[(i)/NBINT], (i) % NBINT) + atomic_clear_int((volatile int *)&(a)[(i)/NBINT], 1 << (i) % NBINT) #define test_bit(i, a) \ - !!(atomic_load_acq_int((volatile int *)(a)[(i)/NBINT]) & 1 << ((i) % NBINT)) + !!(atomic_load_acq_int((volatile int *)&(a)[(i)/NBINT]) & 1 << ((i) % NBINT)) #endif /* _LINUX_BITOPS_H_ */ Modified: projects/ofed/head/sys/ofed/include/linux/types.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/types.h Thu Jul 29 01:15:26 2010 (r210579) +++ projects/ofed/head/sys/ofed/include/linux/types.h Thu Jul 29 02:05:06 2010 (r210580) @@ -46,6 +46,6 @@ typedef unsigned gfp_t; typedef uint64_t loff_t; #define DECLARE_BITMAP(n, bits) \ - unsigned long n[howmany(howmany(bits, 8), sizeof(long) / 8)] + unsigned long n[howmany(bits, sizeof(long) * 8)] #endif /* _LINUX_TYPES_H_ */