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>
This commit is contained in:
parent
e0eeb938ad
commit
692a68ee9c
@ -19,7 +19,7 @@ bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
|
|||||||
const unsigned long *bitmap2, unsigned int bits);
|
const unsigned long *bitmap2, unsigned int bits);
|
||||||
bool __bitmap_equal(const unsigned long *bitmap1,
|
bool __bitmap_equal(const unsigned long *bitmap1,
|
||||||
const unsigned long *bitmap2, unsigned int bits);
|
const unsigned long *bitmap2, unsigned int bits);
|
||||||
void bitmap_clear(unsigned long *map, unsigned int start, int len);
|
void __bitmap_clear(unsigned long *map, unsigned int start, int len);
|
||||||
bool __bitmap_intersects(const unsigned long *bitmap1,
|
bool __bitmap_intersects(const unsigned long *bitmap1,
|
||||||
const unsigned long *bitmap2, unsigned int bits);
|
const unsigned long *bitmap2, unsigned int bits);
|
||||||
|
|
||||||
@ -150,4 +150,19 @@ static inline bool bitmap_intersects(const unsigned long *src1,
|
|||||||
return __bitmap_intersects(src1, src2, nbits);
|
return __bitmap_intersects(src1, src2, nbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void bitmap_clear(unsigned long *map, unsigned int start,
|
||||||
|
unsigned int nbits)
|
||||||
|
{
|
||||||
|
if (__builtin_constant_p(nbits) && nbits == 1)
|
||||||
|
__clear_bit(start, map);
|
||||||
|
else if (small_const_nbits(start + nbits))
|
||||||
|
*map &= ~GENMASK(start + nbits - 1, start);
|
||||||
|
else if (__builtin_constant_p(start & BITMAP_MEM_MASK) &&
|
||||||
|
IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) &&
|
||||||
|
__builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
|
||||||
|
IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT))
|
||||||
|
memset((char *)map + start / 8, 0, nbits / 8);
|
||||||
|
else
|
||||||
|
__bitmap_clear(map, start, nbits);
|
||||||
|
}
|
||||||
#endif /* _TOOLS_LINUX_BITMAP_H */
|
#endif /* _TOOLS_LINUX_BITMAP_H */
|
||||||
|
@ -100,3 +100,23 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __bitmap_clear(unsigned long *map, unsigned int start, int len)
|
||||||
|
{
|
||||||
|
unsigned long *p = map + BIT_WORD(start);
|
||||||
|
const unsigned int size = start + len;
|
||||||
|
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
|
||||||
|
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
|
||||||
|
|
||||||
|
while (len - bits_to_clear >= 0) {
|
||||||
|
*p &= ~mask_to_clear;
|
||||||
|
len -= bits_to_clear;
|
||||||
|
bits_to_clear = BITS_PER_LONG;
|
||||||
|
mask_to_clear = ~0UL;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if (len) {
|
||||||
|
mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
|
||||||
|
*p &= ~mask_to_clear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,8 +5,8 @@ CFLAGS += -I. -I../../include -I../../../lib -g -Og -Wall \
|
|||||||
LDFLAGS += -fsanitize=address -fsanitize=undefined
|
LDFLAGS += -fsanitize=address -fsanitize=undefined
|
||||||
LDLIBS+= -lpthread -lurcu
|
LDLIBS+= -lpthread -lurcu
|
||||||
TARGETS = main idr-test multiorder xarray maple
|
TARGETS = main idr-test multiorder xarray maple
|
||||||
CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o \
|
LIBS := slab.o find_bit.o bitmap.o hweight.o vsprintf.o
|
||||||
slab.o maple.o
|
CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o maple.o $(LIBS)
|
||||||
OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
|
OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
|
||||||
regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \
|
regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \
|
||||||
iteration_check_2.o benchmark.o
|
iteration_check_2.o benchmark.o
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
/* lib/bitmap.c pulls in at least two other files. */
|
|
||||||
|
|
||||||
#include <linux/bitmap.h>
|
|
||||||
|
|
||||||
void bitmap_clear(unsigned long *map, unsigned int start, int len)
|
|
||||||
{
|
|
||||||
unsigned long *p = map + BIT_WORD(start);
|
|
||||||
const unsigned int size = start + len;
|
|
||||||
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
|
|
||||||
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
|
|
||||||
|
|
||||||
while (len - bits_to_clear >= 0) {
|
|
||||||
*p &= ~mask_to_clear;
|
|
||||||
len -= bits_to_clear;
|
|
||||||
bits_to_clear = BITS_PER_LONG;
|
|
||||||
mask_to_clear = ~0UL;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
if (len) {
|
|
||||||
mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
|
|
||||||
*p &= ~mask_to_clear;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user