Skip to content

Commit f20510d

Browse files
abayduracmel
authored andcommitted
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 <[email protected]> Acked-by: Andi Kleen <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Antonov <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Budankov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Riccardo Mancini <[email protected]> Link: http://lore.kernel.org/lkml/f75aa738d8ff8f9cffd7532d671f3ef3deb97a7c.1625065643.git.alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 857286e commit f20510d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tools/include/linux/bitmap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
1818
int __bitmap_equal(const unsigned long *bitmap1,
1919
const unsigned long *bitmap2, unsigned int bits);
2020
void bitmap_clear(unsigned long *map, unsigned int start, int len);
21+
int __bitmap_intersects(const unsigned long *bitmap1,
22+
const unsigned long *bitmap2, unsigned int bits);
2123

2224
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
2325
#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,
170172
return __bitmap_equal(src1, src2, nbits);
171173
}
172174

175+
static inline int bitmap_intersects(const unsigned long *src1,
176+
const unsigned long *src2, unsigned int nbits)
177+
{
178+
if (small_const_nbits(nbits))
179+
return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
180+
else
181+
return __bitmap_intersects(src1, src2, nbits);
182+
}
183+
173184
#endif /* _PERF_BITOPS_H */

tools/lib/bitmap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ int __bitmap_equal(const unsigned long *bitmap1,
8686

8787
return 1;
8888
}
89+
90+
int __bitmap_intersects(const unsigned long *bitmap1,
91+
const unsigned long *bitmap2, unsigned int bits)
92+
{
93+
unsigned int k, lim = bits/BITS_PER_LONG;
94+
for (k = 0; k < lim; ++k)
95+
if (bitmap1[k] & bitmap2[k])
96+
return 1;
97+
98+
if (bits % BITS_PER_LONG)
99+
if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
100+
return 1;
101+
return 0;
102+
}

0 commit comments

Comments
 (0)