Re: [patch V3 07/20] cpumask: Introduce cpumask_weighted_or()

Shrikanth Hegde
2025-11-03T09:15:56Z

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@linutronix.de>
> Reviewed-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
> 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 ?