From f20510d552e2941df2518c73c99fa2537575dbce Mon Sep 17 00:00:00 2001 From: Alexey Bayduraev Date: Wed, 30 Jun 2021 18:54:48 +0300 Subject: tools lib: Adopt bitmap_intersects() operation from the kernel sources Adopt bitmap_intersects() routine that tests whether bitmaps bitmap1 and bitmap2 intersects. This routine will be used during thread masks initialization. Signed-off-by: Alexey Bayduraev Acked-by: Andi Kleen Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Alexei Budankov Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Riccardo Mancini Link: http://lore.kernel.org/lkml/f75aa738d8ff8f9cffd7532d671f3ef3deb97a7c.1625065643.git.alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/bitmap.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tools/include') diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 330dbf7509cc..9d959bc24859 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -18,6 +18,8 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, int __bitmap_equal(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits); void bitmap_clear(unsigned long *map, unsigned int start, int len); +int __bitmap_intersects(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) @@ -170,4 +172,13 @@ static inline int bitmap_equal(const unsigned long *src1, return __bitmap_equal(src1, src2, nbits); } +static inline int bitmap_intersects(const unsigned long *src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; + else + return __bitmap_intersects(src1, src2, nbits); +} + #endif /* _PERF_BITOPS_H */ -- cgit v1.2.3