Skip to content

Commit

Permalink
rcu-tasks: Introduce ->percpu_enqueue_shift for dynamic queue selection
Browse files Browse the repository at this point in the history
This commit introduces a ->percpu_enqueue_shift field to the rcu_tasks
structure, and uses it to shift down the CPU number in order to
select a rcu_tasks_percpu structure.  This field is currently set to a
sufficiently large shift count to always select the CPU-0 instance of
the rcu_tasks_percpu structure, and later commits will adjust this.

Reported-by: Martin Lau <kafai@fb.com>
Cc: Neeraj Upadhyay <neeraj.iitr10@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
  • Loading branch information
Paul E. McKenney committed Dec 8, 2021
1 parent cafafd6 commit 7a30871
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernel/rcu/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct rcu_tasks_percpu {
* @postgp_func: This flavor's post-grace-period function (optional).
* @call_func: This flavor's call_rcu()-equivalent function.
* @rtpcpu: This flavor's rcu_tasks_percpu structure.
* @percpu_enqueue_shift: Shift down CPU ID this much when enqueuing callbacks.
* @name: This flavor's textual name.
* @kname: This flavor's kthread name.
*/
Expand All @@ -75,6 +76,7 @@ struct rcu_tasks {
postgp_func_t postgp_func;
call_rcu_func_t call_func;
struct rcu_tasks_percpu __percpu *rtpcpu;
int percpu_enqueue_shift;
char *name;
char *kname;
};
Expand All @@ -91,6 +93,7 @@ static struct rcu_tasks rt_name = \
.call_func = call, \
.rtpcpu = &rt_name ## __percpu, \
.name = n, \
.percpu_enqueue_shift = ilog2(CONFIG_NR_CPUS), \
.kname = #rt_name, \
}

Expand Down Expand Up @@ -169,6 +172,7 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
unsigned long flags;

raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags);
rtp->percpu_enqueue_shift = ilog2(nr_cpu_ids);
for_each_possible_cpu(cpu) {
struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu);

Expand All @@ -195,7 +199,8 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
rhp->next = NULL;
rhp->func = func;
local_irq_save(flags);
rtpcp = per_cpu_ptr(rtp->rtpcpu, 0 /* smp_processor_id() */);
rtpcp = per_cpu_ptr(rtp->rtpcpu,
smp_processor_id() >> READ_ONCE(rtp->percpu_enqueue_shift));
raw_spin_lock(&rtpcp->cbs_pcpu_lock);
if (!rtpcp->cbs_tail) {
raw_spin_unlock(&rtpcp->cbs_pcpu_lock); // irqs remain disabled.
Expand Down

0 comments on commit 7a30871

Please sign in to comment.