aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@linux.intel.com>2016-12-14 18:08:29 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-14 19:04:10 -0500
commit0629573e6bbd60f20ed2d7a91da1214a6274e751 (patch)
treeaed29e29406c6250a834586b2a45f84152db7c80 /tools/testing
parentb328daf3b7130098b105c18bdae694ddaad5b6e3 (diff)
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>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/radix-tree/Makefile7
-rw-r--r--tools/testing/radix-tree/find_next_bit.c57
-rw-r--r--tools/testing/radix-tree/linux/bitops.h40
-rw-r--r--tools/testing/radix-tree/linux/bitops/non-atomic.h13
-rw-r--r--tools/testing/radix-tree/linux/kernel.h11
5 files changed, 48 insertions, 80 deletions
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile
index 08283a841066..3635e4d3eca7 100644
--- a/tools/testing/radix-tree/Makefile
+++ b/tools/testing/radix-tree/Makefile
@@ -18,7 +18,12 @@ main: $(OFILES)
18clean: 18clean:
19 $(RM) -f $(TARGETS) *.o radix-tree.c 19 $(RM) -f $(TARGETS) *.o radix-tree.c
20 20
21$(OFILES): *.h */*.h ../../../include/linux/radix-tree.h ../../include/linux/*.h 21find_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
23radix-tree.c: ../../../lib/radix-tree.c 28radix-tree.c: ../../../lib/radix-tree.c
24 sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@ 29 sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@
diff --git a/tools/testing/radix-tree/find_next_bit.c b/tools/testing/radix-tree/find_next_bit.c
deleted file mode 100644
index d1c2178bb2d4..000000000000
--- a/tools/testing/radix-tree/find_next_bit.c
+++ /dev/null
@@ -1,57 +0,0 @@
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 */
20unsigned 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
51found_first:
52 tmp &= (~0UL >> (BITS_PER_LONG - size));
53 if (tmp == 0UL) /* Are any bits set? */
54 return result + size; /* Nope. */
55found_middle:
56 return result + __ffs(tmp);
57}
diff --git a/tools/testing/radix-tree/linux/bitops.h b/tools/testing/radix-tree/linux/bitops.h
index 71d58427ab60..a13e9bc76eec 100644
--- a/tools/testing/radix-tree/linux/bitops.h
+++ b/tools/testing/radix-tree/linux/bitops.h
@@ -2,9 +2,14 @@
2#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ 2#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
3 3
4#include <linux/types.h> 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)) 9#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
7#define BITOP_WORD(nr) ((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 * __set_bit - Set a bit in memory 15 * __set_bit - Set a bit in memory
@@ -17,16 +22,16 @@
17 */ 22 */
18static inline void __set_bit(int nr, volatile unsigned long *addr) 23static inline void __set_bit(int nr, volatile unsigned long *addr)
19{ 24{
20 unsigned long mask = BITOP_MASK(nr); 25 unsigned long mask = BIT_MASK(nr);
21 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 26 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
22 27
23 *p |= mask; 28 *p |= mask;
24} 29}
25 30
26static inline void __clear_bit(int nr, volatile unsigned long *addr) 31static inline void __clear_bit(int nr, volatile unsigned long *addr)
27{ 32{
28 unsigned long mask = BITOP_MASK(nr); 33 unsigned long mask = BIT_MASK(nr);
29 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 34 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
30 35
31 *p &= ~mask; 36 *p &= ~mask;
32} 37}
@@ -42,8 +47,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr)
42 */ 47 */
43static inline void __change_bit(int nr, volatile unsigned long *addr) 48static inline void __change_bit(int nr, volatile unsigned long *addr)
44{ 49{
45 unsigned long mask = BITOP_MASK(nr); 50 unsigned long mask = BIT_MASK(nr);
46 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 51 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
47 52
48 *p ^= mask; 53 *p ^= mask;
49} 54}
@@ -59,8 +64,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)
59 */ 64 */
60static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 65static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
61{ 66{
62 unsigned long mask = BITOP_MASK(nr); 67 unsigned long mask = BIT_MASK(nr);
63 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 68 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
64 unsigned long old = *p; 69 unsigned long old = *p;
65 70
66 *p = old | mask; 71 *p = old | mask;
@@ -78,8 +83,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
78 */ 83 */
79static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 84static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
80{ 85{
81 unsigned long mask = BITOP_MASK(nr); 86 unsigned long mask = BIT_MASK(nr);
82 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 87 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
83 unsigned long old = *p; 88 unsigned long old = *p;
84 89
85 *p = old & ~mask; 90 *p = old & ~mask;
@@ -90,8 +95,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
90static inline int __test_and_change_bit(int nr, 95static inline int __test_and_change_bit(int nr,
91 volatile unsigned long *addr) 96 volatile unsigned long *addr)
92{ 97{
93 unsigned long mask = BITOP_MASK(nr); 98 unsigned long mask = BIT_MASK(nr);
94 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 99 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
95 unsigned long old = *p; 100 unsigned long old = *p;
96 101
97 *p = old ^ mask; 102 *p = old ^ mask;
@@ -105,7 +110,7 @@ static inline int __test_and_change_bit(int nr,
105 */ 110 */
106static inline int test_bit(int nr, const volatile unsigned long *addr) 111static inline int test_bit(int nr, const volatile unsigned long *addr)
107{ 112{
108 return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 113 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
109} 114}
110 115
111/** 116/**
@@ -147,4 +152,9 @@ unsigned long find_next_bit(const unsigned long *addr,
147 unsigned long size, 152 unsigned long size,
148 unsigned long offset); 153 unsigned long offset);
149 154
155static inline unsigned long hweight_long(unsigned long w)
156{
157 return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
158}
159
150#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ 160#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
diff --git a/tools/testing/radix-tree/linux/bitops/non-atomic.h b/tools/testing/radix-tree/linux/bitops/non-atomic.h
index 46a825cf2ae1..6a1bcb9d2c4a 100644
--- a/tools/testing/radix-tree/linux/bitops/non-atomic.h
+++ b/tools/testing/radix-tree/linux/bitops/non-atomic.h
@@ -3,7 +3,6 @@
3 3
4#include <asm/types.h> 4#include <asm/types.h>
5 5
6#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
7#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 6#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
8 7
9/** 8/**
@@ -17,7 +16,7 @@
17 */ 16 */
18static inline void __set_bit(int nr, volatile unsigned long *addr) 17static inline void __set_bit(int nr, volatile unsigned long *addr)
19{ 18{
20 unsigned long mask = BITOP_MASK(nr); 19 unsigned long mask = BIT_MASK(nr);
21 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 20 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
22 21
23 *p |= mask; 22 *p |= mask;
@@ -25,7 +24,7 @@ static inline void __set_bit(int nr, volatile unsigned long *addr)
25 24
26static inline void __clear_bit(int nr, volatile unsigned long *addr) 25static inline void __clear_bit(int nr, volatile unsigned long *addr)
27{ 26{
28 unsigned long mask = BITOP_MASK(nr); 27 unsigned long mask = BIT_MASK(nr);
29 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 28 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
30 29
31 *p &= ~mask; 30 *p &= ~mask;
@@ -42,7 +41,7 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr)
42 */ 41 */
43static inline void __change_bit(int nr, volatile unsigned long *addr) 42static inline void __change_bit(int nr, volatile unsigned long *addr)
44{ 43{
45 unsigned long mask = BITOP_MASK(nr); 44 unsigned long mask = BIT_MASK(nr);
46 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 45 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
47 46
48 *p ^= mask; 47 *p ^= mask;
@@ -59,7 +58,7 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)
59 */ 58 */
60static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 59static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
61{ 60{
62 unsigned long mask = BITOP_MASK(nr); 61 unsigned long mask = BIT_MASK(nr);
63 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 62 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
64 unsigned long old = *p; 63 unsigned long old = *p;
65 64
@@ -78,7 +77,7 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
78 */ 77 */
79static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 78static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
80{ 79{
81 unsigned long mask = BITOP_MASK(nr); 80 unsigned long mask = BIT_MASK(nr);
82 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 81 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
83 unsigned long old = *p; 82 unsigned long old = *p;
84 83
@@ -90,7 +89,7 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
90static inline int __test_and_change_bit(int nr, 89static inline int __test_and_change_bit(int nr,
91 volatile unsigned long *addr) 90 volatile unsigned long *addr)
92{ 91{
93 unsigned long mask = BITOP_MASK(nr); 92 unsigned long mask = BIT_MASK(nr);
94 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); 93 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
95 unsigned long old = *p; 94 unsigned long old = *p;
96 95
diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h
index dbe4b92806b8..23e77f5673ce 100644
--- a/tools/testing/radix-tree/linux/kernel.h
+++ b/tools/testing/radix-tree/linux/kernel.h
@@ -47,4 +47,15 @@ static inline int in_interrupt(void)
47{ 47{
48 return 0; 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#endif /* _KERNEL_H */ 61#endif /* _KERNEL_H */