Skip to content

Commit 5ae0f1b

Browse files
committed
rcu: Create and use an rcu_rdp_cpu_online()
The pattern "rdp->grpmask & rcu_rnp_online_cpus(rnp)" occurs frequently in RCU code in order to determine whether rdp->cpu is online from an RCU perspective. This commit therefore creates an rcu_rdp_cpu_online() function to replace it. [ paulmck: Apply kernel test robot unused-variable feedback. ] Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 80b3fd4 commit 5ae0f1b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

kernel/rcu/tree.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ static unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)
222222
return READ_ONCE(rnp->qsmaskinitnext);
223223
}
224224

225+
/*
226+
* Is the CPU corresponding to the specified rcu_data structure online
227+
* from RCU's perspective? This perspective is given by that structure's
228+
* ->qsmaskinitnext field rather than by the global cpu_online_mask.
229+
*/
230+
static bool rcu_rdp_cpu_online(struct rcu_data *rdp)
231+
{
232+
return !!(rdp->grpmask & rcu_rnp_online_cpus(rdp->mynode));
233+
}
234+
225235
/*
226236
* Return true if an RCU grace period is in progress. The READ_ONCE()s
227237
* permit this function to be invoked without holding the root rcu_node
@@ -1168,23 +1178,20 @@ void rcu_request_urgent_qs_task(struct task_struct *t)
11681178
bool rcu_lockdep_current_cpu_online(void)
11691179
{
11701180
struct rcu_data *rdp;
1171-
struct rcu_node *rnp;
11721181
bool ret = false;
11731182

11741183
if (in_nmi() || !rcu_scheduler_fully_active)
11751184
return true;
11761185
preempt_disable_notrace();
11771186
rdp = this_cpu_ptr(&rcu_data);
1178-
rnp = rdp->mynode;
11791187
/*
11801188
* Strictly, we care here about the case where the current CPU is
11811189
* in rcu_cpu_starting() and thus has an excuse for rdp->grpmask
11821190
* not being up to date. So arch_spin_is_locked() might have a
11831191
* false positive if it's held by some *other* CPU, but that's
11841192
* OK because that just means a false *negative* on the warning.
11851193
*/
1186-
if (rdp->grpmask & rcu_rnp_online_cpus(rnp) ||
1187-
arch_spin_is_locked(&rcu_state.ofl_lock))
1194+
if (rcu_rdp_cpu_online(rdp) || arch_spin_is_locked(&rcu_state.ofl_lock))
11881195
ret = true;
11891196
preempt_enable_notrace();
11901197
return ret;
@@ -1269,8 +1276,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
12691276
* For more detail, please refer to the "Hotplug CPU" section
12701277
* of RCU's Requirements documentation.
12711278
*/
1272-
if (WARN_ON_ONCE(!(rdp->grpmask & rcu_rnp_online_cpus(rnp)))) {
1273-
bool onl;
1279+
if (WARN_ON_ONCE(!rcu_rdp_cpu_online(rdp))) {
12741280
struct rcu_node *rnp1;
12751281

12761282
pr_info("%s: grp: %d-%d level: %d ->gp_seq %ld ->completedqs %ld\n",
@@ -1279,9 +1285,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
12791285
for (rnp1 = rnp; rnp1; rnp1 = rnp1->parent)
12801286
pr_info("%s: %d:%d ->qsmask %#lx ->qsmaskinit %#lx ->qsmaskinitnext %#lx ->rcu_gp_init_mask %#lx\n",
12811287
__func__, rnp1->grplo, rnp1->grphi, rnp1->qsmask, rnp1->qsmaskinit, rnp1->qsmaskinitnext, rnp1->rcu_gp_init_mask);
1282-
onl = !!(rdp->grpmask & rcu_rnp_online_cpus(rnp));
12831288
pr_info("%s %d: %c online: %ld(%d) offline: %ld(%d)\n",
1284-
__func__, rdp->cpu, ".o"[onl],
1289+
__func__, rdp->cpu, ".o"[rcu_rdp_cpu_online(rdp)],
12851290
(long)rdp->rcu_onl_gp_seq, rdp->rcu_onl_gp_flags,
12861291
(long)rdp->rcu_ofl_gp_seq, rdp->rcu_ofl_gp_flags);
12871292
return 1; /* Break things loose after complaining. */

kernel/rcu/tree_plugin.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void rcu_note_context_switch(bool preempt)
330330
* then queue the task as required based on the states
331331
* of any ongoing and expedited grace periods.
332332
*/
333-
WARN_ON_ONCE((rdp->grpmask & rcu_rnp_online_cpus(rnp)) == 0);
333+
WARN_ON_ONCE(!rcu_rdp_cpu_online(rdp));
334334
WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
335335
trace_rcu_preempt_task(rcu_state.name,
336336
t->pid,
@@ -773,7 +773,6 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck)
773773
int cpu;
774774
int i;
775775
struct list_head *lhp;
776-
bool onl;
777776
struct rcu_data *rdp;
778777
struct rcu_node *rnp1;
779778

@@ -797,9 +796,8 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck)
797796
pr_cont("\n");
798797
for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++) {
799798
rdp = per_cpu_ptr(&rcu_data, cpu);
800-
onl = !!(rdp->grpmask & rcu_rnp_online_cpus(rnp));
801799
pr_info("\t%d: %c online: %ld(%d) offline: %ld(%d)\n",
802-
cpu, ".o"[onl],
800+
cpu, ".o"[rcu_rdp_cpu_online(rdp)],
803801
(long)rdp->rcu_onl_gp_seq, rdp->rcu_onl_gp_flags,
804802
(long)rdp->rcu_ofl_gp_seq, rdp->rcu_ofl_gp_flags);
805803
}

0 commit comments

Comments
 (0)