lkml.org 
[lkml]   [2022]   [Jan]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 27/54] lib/bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions
Date
On 1/23/22 20:38, Yury Norov wrote:
> Many kernel users use bitmap_weight() to compare the result against
> some number or expression:
>
> if (bitmap_weight(...) > 1)
> do_something();
>
> It works OK, but may be significantly improved for large bitmaps: if
> first few words count set bits to a number greater than given, we can
> stop counting and immediately return.
>
> The same idea would work in other direction: if we know that the number
> of set bits that we counted so far is small enough, so that it would be
> smaller than required number even if all bits of the rest of the bitmap
> are set, we can stop counting earlier.
>
> This patch adds new bitmap_weight_cmp() as suggested by Michał Mirosław
> and a family of eq, gt, ge, lt and le wrappers to allow this optimization.
> The following patches apply new functions where appropriate.
>

Thanks for pushing this improvement Yury. Seeing how much this has
evolved from the single_bit_set() suggestion - it'd be a bit thick from
me to add a suggested-by ;) I did review it though and it looks good to me!

Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>

> Suggested-by: "Michał Mirosław" <mirq-linux@rere.qmqm.pl> (for bitmap_weight_cmp)
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
> include/linux/bitmap.h | 80 ++++++++++++++++++++++++++++++++++++++++++
> lib/bitmap.c | 21 +++++++++++
> 2 files changed, 101 insertions(+)


--
The Linux Kernel guy at ROHM Semiconductors

Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~ this year is the year of a signature writers block ~~
\
 
 \ /
  Last update: 2022-01-28 08:00    [W:0.231 / U:1.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site