Re: [patch V3 07/20] cpumask: Introduce cpumask_weighted_or()
From: Shrikanth Hegde
Date: Mon Nov 03 2025 - 04:16:06 EST
On 10/29/25 6:39 PM, Thomas Gleixner wrote:
CID management OR's two cpumasks and then calculates the weight on the
result. That's inefficient as that has to walk the same stuff twice. As
this is done with runqueue lock held, there is a real benefit of speeding
this up. Depending on the system this results in 10-20% less cycles spent
with runqueue lock held for a 4K cpumask.
Provide cpumask_weighted_or() and the corresponding bitmap functions which
return the weight of the OR result right away.
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Reviewed-by: Yury Norov (NVIDIA) <yury.norov@xxxxxxxxx>
---
V3: Rename again - Yury
V2: Rename and use the BITMAP_WEIGHT() macro - Yury
---
include/linux/bitmap.h | 15 +++++++++++++++
include/linux/cpumask.h | 16 ++++++++++++++++
lib/bitmap.c | 6 ++++++
3 files changed, 37 insertions(+)
/**
+ * cpumask_weighted_or - *dstp = *src1p | *src2p and return the weight of the result
+ * @dstp: the cpumask result
+ * @src1p: the first input
+ * @src2p: the second input
+ *
+ * Return: The number of bits set in the resulting cpumask @dstp
+ */
+static __always_inline
+unsigned int cpumask_weighted_or(struct cpumask *dstp, const struct cpumask *src1p,
+ const struct cpumask *src2p)
+{
+ return bitmap_weighted_or(cpumask_bits(dstp), cpumask_bits(src1p),
+ cpumask_bits(src2p), small_cpumask_bits);
+}
nit:
We have currently cpumask_weight_and & variants.
Wouldn't it be better to name it cpumask_weight_or ?