rcu: Replace cpumask_weight with cpumask_empty where appropriate
authorYury Norov <yury.norov@gmail.com>
Sun, 23 Jan 2022 18:38:53 +0000 (10:38 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 14 Feb 2022 18:36:58 +0000 (10:36 -0800)
In some places, RCU 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>
Acked-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree_nocb.h
kernel/rcu/tree_plugin.h

index eeafb546a7a09f8c790f8f0ec251f374187bbbf7..f83c7b1d611031e36e0e4e90845bc32bfdbdb624 100644 (file)
@@ -1169,7 +1169,7 @@ void __init rcu_init_nohz(void)
        struct rcu_data *rdp;
 
 #if defined(CONFIG_NO_HZ_FULL)
-       if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
+       if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
                need_rcu_nocb_mask = true;
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
@@ -1348,7 +1348,7 @@ static void __init rcu_organize_nocb_kthreads(void)
  */
 void rcu_bind_current_to_nocb(void)
 {
-       if (cpumask_available(rcu_nocb_mask) && cpumask_weight(rcu_nocb_mask))
+       if (cpumask_available(rcu_nocb_mask) && !cpumask_empty(rcu_nocb_mask))
                WARN_ON(sched_setaffinity(current->pid, rcu_nocb_mask));
 }
 EXPORT_SYMBOL_GPL(rcu_bind_current_to_nocb);
index 07845dcd33c5e32b369151e5604a3014c2b1764a..efd0c87d2ffae5ba409b2ac4a41c65988c890abe 100644 (file)
@@ -1220,7 +1220,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
                    cpu != outgoingcpu)
                        cpumask_set_cpu(cpu, cm);
        cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU));
-       if (cpumask_weight(cm) == 0)
+       if (cpumask_empty(cm))
                cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU));
        set_cpus_allowed_ptr(t, cm);
        mutex_unlock(&rnp->boost_kthread_mutex);