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
18int __bitmap_equal(const unsigned long *bitmap1,18int __bitmap_equal(const unsigned long *bitmap1,
19 const unsigned long *bitmap2, unsigned int bits);19 const unsigned long *bitmap2, unsigned int bits);
20void bitmap_clear(unsigned long *map, unsigned int start, int len);20void bitmap_clear(unsigned long *map, unsigned int start, int len);
21int __bitmap_intersects(const unsigned long *bitmap1,
22 const unsigned long *bitmap2, unsigned int bits);
21 23
22#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))24#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
23#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))25#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
170 return __bitmap_equal(src1, src2, nbits);172 return __bitmap_equal(src1, src2, nbits);
171}173}
172 174
175static 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
173#endif /* _PERF_BITOPS_H */184#endif /* _PERF_BITOPS_H */
tools/lib/bitmap.c+14−0
@@ -86,3 +86,17 @@ int __bitmap_equal(const unsigned long *bitmap1, · 85 unmodified lines
86 86
87 return 1;87 return 1;
88}88}
89
90int __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