From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
"Yury Norov [NVIDIA]" <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH v3 2/3] cpumask: introduce cpumask_random()
Date: Tue, 17 Jun 2025 16:08:52 -0400 [thread overview]
Message-ID: <20250617200854.60753-3-yury.norov@gmail.com> (raw)
In-Reply-To: <20250617200854.60753-1-yury.norov@gmail.com>
From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
Propagate find_random_bit() to cpumask API.
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
include/linux/cpumask.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 7ae80a7ca81e..39b71b662da3 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -354,6 +354,18 @@ unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
return find_next_bit_wrap(cpumask_bits(src), small_cpumask_bits, n + 1);
}
+/**
+ * cpumask_random - get random cpu in *src.
+ * @src: cpumask pointer
+ *
+ * Return: random set bit, or >= nr_cpu_ids if @src is empty.
+ */
+static __always_inline
+unsigned int cpumask_random(const struct cpumask *src)
+{
+ return find_random_bit(cpumask_bits(src), nr_cpu_ids);
+}
+
/**
* for_each_cpu - iterate over every cpu in a mask
* @cpu: the (optionally unsigned) integer iterator
--
2.43.0
next prev parent reply other threads:[~2025-06-17 20:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 20:08 [PATCH v3 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-17 20:08 ` [PATCH v3 1/3] bitmap: generalize node_random() Yury Norov
2025-06-17 22:50 ` Andrew Morton
2025-06-17 22:59 ` Yury Norov
2025-06-17 20:08 ` Yury Norov [this message]
2025-06-17 20:08 ` [PATCH v3 3/3] clocksource: Improve randomness in clocksource_verify_choose_cpus() 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=20250617200854.60753-3-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=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 \
/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