History

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.

Alexey Bayduraev committed 5 years ago

Commit f20510d1 parent 857286e2 files · +25 −0Browse files

Unified · Split

2 files
  1. tools/include/linux/bitmap.h +11 −0
  2. tools/lib/bitmap.c +14 −0
tools/include/linux/bitmap.h+11−0
@@ -18,6 +18,8 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, · 17 unmodified lines
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, · 146 unmodified lines
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+14−0
@@ -86,3 +86,17 @@ int __bitmap_equal(const unsigned long *bitmap1, · 85 unmodified lines
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+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t