Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib: Add for_each_clear_bit macro

Adding for_each_clear_bit macro plus all its the necessary backbone
functions. Taken from related kernel code. It will be used in following
patch.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-cayv2zbqi0nlmg5sjjxs1775@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
02bc11de fe316723

+72
+1
tools/include/asm-generic/bitops.h
··· 13 13 */ 14 14 15 15 #include <asm-generic/bitops/__ffs.h> 16 + #include <asm-generic/bitops/__ffz.h> 16 17 #include <asm-generic/bitops/fls.h> 17 18 #include <asm-generic/bitops/__fls.h> 18 19 #include <asm-generic/bitops/fls64.h>
+12
tools/include/asm-generic/bitops/__ffz.h
··· 1 + #ifndef _ASM_GENERIC_BITOPS_FFZ_H_ 2 + #define _ASM_GENERIC_BITOPS_FFZ_H_ 3 + 4 + /* 5 + * ffz - find first zero in word. 6 + * @word: The word to search 7 + * 8 + * Undefined if no zero exists, so code should check against ~0UL first. 9 + */ 10 + #define ffz(x) __ffs(~(x)) 11 + 12 + #endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
+28
tools/include/asm-generic/bitops/find.h
··· 15 15 size, unsigned long offset); 16 16 #endif 17 17 18 + #ifndef find_next_zero_bit 19 + 20 + /** 21 + * find_next_zero_bit - find the next cleared bit in a memory region 22 + * @addr: The address to base the search on 23 + * @offset: The bitnumber to start searching at 24 + * @size: The bitmap size in bits 25 + * 26 + * Returns the bit number of the next zero bit 27 + * If no bits are zero, returns @size. 28 + */ 29 + unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 30 + unsigned long offset); 31 + #endif 32 + 18 33 #ifndef find_first_bit 19 34 20 35 /** ··· 44 29 unsigned long size); 45 30 46 31 #endif /* find_first_bit */ 32 + 33 + #ifndef find_first_zero_bit 34 + 35 + /** 36 + * find_first_zero_bit - find the first cleared bit in a memory region 37 + * @addr: The address to start the search at 38 + * @size: The maximum number of bits to search 39 + * 40 + * Returns the bit number of the first cleared bit. 41 + * If no bits are zero, returns @size. 42 + */ 43 + unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size); 44 + #endif 47 45 48 46 #endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */
+5
tools/include/linux/bitops.h
··· 39 39 (bit) < (size); \ 40 40 (bit) = find_next_bit((addr), (size), (bit) + 1)) 41 41 42 + #define for_each_clear_bit(bit, addr, size) \ 43 + for ((bit) = find_first_zero_bit((addr), (size)); \ 44 + (bit) < (size); \ 45 + (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) 46 + 42 47 /* same as for_each_set_bit() but use bit as value to start with */ 43 48 #define for_each_set_bit_from(bit, addr, size) \ 44 49 for ((bit) = find_next_bit((addr), (size), (bit)); \
+25
tools/lib/find_bit.c
··· 82 82 return size; 83 83 } 84 84 #endif 85 + 86 + #ifndef find_first_zero_bit 87 + /* 88 + * Find the first cleared bit in a memory region. 89 + */ 90 + unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) 91 + { 92 + unsigned long idx; 93 + 94 + for (idx = 0; idx * BITS_PER_LONG < size; idx++) { 95 + if (addr[idx] != ~0UL) 96 + return min(idx * BITS_PER_LONG + ffz(addr[idx]), size); 97 + } 98 + 99 + return size; 100 + } 101 + #endif 102 + 103 + #ifndef find_next_zero_bit 104 + unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 105 + unsigned long offset) 106 + { 107 + return _find_next_bit(addr, size, offset, ~0UL); 108 + } 109 + #endif
+1
tools/perf/MANIFEST
··· 51 51 tools/include/asm-generic/bitops/atomic.h 52 52 tools/include/asm-generic/bitops/const_hweight.h 53 53 tools/include/asm-generic/bitops/__ffs.h 54 + tools/include/asm-generic/bitops/__ffz.h 54 55 tools/include/asm-generic/bitops/__fls.h 55 56 tools/include/asm-generic/bitops/find.h 56 57 tools/include/asm-generic/bitops/fls64.h