Re: [PATCH 22/49] sched: replace cpumask_weight with cpumask_empty where appropriate

From: Yury Norov
Date: Fri Feb 11 2022 - 09:21:57 EST


On Fri, Feb 11, 2022 at 11:19:58AM +0100, Peter Zijlstra wrote:
> On Thu, Feb 10, 2022 at 02:49:06PM -0800, Yury Norov wrote:
> > In some places, kernel/sched code calls cpumask_weight() to check if
> > any bit of a given cpumask is set. We can do it more efficiently with
> > cpumask_empty() because cpumask_empty() stops traversing the cpumask as
> > soon as it finds first set bit, while cpumask_weight() counts all bits
> > unconditionally.
> >
> > Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
>
> Neither of these paths are really performance sentitive, but whatever.
>
> Do you want me to take this now,

Yes please. Many patches from this series already merged this way.

> or do you want to merge the whole
> series somewere else? In which case:
>
> Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
>
> > ---
> > kernel/sched/core.c | 2 +-
> > kernel/sched/topology.c | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 28d1b7af03dc..ed7b392945b7 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -8711,7 +8711,7 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
> > {
> > int ret = 1;
> >
> > - if (!cpumask_weight(cur))
> > + if (cpumask_empty(cur))
> > return ret;
> >
> > ret = dl_cpuset_cpumask_can_shrink(cur, trial);
> > diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> > index d201a7052a29..8478e2a8cd65 100644
> > --- a/kernel/sched/topology.c
> > +++ b/kernel/sched/topology.c
> > @@ -74,7 +74,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
> > break;
> > }
> >
> > - if (!cpumask_weight(sched_group_span(group))) {
> > + if (cpumask_empty(sched_group_span(group))) {
> > printk(KERN_CONT "\n");
> > printk(KERN_ERR "ERROR: empty group\n");
> > break;
> > --
> > 2.32.0
> >