Re: [RFC PATCH] cpumask: Implement "random" version of cpumask_any_but()
From: Mark Rutland
Date: Tue Jan 14 2025 - 10:03:19 EST
On Tue, Jan 14, 2025 at 03:15:43PM +0800, I Hsin Cheng wrote:
> On Mon, Jan 13, 2025 at 01:00:56PM -0500, Yury Norov wrote:
> > On Mon, Jan 13, 2025 at 11:05:19AM +0000, Mark Rutland wrote:
> > > On Mon, Jan 13, 2025 at 02:18:39PM +0800, I Hsin Cheng wrote:
> > > > Original implementation of "cpumask_any_but()" isn't actually random as
> > > > the comment claims itself to be. It's behavior is in fact to select the
> > > > first cpu in "mask" which isn't equal to "cpu".
> > >
> > > What it says specifically is:
> > >
> > > cpumask_any_but - return a "random" in a cpumask, but not this one.
> > >
> > > ... and by "random", it really means "arbitrary".
> > >
> > > The idea here is that the caller is specifying that it doesn't care
> > > which specific CPU is chosen, but this is not required to be a random
> > > selection.
> I now realize "random" here is more of a convention for the caller to
> states that it doesn't matter which cpu it gets, maybe we should
> rephrase the comment to make it less confusing? Because I think "random"
> itself does stands for a particular meaning.
FWIW, I agree. I reckon (as above), we could replace "random" with
arbitrary, i.e. replace
return a "random" cpu in a cpumask ...
... with:
return an arbitrary cpu in a cpumask ...
Looking again I see that the comment for cpumask_any_but() misses the
word "cpu" too, so it'd be nice to clean that up regardless.
Mark.