sched: replace cpumask_weight with cpumask_empty where appropriate
authorYury Norov <yury.norov@gmail.com>
Thu, 10 Feb 2022 22:49:06 +0000 (14:49 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 16 Feb 2022 14:57:53 +0000 (15:57 +0100)
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@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220210224933.379149-23-yury.norov@gmail.com
kernel/sched/core.c
kernel/sched/topology.c

index 1d863d7f6ad7300a14dc1fbcec072ba1041279ad..c620aab27acf402eac94120095657ff992f8ccc6 100644 (file)
@@ -8708,7 +8708,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);
index e6cd55951304275acd06c9ced3554711f2b9477e..1c84b48def20588b538a183ae08e3a656f2b1ef1 100644 (file)
@@ -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;