[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250604143442.37635ce63e50a7425a390c2e@linux-foundation.org>
Date: Wed, 4 Jun 2025 14:34:42 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Yury Norov <yury.norov@...il.com>
Cc: linux-kernel@...r.kernel.org, Rasmus Villemoes
<linux@...musvillemoes.dk>, John Stultz <jstultz@...gle.com>, Thomas
Gleixner <tglx@...utronix.de>, Stephen Boyd <sboyd@...nel.org>
Subject: Re: [PATCH 1/3] bitmap: generalize node_random()
On Wed, 4 Jun 2025 17:21:21 -0400 Yury Norov <yury.norov@...il.com> wrote:
> Generalize node_random and make it available to general bitmaps and
> cpumasks users.
Seems sensible.
> --- a/lib/find_bit.c
> +++ b/lib/find_bit.c
>
> +unsigned long find_random_bit(const unsigned long *addr, unsigned long size)
> +{
> + int w = bitmap_weight(addr, size);
> +
> + switch (w) {
> + case 0:
> + return size;
> + case 1:
> + return find_first_bit(addr, size);
Is the `1' special case useful? The `default' case should still work OK?
> + default:
> + return find_nth_bit(addr, size, get_random_u32_below(w));
> + }
> +}
> +EXPORT_SYMBOL(find_random_bit);
Some kerneldoc, please?
Of course, the hard-coding of get_random_u32_below() might be
unsuitable for some future potential callers but we can deal with that
if it ever occurs.
Powered by blists - more mailing lists