From b160368a9727b3d2f9edb6ec1c42f02c7a05ba72 Mon Sep 17 00:00:00 2001 From: walter Date: Thu, 20 Dec 2007 23:02:07 +0000 Subject: [PATCH] b=14390 i=adilger fixes problem where b1_4 does not build on xt3 due to missing uint32_t defn in lnet/libcfs/user-bitops.c --- lnet/include/libcfs/bitmap.h | 11 +++--- lnet/include/libcfs/user-bitops.h | 72 ++++++++++++++++++++++++++++++++++++--- lnet/libcfs/user-bitops.c | 50 +++++++++++++-------------- lnet/libcfs/user-prim.c | 7 ---- 4 files changed, 97 insertions(+), 43 deletions(-) diff --git a/lnet/include/libcfs/bitmap.h b/lnet/include/libcfs/bitmap.h index b9e6e18..64ee0e3 100644 --- a/lnet/include/libcfs/bitmap.h +++ b/lnet/include/libcfs/bitmap.h @@ -28,24 +28,24 @@ typedef struct { unsigned long data[0]; } bitmap_t; -#define BITMAP_SIZE(nbits) (((nbits/BITS_PER_LONG)+1)*sizeof(long)+sizeof(bitmap_t)) +#define CFS_BITMAP_SIZE(nbits) \ + (((nbits/BITS_PER_LONG)+1)*sizeof(long)+sizeof(bitmap_t)) static inline bitmap_t *ALLOCATE_BITMAP(int size) { bitmap_t *ptr; - OBD_ALLOC(ptr, BITMAP_SIZE(size)); + OBD_ALLOC(ptr, CFS_BITMAP_SIZE(size)); if (ptr == NULL) RETURN(ptr); ptr->size = size; - memset(ptr->data, 0, BITMAP_SIZE(size)); RETURN (ptr); } -#define FREE_BITMAP(ptr) OBD_FREE(ptr, BITMAP_SIZE(ptr->size)) +#define FREE_BITMAP(ptr) OBD_FREE(ptr, CFS_BITMAP_SIZE(ptr->size)) static inline void bitmap_set(bitmap_t *bitmap, int nbit) @@ -62,8 +62,7 @@ void bitmap_clear(bitmap_t *bitmap, int nbit) static inline int bitmap_check(bitmap_t *bitmap, int nbit) { - int pos = nbit % BITS_PER_LONG; - return test_bit(pos, bitmap->data+(nbit/BITS_PER_LONG)); + return test_bit(nbit, bitmap->data); } /* return 0 is bitmap has none set bits */ diff --git a/lnet/include/libcfs/user-bitops.h b/lnet/include/libcfs/user-bitops.h index f6034c3..272bcf2 100644 --- a/lnet/include/libcfs/user-bitops.h +++ b/lnet/include/libcfs/user-bitops.h @@ -26,11 +26,75 @@ #ifndef __LIBCFS_USER_BITOPS_H__ #define __LIBCFS_USER_BITOPS_H__ -unsigned long find_next_bit(const unsigned int *addr, - unsigned long size, unsigned long offset); +/* test if bit nr is set in bitmap addr; returns previous value of bit nr */ +static __inline__ int set_bit(int nr, long * addr) +{ + long mask; -unsigned long find_next_zero_bit(const unsigned int *addr, - unsigned long size, unsigned long offset); + addr += nr / BITS_PER_LONG; + mask = 1UL << (nr & (BITS_PER_LONG - 1)); + nr = (mask & *addr) != 0; + *addr |= mask; + return nr; +} + +/* clear bit nr in bitmap addr; returns previous value of bit nr*/ +static __inline__ int clear_bit(int nr, long * addr) +{ + long mask; + + addr += nr / BITS_PER_LONG; + mask = 1UL << (nr & (BITS_PER_LONG - 1)); + nr = (mask & *addr) != 0; + *addr &= ~mask; + return nr; +} + +static __inline__ int test_bit(int nr, long * addr) +{ + return ((1UL << (nr & (BITS_PER_LONG - 1))) & ((addr)[nr / BITS_PER_LONG])) != 0; +} + +/* using binary seach */ +static __inline__ unsigned long __ffs(long data) +{ + int pos = 0; + +#if BITS_PER_LONG == 64 + if ((data & 0xFFFFFFFF) == 0) { + pos += 32; + data >>= 32; + } +#endif + if ((data & 0xFFFF) == 0) { + pos += 16; + data >>= 16; + } + if ((data & 0xFF) == 0) { + pos += 8; + data >>= 8; + } + if ((data & 0xF) == 0) { + pos += 4; + data >>= 4; + } + if ((data & 0x3) == 0) { + pos += 2; + data >>= 2; + } + if ((data & 0x1) == 0) + pos += 1; + + return pos; +} + +#define __ffz(x) __ffs(~(x)) + +unsigned long find_next_bit(unsigned long *addr, + unsigned long size, unsigned long offset); + +unsigned long find_next_zero_bit(unsigned long *addr, + unsigned long size, unsigned long offset); #define find_first_bit(addr,size) (find_next_bit((addr),(size),0)) #define find_first_zero_bit(addr,size) (find_next_zero_bit((addr),(size),0)) diff --git a/lnet/libcfs/user-bitops.c b/lnet/libcfs/user-bitops.c index 2c252e8..8f94593 100644 --- a/lnet/libcfs/user-bitops.c +++ b/lnet/libcfs/user-bitops.c @@ -23,74 +23,72 @@ #include #include +#include -#include /* for ffs - confirm POSIX */ +#define OFF_BY_START(start) ((start)/BITS_PER_LONG) -#define BITS_PER_WORD 32 -#define OFF_BY_START(start) ((start)/BITS_PER_WORD) - -unsigned long find_next_bit(const unsigned int *addr, - unsigned long size, unsigned long offset) +unsigned long find_next_bit(unsigned long *addr, + unsigned long size, unsigned long offset) { - uint32_t *word, *last; - unsigned int first_bit, bit, base; + unsigned long *word, *last; + unsigned long first_bit, bit, base; word = addr + OFF_BY_START(offset); last = addr + OFF_BY_START(size-1); - first_bit = offset % BITS_PER_WORD; + first_bit = offset % BITS_PER_LONG; base = offset - first_bit; if (offset >= size) return size; if (first_bit != 0) { int tmp = (*word++) & (~0UL << first_bit); - bit = ffs(tmp); - if (bit < BITS_PER_WORD) + bit = __ffs(tmp); + if (bit < BITS_PER_LONG) goto found; word++; - base += BITS_PER_WORD; + base += BITS_PER_LONG; } while (word <= last) { - if (*word != 0ul) { - bit = ffs(*word); + if (*word != 0UL) { + bit = __ffs(*word); goto found; } word++; - base += BITS_PER_WORD; + base += BITS_PER_LONG; } return size; found: return base + bit; } -unsigned long find_next_zero_bit(const unsigned int *addr, - unsigned long size, unsigned long offset) +unsigned long find_next_zero_bit(unsigned long *addr, + unsigned long size, unsigned long offset) { - uint32_t *word, *last; - unsigned int first_bit, bit, base; + unsigned long *word, *last; + unsigned long first_bit, bit, base; word = addr + OFF_BY_START(offset); last = addr + OFF_BY_START(size-1); - first_bit = offset % BITS_PER_WORD; + first_bit = offset % BITS_PER_LONG; base = offset - first_bit; if (offset >= size) return size; if (first_bit != 0) { int tmp = (*word++) & (~0UL << first_bit); - bit = ffs(~tmp); - if (bit < BITS_PER_WORD) + bit = __ffz(tmp); + if (bit < BITS_PER_LONG) goto found; word++; - base += BITS_PER_WORD; + base += BITS_PER_LONG; } while (word <= last) { - if (*word != ~0ul) { - bit = ffs(*word); + if (*word != ~0UL) { + bit = __ffz(*word); goto found; } word++; - base += BITS_PER_WORD; + base += BITS_PER_LONG; } return size; found: diff --git a/lnet/libcfs/user-prim.c b/lnet/libcfs/user-prim.c index d363718..2dad1b3 100644 --- a/lnet/libcfs/user-prim.c +++ b/lnet/libcfs/user-prim.c @@ -276,13 +276,6 @@ void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr) cfs_free(addr); } -/* - * This uses user-visible declarations from - */ -#ifdef __linux__ -#include -#endif - void cfs_enter_debugger(void) { /* -- 1.8.3.1