diff options
| author | Jiri Olsa <[email protected]> | 2016-10-10 07:26:33 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2016-10-24 14:07:33 +0000 |
| commit | 02bc11de567273da8ab25c54336ddbb71986f38f (patch) | |
| tree | 2356fcbb1ad8571a14e61ca58575a752c3de6c2c /tools/lib/find_bit.c | |
| parent | tools lib traceevent: Add version for traceevent shared object (diff) | |
| download | kernel-02bc11de567273da8ab25c54336ddbb71986f38f.tar.gz kernel-02bc11de567273da8ab25c54336ddbb71986f38f.zip | |
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 <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/lib/find_bit.c')
| -rw-r--r-- | tools/lib/find_bit.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index 9122a9e80046..6d8b8f22cf55 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -82,3 +82,28 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size) return size; } #endif + +#ifndef find_first_zero_bit +/* + * Find the first cleared bit in a memory region. + */ +unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) +{ + unsigned long idx; + + for (idx = 0; idx * BITS_PER_LONG < size; idx++) { + if (addr[idx] != ~0UL) + return min(idx * BITS_PER_LONG + ffz(addr[idx]), size); + } + + return size; +} +#endif + +#ifndef find_next_zero_bit +unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr, size, offset, ~0UL); +} +#endif |
