diff options
author | Jiri Olsa <jolsa@kernel.org> | 2016-10-10 03:26:33 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-10-24 10:07:33 -0400 |
commit | 02bc11de567273da8ab25c54336ddbb71986f38f (patch) | |
tree | 2356fcbb1ad8571a14e61ca58575a752c3de6c2c /tools/lib/find_bit.c | |
parent | fe316723a8106c7527710ae7085a1dc6a9c1ab05 (diff) |
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>
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) | |||
82 | return size; | 82 | return size; |
83 | } | 83 | } |
84 | #endif | 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 | ||