Skip to content

Commit 2bcd18e

Browse files
committed
rcu-tasks: Use order_base_2() instead of ilog2()
The ilog2() function can be used to generate a shift count, but it will generate the same count for a power of two as for one greater than a power of two. This results in shift counts that are larger than necessary for systems with a power-of-two number of CPUs because the CPUs are numbered from zero, so that the maximum CPU number is one less than that power of two. This commit therefore substitutes order_base_2(), which appears to have been designed for exactly this use case. Suggested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent da12301 commit 2bcd18e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/rcu/tasks.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static struct rcu_tasks rt_name = \
123123
.call_func = call, \
124124
.rtpcpu = &rt_name ## __percpu, \
125125
.name = n, \
126-
.percpu_enqueue_shift = ilog2(CONFIG_NR_CPUS) + 1, \
126+
.percpu_enqueue_shift = order_base_2(CONFIG_NR_CPUS), \
127127
.percpu_enqueue_lim = 1, \
128128
.percpu_dequeue_lim = 1, \
129129
.barrier_q_mutex = __MUTEX_INITIALIZER(rt_name.barrier_q_mutex), \
@@ -302,7 +302,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
302302
if (unlikely(needadjust)) {
303303
raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags);
304304
if (rtp->percpu_enqueue_lim != nr_cpu_ids) {
305-
WRITE_ONCE(rtp->percpu_enqueue_shift, ilog2(nr_cpu_ids) + 1);
305+
WRITE_ONCE(rtp->percpu_enqueue_shift, order_base_2(nr_cpu_ids));
306306
WRITE_ONCE(rtp->percpu_dequeue_lim, nr_cpu_ids);
307307
smp_store_release(&rtp->percpu_enqueue_lim, nr_cpu_ids);
308308
pr_info("Switching %s to per-CPU callback queuing.\n", rtp->name);
@@ -417,7 +417,7 @@ static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
417417
if (rcu_task_cb_adjust && ncbs <= rcu_task_collapse_lim) {
418418
raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags);
419419
if (rtp->percpu_enqueue_lim > 1) {
420-
WRITE_ONCE(rtp->percpu_enqueue_shift, ilog2(nr_cpu_ids) + 1);
420+
WRITE_ONCE(rtp->percpu_enqueue_shift, order_base_2(nr_cpu_ids));
421421
smp_store_release(&rtp->percpu_enqueue_lim, 1);
422422
rtp->percpu_dequeue_gpseq = get_state_synchronize_rcu();
423423
pr_info("Starting switch %s to CPU-0 callback queuing.\n", rtp->name);

0 commit comments

Comments
 (0)