Skip to content

Commit 4ade081

Browse files
committed
tools: sync tools/bitmap with mother linux
Remove tools/include/asm-generic/bitops/find.h and copy include/linux/bitmap.h to tools. find_*_le() functions are not copied because not needed in tools. Signed-off-by: Yury Norov <[email protected]> Tested-by: Wolfram Sang <[email protected]>
1 parent b5c7e7e commit 4ade081

File tree

5 files changed

+100
-11
lines changed

5 files changed

+100
-11
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,8 +3365,8 @@ F: lib/bitmap.c
33653365
F: lib/find_bit.c
33663366
F: lib/find_bit_benchmark.c
33673367
F: lib/test_bitmap.c
3368-
F: tools/include/asm-generic/bitops/find.h
33693368
F: tools/include/linux/bitmap.h
3369+
F: tools/include/linux/find.h
33703370
F: tools/lib/bitmap.c
33713371
F: tools/lib/find_bit.c
33723372

tools/include/asm-generic/bitops.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <asm-generic/bitops/fls.h>
1919
#include <asm-generic/bitops/__fls.h>
2020
#include <asm-generic/bitops/fls64.h>
21-
#include <asm-generic/bitops/find.h>
2221

2322
#ifndef _TOOLS_LINUX_BITOPS_H_
2423
#error only <linux/bitops.h> can be included directly

tools/include/linux/bitmap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _PERF_BITOPS_H
3-
#define _PERF_BITOPS_H
2+
#ifndef _TOOLS_LINUX_BITMAP_H
3+
#define _TOOLS_LINUX_BITMAP_H
44

55
#include <string.h>
66
#include <linux/bitops.h>
7+
#include <linux/find.h>
78
#include <stdlib.h>
89
#include <linux/kernel.h>
910

@@ -181,4 +182,4 @@ static inline int bitmap_intersects(const unsigned long *src1,
181182
return __bitmap_intersects(src1, src2, nbits);
182183
}
183184

184-
#endif /* _PERF_BITOPS_H */
185+
#endif /* _TOOLS_LINUX_BITMAP_H */

tools/include/asm-generic/bitops/find.h renamed to tools/include/linux/find.h

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
3-
#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
2+
#ifndef _TOOLS_LINUX_FIND_H_
3+
#define _TOOLS_LINUX_FIND_H_
4+
5+
#ifndef _TOOLS_LINUX_BITMAP_H
6+
#error tools: only <linux/bitmap.h> can be included directly
7+
#endif
8+
9+
#include <linux/bitops.h>
410

511
extern unsigned long _find_next_bit(const unsigned long *addr1,
612
const unsigned long *addr2, unsigned long nbits,
713
unsigned long start, unsigned long invert, unsigned long le);
814
extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size);
15+
extern unsigned long _find_first_and_bit(const unsigned long *addr1,
16+
const unsigned long *addr2, unsigned long size);
917
extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size);
1018
extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size);
1119

@@ -96,7 +104,6 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
96104
#endif
97105

98106
#ifndef find_first_bit
99-
100107
/**
101108
* find_first_bit - find the first set bit in a memory region
102109
* @addr: The address to start the search at
@@ -116,11 +123,34 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
116123

117124
return _find_first_bit(addr, size);
118125
}
126+
#endif
127+
128+
#ifndef find_first_and_bit
129+
/**
130+
* find_first_and_bit - find the first set bit in both memory regions
131+
* @addr1: The first address to base the search on
132+
* @addr2: The second address to base the search on
133+
* @size: The bitmap size in bits
134+
*
135+
* Returns the bit number for the next set bit
136+
* If no bits are set, returns @size.
137+
*/
138+
static inline
139+
unsigned long find_first_and_bit(const unsigned long *addr1,
140+
const unsigned long *addr2,
141+
unsigned long size)
142+
{
143+
if (small_const_nbits(size)) {
144+
unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0);
119145

120-
#endif /* find_first_bit */
146+
return val ? __ffs(val) : size;
147+
}
121148

122-
#ifndef find_first_zero_bit
149+
return _find_first_and_bit(addr1, addr2, size);
150+
}
151+
#endif
123152

153+
#ifndef find_first_zero_bit
124154
/**
125155
* find_first_zero_bit - find the first cleared bit in a memory region
126156
* @addr: The address to start the search at
@@ -142,4 +172,43 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
142172
}
143173
#endif
144174

145-
#endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */
175+
#ifndef find_last_bit
176+
/**
177+
* find_last_bit - find the last set bit in a memory region
178+
* @addr: The address to start the search at
179+
* @size: The number of bits to search
180+
*
181+
* Returns the bit number of the last set bit, or size.
182+
*/
183+
static inline
184+
unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
185+
{
186+
if (small_const_nbits(size)) {
187+
unsigned long val = *addr & GENMASK(size - 1, 0);
188+
189+
return val ? __fls(val) : size;
190+
}
191+
192+
return _find_last_bit(addr, size);
193+
}
194+
#endif
195+
196+
/**
197+
* find_next_clump8 - find next 8-bit clump with set bits in a memory region
198+
* @clump: location to store copy of found clump
199+
* @addr: address to base the search on
200+
* @size: bitmap size in number of bits
201+
* @offset: bit offset at which to start searching
202+
*
203+
* Returns the bit offset for the next set clump; the found clump value is
204+
* copied to the location pointed by @clump. If no bits are set, returns @size.
205+
*/
206+
extern unsigned long find_next_clump8(unsigned long *clump,
207+
const unsigned long *addr,
208+
unsigned long size, unsigned long offset);
209+
210+
#define find_first_clump8(clump, bits, size) \
211+
find_next_clump8((clump), (bits), (size), 0)
212+
213+
214+
#endif /*__LINUX_FIND_H_ */

tools/lib/find_bit.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ unsigned long _find_first_bit(const unsigned long *addr, unsigned long size)
9696
}
9797
#endif
9898

99+
#ifndef find_first_and_bit
100+
/*
101+
* Find the first set bit in two memory regions.
102+
*/
103+
unsigned long _find_first_and_bit(const unsigned long *addr1,
104+
const unsigned long *addr2,
105+
unsigned long size)
106+
{
107+
unsigned long idx, val;
108+
109+
for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
110+
val = addr1[idx] & addr2[idx];
111+
if (val)
112+
return min(idx * BITS_PER_LONG + __ffs(val), size);
113+
}
114+
115+
return size;
116+
}
117+
#endif
118+
99119
#ifndef find_first_zero_bit
100120
/*
101121
* Find the first cleared bit in a memory region.

0 commit comments

Comments
 (0)