Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

radix tree test suite: use common find-bit code

Remove the old find_next_bit code in favour of linking in the find_bit
code from tools/lib.

Link: http://lkml.kernel.org/r/1480369871-5271-48-git-send-email-mawilcox@linuxonhyperv.com
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Matthew Wilcox and committed by
Linus Torvalds
0629573e b328daf3

+48 -80
+6 -1
tools/testing/radix-tree/Makefile
··· 18 18 clean: 19 19 $(RM) -f $(TARGETS) *.o radix-tree.c 20 20 21 - $(OFILES): *.h */*.h ../../../include/linux/radix-tree.h ../../include/linux/*.h 21 + find_next_bit.o: ../../lib/find_bit.c 22 + $(CC) $(CFLAGS) -c -o $@ $< 23 + 24 + $(OFILES): *.h */*.h \ 25 + ../../include/linux/*.h \ 26 + ../../../include/linux/radix-tree.h 22 27 23 28 radix-tree.c: ../../../lib/radix-tree.c 24 29 sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@
-57
tools/testing/radix-tree/find_next_bit.c
··· 1 - /* find_next_bit.c: fallback find next bit implementation 2 - * 3 - * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. 4 - * Written by David Howells (dhowells@redhat.com) 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; either version 9 - * 2 of the License, or (at your option) any later version. 10 - */ 11 - 12 - #include <linux/types.h> 13 - #include <linux/bitops.h> 14 - 15 - #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 16 - 17 - /* 18 - * Find the next set bit in a memory region. 19 - */ 20 - unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 21 - unsigned long offset) 22 - { 23 - const unsigned long *p = addr + BITOP_WORD(offset); 24 - unsigned long result = offset & ~(BITS_PER_LONG-1); 25 - unsigned long tmp; 26 - 27 - if (offset >= size) 28 - return size; 29 - size -= result; 30 - offset %= BITS_PER_LONG; 31 - if (offset) { 32 - tmp = *(p++); 33 - tmp &= (~0UL << offset); 34 - if (size < BITS_PER_LONG) 35 - goto found_first; 36 - if (tmp) 37 - goto found_middle; 38 - size -= BITS_PER_LONG; 39 - result += BITS_PER_LONG; 40 - } 41 - while (size & ~(BITS_PER_LONG-1)) { 42 - if ((tmp = *(p++))) 43 - goto found_middle; 44 - result += BITS_PER_LONG; 45 - size -= BITS_PER_LONG; 46 - } 47 - if (!size) 48 - return result; 49 - tmp = *p; 50 - 51 - found_first: 52 - tmp &= (~0UL >> (BITS_PER_LONG - size)); 53 - if (tmp == 0UL) /* Are any bits set? */ 54 - return result + size; /* Nope. */ 55 - found_middle: 56 - return result + __ffs(tmp); 57 - }
+25 -15
tools/testing/radix-tree/linux/bitops.h
··· 2 2 #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 3 3 4 4 #include <linux/types.h> 5 + #include <linux/bitops/find.h> 6 + #include <linux/bitops/hweight.h> 7 + #include <linux/kernel.h> 5 8 6 - #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 7 - #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 9 + #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 10 + #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) 11 + #define BITS_PER_BYTE 8 12 + #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) 8 13 9 14 /** 10 15 * __set_bit - Set a bit in memory ··· 22 17 */ 23 18 static inline void __set_bit(int nr, volatile unsigned long *addr) 24 19 { 25 - unsigned long mask = BITOP_MASK(nr); 26 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 20 + unsigned long mask = BIT_MASK(nr); 21 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 27 22 28 23 *p |= mask; 29 24 } 30 25 31 26 static inline void __clear_bit(int nr, volatile unsigned long *addr) 32 27 { 33 - unsigned long mask = BITOP_MASK(nr); 34 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 28 + unsigned long mask = BIT_MASK(nr); 29 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 35 30 36 31 *p &= ~mask; 37 32 } ··· 47 42 */ 48 43 static inline void __change_bit(int nr, volatile unsigned long *addr) 49 44 { 50 - unsigned long mask = BITOP_MASK(nr); 51 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 45 + unsigned long mask = BIT_MASK(nr); 46 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 52 47 53 48 *p ^= mask; 54 49 } ··· 64 59 */ 65 60 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 66 61 { 67 - unsigned long mask = BITOP_MASK(nr); 68 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 62 + unsigned long mask = BIT_MASK(nr); 63 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 69 64 unsigned long old = *p; 70 65 71 66 *p = old | mask; ··· 83 78 */ 84 79 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 85 80 { 86 - unsigned long mask = BITOP_MASK(nr); 87 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 81 + unsigned long mask = BIT_MASK(nr); 82 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 88 83 unsigned long old = *p; 89 84 90 85 *p = old & ~mask; ··· 95 90 static inline int __test_and_change_bit(int nr, 96 91 volatile unsigned long *addr) 97 92 { 98 - unsigned long mask = BITOP_MASK(nr); 99 - unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 93 + unsigned long mask = BIT_MASK(nr); 94 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 100 95 unsigned long old = *p; 101 96 102 97 *p = old ^ mask; ··· 110 105 */ 111 106 static inline int test_bit(int nr, const volatile unsigned long *addr) 112 107 { 113 - return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 108 + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 114 109 } 115 110 116 111 /** ··· 151 146 unsigned long find_next_bit(const unsigned long *addr, 152 147 unsigned long size, 153 148 unsigned long offset); 149 + 150 + static inline unsigned long hweight_long(unsigned long w) 151 + { 152 + return sizeof(w) == 4 ? hweight32(w) : hweight64(w); 153 + } 154 154 155 155 #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
+6 -7
tools/testing/radix-tree/linux/bitops/non-atomic.h
··· 3 3 4 4 #include <asm/types.h> 5 5 6 - #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 7 6 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 8 7 9 8 /** ··· 16 17 */ 17 18 static inline void __set_bit(int nr, volatile unsigned long *addr) 18 19 { 19 - unsigned long mask = BITOP_MASK(nr); 20 + unsigned long mask = BIT_MASK(nr); 20 21 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 21 22 22 23 *p |= mask; ··· 24 25 25 26 static inline void __clear_bit(int nr, volatile unsigned long *addr) 26 27 { 27 - unsigned long mask = BITOP_MASK(nr); 28 + unsigned long mask = BIT_MASK(nr); 28 29 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 29 30 30 31 *p &= ~mask; ··· 41 42 */ 42 43 static inline void __change_bit(int nr, volatile unsigned long *addr) 43 44 { 44 - unsigned long mask = BITOP_MASK(nr); 45 + unsigned long mask = BIT_MASK(nr); 45 46 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 46 47 47 48 *p ^= mask; ··· 58 59 */ 59 60 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 60 61 { 61 - unsigned long mask = BITOP_MASK(nr); 62 + unsigned long mask = BIT_MASK(nr); 62 63 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 63 64 unsigned long old = *p; 64 65 ··· 77 78 */ 78 79 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 79 80 { 80 - unsigned long mask = BITOP_MASK(nr); 81 + unsigned long mask = BIT_MASK(nr); 81 82 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 82 83 unsigned long old = *p; 83 84 ··· 89 90 static inline int __test_and_change_bit(int nr, 90 91 volatile unsigned long *addr) 91 92 { 92 - unsigned long mask = BITOP_MASK(nr); 93 + unsigned long mask = BIT_MASK(nr); 93 94 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 94 95 unsigned long old = *p; 95 96
+11
tools/testing/radix-tree/linux/kernel.h
··· 47 47 { 48 48 return 0; 49 49 } 50 + 51 + /* 52 + * This looks more complex than it should be. But we need to 53 + * get the type for the ~ right in round_down (it needs to be 54 + * as wide as the result!), and we want to evaluate the macro 55 + * arguments just once each. 56 + */ 57 + #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 58 + #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 59 + #define round_down(x, y) ((x) & ~__round_mask(x, y)) 60 + 50 61 #endif /* _KERNEL_H */