Re: [PATCH 3/4] cpumask: add cpumask_{first,next}_andnot() API

From: James Morse
Date: Thu Apr 24 2025 - 13:07:50 EST


Hi Yury,

On 07/04/2025 16:38, Yury Norov wrote:
> From: Yury Norov [NVIDIA] <yury.norov@xxxxxxxxx>
>
> With the lack of the functions, client code has to abuse less efficient
> cpumask_nth().


> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> index 0f816092c891..9067c3411cd0 100644
> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h

> @@ -458,6 +490,33 @@ unsigned int cpumask_any_and_but(const struct cpumask *mask1,
> return cpumask_next_and(cpu, mask1, mask2);
> }
>
> +/**
> + * cpumask_andnot_any_but - pick an arbitrary cpu from *mask1 & ~*mask2, but not this one.
> + * @mask1: the first input cpumask
> + * @mask2: the second input cpumask
> + * @cpu: the cpu to ignore
> + *
> + * If @cpu == -1, the function returns the first matching cpu.
> + * Returns >= nr_cpu_ids if no cpus set.
> + */
> +static __always_inline
> +unsigned int cpumask_andnot_any_but(const struct cpumask *mask1,
> + const struct cpumask *mask2,
> + unsigned int cpu)

Nit: Shouldn't this be named cpumask_any_andnot_but()?
It's any cpu from the first-mask, then 'andnot' the second. This fits with the other
instances of this, e.g. cpumask_any_and_but().


> +{
> + unsigned int i;
> +
> + /* -1 is a legal arg here. */
> + if (cpu != -1)
> + cpumask_check(cpu);
> +
> + i = cpumask_first_andnot(mask1, mask2);
> + if (i != cpu)
> + return i;
> +
> + return cpumask_next_andnot(cpu, mask1, mask2);
> +}


Thanks,

James