Skip to content

Commit 6a2c1d4

Browse files
YuryNorovpaulmckrcu
authored andcommitted
rcu: Replace cpumask_weight with cpumask_empty where appropriate
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>
1 parent e6339d3 commit 6a2c1d4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

kernel/rcu/tree_nocb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ void __init rcu_init_nohz(void)
11691169
struct rcu_data *rdp;
11701170

11711171
#if defined(CONFIG_NO_HZ_FULL)
1172-
if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
1172+
if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
11731173
need_rcu_nocb_mask = true;
11741174
#endif /* #if defined(CONFIG_NO_HZ_FULL) */
11751175

@@ -1348,7 +1348,7 @@ static void __init rcu_organize_nocb_kthreads(void)
13481348
*/
13491349
void rcu_bind_current_to_nocb(void)
13501350
{
1351-
if (cpumask_available(rcu_nocb_mask) && cpumask_weight(rcu_nocb_mask))
1351+
if (cpumask_available(rcu_nocb_mask) && !cpumask_empty(rcu_nocb_mask))
13521352
WARN_ON(sched_setaffinity(current->pid, rcu_nocb_mask));
13531353
}
13541354
EXPORT_SYMBOL_GPL(rcu_bind_current_to_nocb);

kernel/rcu/tree_plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
12201220
cpu != outgoingcpu)
12211221
cpumask_set_cpu(cpu, cm);
12221222
cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU));
1223-
if (cpumask_weight(cm) == 0)
1223+
if (cpumask_empty(cm))
12241224
cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU));
12251225
set_cpus_allowed_ptr(t, cm);
12261226
mutex_unlock(&rnp->boost_kthread_mutex);

0 commit comments

Comments
 (0)