Re: [PATCH 2/5] linux: bitmap.h: add 'for_each_set_bitrange' iteration macro

2023-12-26 Thread Simon Glass
On Mon, Dec 11, 2023 at 12:21 PM  wrote:
>
> From: Lukas Funke 
>
> Add 'for_each_set_bitrange' (from Linux kernel) in order to iterate
> over each set bitrange of a bitmap. This becomes handy if one wants
> to generate a cpu list i.e. for isolcpu or nohz_full.
>
> Signed-off-by: Lukas Funke 
> ---
>
>  include/linux/bitmap.h | 7 +++
>  1 file changed, 7 insertions(+)
>

Reviewed-by: Simon Glass 


[PATCH 2/5] linux: bitmap.h: add 'for_each_set_bitrange' iteration macro

2023-12-11 Thread lukas . funke-oss
From: Lukas Funke 

Add 'for_each_set_bitrange' (from Linux kernel) in order to iterate
over each set bitrange of a bitmap. This becomes handy if one wants
to generate a cpu list i.e. for isolcpu or nohz_full.

Signed-off-by: Lukas Funke 
---

 include/linux/bitmap.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 0a8503af9f..9714533078 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -159,6 +159,13 @@ static inline unsigned long find_first_bit(const unsigned 
long *addr, unsigned l
 (bit) < (size);\
 (bit) = find_next_bit((addr), (size), (bit) + 1))
 
+#define for_each_set_bitrange(b, e, addr, size)\
+   for ((b) = 0;   \
+(b) = find_next_bit((addr), (size), b),\
+(e) = find_next_zero_bit((addr), (size), (b) + 1), \
+(b) < (size);  \
+(b) = (e) + 1)
+
 static inline unsigned long
 bitmap_find_next_zero_area(unsigned long *map,
   unsigned long size,
-- 
2.30.2