From: Andrew Morton <akpm@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>
Subject: Re: [PATCH 1/3] bitmap: generalize node_random()
Date: Wed, 4 Jun 2025 14:34:42 -0700 [thread overview]
Message-ID: <20250604143442.37635ce63e50a7425a390c2e@linux-foundation.org> (raw)
In-Reply-To: <20250604212125.25656-2-yury.norov@gmail.com>
On Wed, 4 Jun 2025 17:21:21 -0400 Yury Norov <yury.norov@gmail.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.
next prev parent reply other threads:[~2025-06-04 21:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 21:21 [PATCH 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-04 21:21 ` [PATCH 1/3] bitmap: generalize node_random() Yury Norov
2025-06-04 21:34 ` Andrew Morton [this message]
2025-06-04 21:46 ` Yury Norov
2025-06-04 22:37 ` Andrew Morton
2025-06-04 21:21 ` [PATCH 2/3] cpumask: introduce cpumask_random() Yury Norov
2025-06-04 21:21 ` [PATCH 3/3] clocksource: improve randomness in clocksource_verify_choose_cpus() Yury Norov
2025-06-05 18:17 ` John Stultz
2025-06-08 19:45 [PATCH v2 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-08 19:45 ` [PATCH 1/3] bitmap: generalize node_random() Yury Norov
2025-06-08 21:44 ` kernel test robot
2025-06-09 14:28 ` Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250604143442.37635ce63e50a7425a390c2e@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®