From e5f552b70dccbd2fdf21ec7b7053a01bcbe062c2 Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Wed, 16 Apr 2014 14:37:53 -0400 Subject: [PATCH] LU-3963 Revert bitops changes This reverts bitops portions of http://review.whamcloud.com/7803 commit 001b8dbfacb747f1649a2eb047a5f118ce32fdc7 The uncovered problem is such that previously used fls returned 0 for the case of no bits set where as __fls return value for such a case is undefined in the case of at least Linux kernel. Change-Id: I993674161b08791157781a2b1da0872b12358bb1 Signed-off-by: Oleg Drokin Reviewed-on: http://review.whamcloud.com/9978 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo --- libcfs/include/libcfs/user-bitops.h | 8 ++++---- libcfs/include/libcfs/winnt/portals_utils.h | 6 +++--- libcfs/libcfs/hash.c | 4 ++-- libcfs/libcfs/user-bitops.c | 8 ++++---- lustre/obdclass/lprocfs_status.c | 2 +- lustre/ofd/ofd_dev.c | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libcfs/include/libcfs/user-bitops.h b/libcfs/include/libcfs/user-bitops.h index 7b31bc9..1b16ca77 100644 --- a/libcfs/include/libcfs/user-bitops.h +++ b/libcfs/include/libcfs/user-bitops.h @@ -76,7 +76,7 @@ static inline int test_bit(int nr, const unsigned long *addr) } /* using binary seach */ -static inline unsigned long __fls(long data) +static __inline__ unsigned long fls(long data) { int pos = 32; @@ -115,7 +115,7 @@ static inline unsigned long __fls(long data) return pos; } -static inline unsigned long __ffs(long data) +static __inline__ unsigned long __cfs_ffs(long data) { int pos = 0; @@ -147,8 +147,8 @@ static inline unsigned long __ffs(long data) return pos; } -#define __ffz(x) __ffs(~(x)) -#define __flz(x) __fls(~(x)) +#define ffz(x) ffs(~(x)) +#define flz(x) fls(~(x)) unsigned long find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset); diff --git a/libcfs/include/libcfs/winnt/portals_utils.h b/libcfs/include/libcfs/winnt/portals_utils.h index b8678d9..39ab41f 100644 --- a/libcfs/include/libcfs/winnt/portals_utils.h +++ b/libcfs/include/libcfs/winnt/portals_utils.h @@ -141,7 +141,7 @@ static inline int ffs(int x) return r; } -static inline unsigned long __ffs(unsigned long word) +static inline unsigned long __cfs_ffs(unsigned long word) { int num = 0; @@ -180,7 +180,7 @@ static inline unsigned long __ffs(unsigned long word) * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. */ static inline -int __fls(int x) +int fls(int x) { int r = 32; @@ -217,7 +217,7 @@ static inline unsigned find_first_bit(const unsigned long *addr, while (x < size) { unsigned long val = *addr++; if (val) - return __ffs(val) + x; + return __cfs_ffs(val) + x; x += (sizeof(*addr)<<3); } return x; diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index af0b3a9..0c4faf8 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -2131,7 +2131,7 @@ int cfs_hash_debug_str(cfs_hash_t *hs, char *str, int size) #endif } total += bd.bd_bucket->hsb_count; - dist[min(__fls(bd.bd_bucket->hsb_count/max(theta,1)),7UL)]++; + dist[min(fls(bd.bd_bucket->hsb_count/max(theta,1)),7)]++; cfs_hash_bd_unlock(hs, &bd, 0); } @@ -2200,7 +2200,7 @@ int cfs_hash_debug_str_seq(cfs_hash_t *hs, struct seq_file *m) #endif } total += bd.bd_bucket->hsb_count; - dist[min(__fls(bd.bd_bucket->hsb_count/max(theta,1)),7UL)]++; + dist[min(fls(bd.bd_bucket->hsb_count/max(theta,1)),7)]++; cfs_hash_bd_unlock(hs, &bd, 0); } diff --git a/libcfs/libcfs/user-bitops.c b/libcfs/libcfs/user-bitops.c index 26228ee..65f2da9 100644 --- a/libcfs/libcfs/user-bitops.c +++ b/libcfs/libcfs/user-bitops.c @@ -55,7 +55,7 @@ unsigned long find_next_bit(unsigned long *addr, return size; if (first_bit != 0) { int tmp = (*word++) & (~0UL << first_bit); - bit = __ffs(tmp); + bit = __cfs_ffs(tmp); if (bit < BITS_PER_LONG) goto found; word++; @@ -63,7 +63,7 @@ unsigned long find_next_bit(unsigned long *addr, } while (word <= last) { if (*word != 0UL) { - bit = __ffs(*word); + bit = __cfs_ffs(*word); goto found; } word++; @@ -89,7 +89,7 @@ unsigned long find_next_zero_bit(unsigned long *addr, return size; if (first_bit != 0) { int tmp = (*word++) & (~0UL << first_bit); - bit = __ffz(tmp); + bit = ffz(tmp); if (bit < BITS_PER_LONG) goto found; word++; @@ -97,7 +97,7 @@ unsigned long find_next_zero_bit(unsigned long *addr, } while (word <= last) { if (*word != ~0UL) { - bit = __ffz(*word); + bit = ffz(*word); goto found; } word++; diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 9527bb2..9956ada 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -3281,7 +3281,7 @@ void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) unsigned int val = 0; if (likely(value != 0)) - val = min_t(unsigned int, __fls(value - 1), OBD_HIST_MAX); + val = min(fls(value - 1), OBD_HIST_MAX); lprocfs_oh_tally(oh, val); } diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index d7ca3f4..3166fb7 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -2200,7 +2200,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, obd->obd_name, osfs->os_bsize); GOTO(err_fini_stack, rc = -EPROTO); } - m->ofd_blockbits = __fls(osfs->os_bsize) - 1; + m->ofd_blockbits = fls(osfs->os_bsize) - 1; m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT; if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS) -- 1.8.3.1