Skip to content

Commit 692a68e

Browse files
RichardWeiYangYuryNorov
authored andcommitted
radix tree test suite: put definition of bitmap_clear() into lib/bitmap.c
In tools/ directory, function bitmap_clear() is currently only used in object file tools/testing/radix-tree/xarray.o. But instead of keeping a bitmap.c with only bitmap_clear() definition in radix-tree's own directory, it would be more proper to put it in common directory lib/. Sync the kernel definition and link some related libs, no functional change is expected. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> CC: Matthew Wilcox <willy@infradead.org> CC: Yury Norov <yury.norov@gmail.com> Signed-off-by: Yury Norov <yury.norov@gmail.com>
1 parent e0eeb93 commit 692a68e

4 files changed

Lines changed: 38 additions & 26 deletions

File tree

tools/include/linux/bitmap.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
1919
const unsigned long *bitmap2, unsigned int bits);
2020
bool __bitmap_equal(const unsigned long *bitmap1,
2121
const unsigned long *bitmap2, unsigned int bits);
22-
void bitmap_clear(unsigned long *map, unsigned int start, int len);
22+
void __bitmap_clear(unsigned long *map, unsigned int start, int len);
2323
bool __bitmap_intersects(const unsigned long *bitmap1,
2424
const unsigned long *bitmap2, unsigned int bits);
2525

@@ -150,4 +150,19 @@ static inline bool bitmap_intersects(const unsigned long *src1,
150150
return __bitmap_intersects(src1, src2, nbits);
151151
}
152152

153+
static inline void bitmap_clear(unsigned long *map, unsigned int start,
154+
unsigned int nbits)
155+
{
156+
if (__builtin_constant_p(nbits) && nbits == 1)
157+
__clear_bit(start, map);
158+
else if (small_const_nbits(start + nbits))
159+
*map &= ~GENMASK(start + nbits - 1, start);
160+
else if (__builtin_constant_p(start & BITMAP_MEM_MASK) &&
161+
IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) &&
162+
__builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
163+
IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT))
164+
memset((char *)map + start / 8, 0, nbits / 8);
165+
else
166+
__bitmap_clear(map, start, nbits);
167+
}
153168
#endif /* _TOOLS_LINUX_BITMAP_H */

tools/lib/bitmap.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,23 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
100100
return true;
101101
return false;
102102
}
103+
104+
void __bitmap_clear(unsigned long *map, unsigned int start, int len)
105+
{
106+
unsigned long *p = map + BIT_WORD(start);
107+
const unsigned int size = start + len;
108+
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
109+
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
110+
111+
while (len - bits_to_clear >= 0) {
112+
*p &= ~mask_to_clear;
113+
len -= bits_to_clear;
114+
bits_to_clear = BITS_PER_LONG;
115+
mask_to_clear = ~0UL;
116+
p++;
117+
}
118+
if (len) {
119+
mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
120+
*p &= ~mask_to_clear;
121+
}
122+
}

tools/testing/radix-tree/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ CFLAGS += -I. -I../../include -I../../../lib -g -Og -Wall \
55
LDFLAGS += -fsanitize=address -fsanitize=undefined
66
LDLIBS+= -lpthread -lurcu
77
TARGETS = main idr-test multiorder xarray maple
8-
CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o \
9-
slab.o maple.o
8+
LIBS := slab.o find_bit.o bitmap.o hweight.o vsprintf.o
9+
CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o maple.o $(LIBS)
1010
OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
1111
regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \
1212
iteration_check_2.o benchmark.o

tools/testing/radix-tree/bitmap.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)