Skip to content

Commit dc5a4f2

Browse files
committed
rcu: Switch ->dynticks to rcu_data structure, remove rcu_dynticks
This commit move ->dynticks from the rcu_dynticks structure to the rcu_data structure, replacing the field of the same name. It also updates the code to access ->dynticks from the rcu_data structure and to use the rcu_data structure rather than following to now-gone ->dynticks field to the now-gone rcu_dynticks structure. While in the area, this commit also fixes up comments. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 4c5273b commit dc5a4f2

4 files changed

Lines changed: 56 additions & 80 deletions

File tree

‎kernel/rcu/tree.c‎

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,20 @@
7373

7474
/* Data structures. */
7575

76+
/*
77+
* Steal a bit from the bottom of ->dynticks for idle entry/exit
78+
* control. Initially this is for TLB flushing.
79+
*/
80+
#define RCU_DYNTICK_CTRL_MASK 0x1
81+
#define RCU_DYNTICK_CTRL_CTR (RCU_DYNTICK_CTRL_MASK + 1)
82+
#ifndef rcu_eqs_special_exit
83+
#define rcu_eqs_special_exit() do { } while (0)
84+
#endif
85+
7686
static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = {
7787
.dynticks_nesting = 1,
7888
.dynticks_nmi_nesting = DYNTICK_IRQ_NONIDLE,
89+
.dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR),
7990
};
8091
struct rcu_state rcu_state = {
8192
.level = { &rcu_state.node[0] },
@@ -202,35 +213,21 @@ void rcu_softirq_qs(void)
202213
rcu_preempt_deferred_qs(current);
203214
}
204215

205-
/*
206-
* Steal a bit from the bottom of ->dynticks for idle entry/exit
207-
* control. Initially this is for TLB flushing.
208-
*/
209-
#define RCU_DYNTICK_CTRL_MASK 0x1
210-
#define RCU_DYNTICK_CTRL_CTR (RCU_DYNTICK_CTRL_MASK + 1)
211-
#ifndef rcu_eqs_special_exit
212-
#define rcu_eqs_special_exit() do { } while (0)
213-
#endif
214-
215-
static DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
216-
.dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR),
217-
};
218-
219216
/*
220217
* Record entry into an extended quiescent state. This is only to be
221218
* called when not already in an extended quiescent state.
222219
*/
223220
static void rcu_dynticks_eqs_enter(void)
224221
{
225-
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
222+
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
226223
int seq;
227224

228225
/*
229226
* CPUs seeing atomic_add_return() must see prior RCU read-side
230227
* critical sections, and we also must force ordering with the
231228
* next idle sojourn.
232229
*/
233-
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdtp->dynticks);
230+
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
234231
/* Better be in an extended quiescent state! */
235232
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
236233
(seq & RCU_DYNTICK_CTRL_CTR));
@@ -245,19 +242,19 @@ static void rcu_dynticks_eqs_enter(void)
245242
*/
246243
static void rcu_dynticks_eqs_exit(void)
247244
{
248-
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
245+
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
249246
int seq;
250247

251248
/*
252249
* CPUs seeing atomic_add_return() must see prior idle sojourns,
253250
* and we also must force ordering with the next RCU read-side
254251
* critical section.
255252
*/
256-
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdtp->dynticks);
253+
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
257254
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
258255
!(seq & RCU_DYNTICK_CTRL_CTR));
259256
if (seq & RCU_DYNTICK_CTRL_MASK) {
260-
atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdtp->dynticks);
257+
atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdp->dynticks);
261258
smp_mb__after_atomic(); /* _exit after clearing mask. */
262259
/* Prefer duplicate flushes to losing a flush. */
263260
rcu_eqs_special_exit();
@@ -276,11 +273,11 @@ static void rcu_dynticks_eqs_exit(void)
276273
*/
277274
static void rcu_dynticks_eqs_online(void)
278275
{
279-
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
276+
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
280277

281-
if (atomic_read(&rdtp->dynticks) & RCU_DYNTICK_CTRL_CTR)
278+
if (atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR)
282279
return;
283-
atomic_add(RCU_DYNTICK_CTRL_CTR, &rdtp->dynticks);
280+
atomic_add(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
284281
}
285282

286283
/*
@@ -290,18 +287,18 @@ static void rcu_dynticks_eqs_online(void)
290287
*/
291288
bool rcu_dynticks_curr_cpu_in_eqs(void)
292289
{
293-
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
290+
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
294291

295-
return !(atomic_read(&rdtp->dynticks) & RCU_DYNTICK_CTRL_CTR);
292+
return !(atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR);
296293
}
297294

298295
/*
299296
* Snapshot the ->dynticks counter with full ordering so as to allow
300297
* stable comparison of this counter with past and future snapshots.
301298
*/
302-
int rcu_dynticks_snap(struct rcu_dynticks *rdtp)
299+
int rcu_dynticks_snap(struct rcu_data *rdp)
303300
{
304-
int snap = atomic_add_return(0, &rdtp->dynticks);
301+
int snap = atomic_add_return(0, &rdp->dynticks);
305302

306303
return snap & ~RCU_DYNTICK_CTRL_MASK;
307304
}
@@ -316,13 +313,13 @@ static bool rcu_dynticks_in_eqs(int snap)
316313
}
317314

318315
/*
319-
* Return true if the CPU corresponding to the specified rcu_dynticks
316+
* Return true if the CPU corresponding to the specified rcu_data
320317
* structure has spent some time in an extended quiescent state since
321318
* rcu_dynticks_snap() returned the specified snapshot.
322319
*/
323-
static bool rcu_dynticks_in_eqs_since(struct rcu_dynticks *rdtp, int snap)
320+
static bool rcu_dynticks_in_eqs_since(struct rcu_data *rdp, int snap)
324321
{
325-
return snap != rcu_dynticks_snap(rdtp);
322+
return snap != rcu_dynticks_snap(rdp);
326323
}
327324

328325
/*
@@ -336,14 +333,14 @@ bool rcu_eqs_special_set(int cpu)
336333
{
337334
int old;
338335
int new;
339-
struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
336+
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
340337

341338
do {
342-
old = atomic_read(&rdtp->dynticks);
339+
old = atomic_read(&rdp->dynticks);
343340
if (old & RCU_DYNTICK_CTRL_CTR)
344341
return false;
345342
new = old | RCU_DYNTICK_CTRL_MASK;
346-
} while (atomic_cmpxchg(&rdtp->dynticks, old, new) != old);
343+
} while (atomic_cmpxchg(&rdp->dynticks, old, new) != old);
347344
return true;
348345
}
349346

@@ -360,11 +357,11 @@ bool rcu_eqs_special_set(int cpu)
360357
*/
361358
static void __maybe_unused rcu_momentary_dyntick_idle(void)
362359
{
363-
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
364360
int special;
365361

366362
raw_cpu_write(rcu_data.rcu_need_heavy_qs, false);
367-
special = atomic_add_return(2 * RCU_DYNTICK_CTRL_CTR, &rdtp->dynticks);
363+
special = atomic_add_return(2 * RCU_DYNTICK_CTRL_CTR,
364+
&this_cpu_ptr(&rcu_data)->dynticks);
368365
/* It is illegal to call this from idle state. */
369366
WARN_ON_ONCE(!(special & RCU_DYNTICK_CTRL_CTR));
370367
rcu_preempt_deferred_qs(current);
@@ -573,9 +570,7 @@ static struct rcu_node *rcu_get_root(void)
573570
static void rcu_eqs_enter(bool user)
574571
{
575572
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
576-
struct rcu_dynticks *rdtp;
577573

578-
rdtp = this_cpu_ptr(&rcu_dynticks);
579574
WARN_ON_ONCE(rdp->dynticks_nmi_nesting != DYNTICK_IRQ_NONIDLE);
580575
WRITE_ONCE(rdp->dynticks_nmi_nesting, 0);
581576
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
@@ -586,7 +581,7 @@ static void rcu_eqs_enter(bool user)
586581
}
587582

588583
lockdep_assert_irqs_disabled();
589-
trace_rcu_dyntick(TPS("Start"), rdp->dynticks_nesting, 0, rdtp->dynticks);
584+
trace_rcu_dyntick(TPS("Start"), rdp->dynticks_nesting, 0, rdp->dynticks);
590585
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
591586
rdp = this_cpu_ptr(&rcu_data);
592587
do_nocb_deferred_wakeup(rdp);
@@ -635,7 +630,7 @@ void rcu_user_enter(void)
635630

636631
/*
637632
* If we are returning from the outermost NMI handler that interrupted an
638-
* RCU-idle period, update rdtp->dynticks and rdp->dynticks_nmi_nesting
633+
* RCU-idle period, update rdp->dynticks and rdp->dynticks_nmi_nesting
639634
* to let the RCU grace-period handling know that the CPU is back to
640635
* being RCU-idle.
641636
*
@@ -645,7 +640,6 @@ void rcu_user_enter(void)
645640
static __always_inline void rcu_nmi_exit_common(bool irq)
646641
{
647642
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
648-
struct rcu_dynticks __maybe_unused *rdtp = this_cpu_ptr(&rcu_dynticks);
649643

650644
/*
651645
* Check for ->dynticks_nmi_nesting underflow and bad ->dynticks.
@@ -660,14 +654,14 @@ static __always_inline void rcu_nmi_exit_common(bool irq)
660654
* leave it in non-RCU-idle state.
661655
*/
662656
if (rdp->dynticks_nmi_nesting != 1) {
663-
trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2, rdtp->dynticks);
657+
trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2, rdp->dynticks);
664658
WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */
665659
rdp->dynticks_nmi_nesting - 2);
666660
return;
667661
}
668662

669663
/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */
670-
trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, rdtp->dynticks);
664+
trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, rdp->dynticks);
671665
WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */
672666

673667
if (irq)
@@ -742,11 +736,9 @@ void rcu_irq_exit_irqson(void)
742736
static void rcu_eqs_exit(bool user)
743737
{
744738
struct rcu_data *rdp;
745-
struct rcu_dynticks *rdtp;
746739
long oldval;
747740

748741
lockdep_assert_irqs_disabled();
749-
rdtp = this_cpu_ptr(&rcu_dynticks);
750742
rdp = this_cpu_ptr(&rcu_data);
751743
oldval = rdp->dynticks_nesting;
752744
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && oldval < 0);
@@ -757,7 +749,7 @@ static void rcu_eqs_exit(bool user)
757749
rcu_dynticks_task_exit();
758750
rcu_dynticks_eqs_exit();
759751
rcu_cleanup_after_idle();
760-
trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, rdtp->dynticks);
752+
trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, rdp->dynticks);
761753
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
762754
WRITE_ONCE(rdp->dynticks_nesting, 1);
763755
WARN_ON_ONCE(rdp->dynticks_nmi_nesting);
@@ -802,7 +794,7 @@ void rcu_user_exit(void)
802794
* rcu_nmi_enter_common - inform RCU of entry to NMI context
803795
* @irq: Is this call from rcu_irq_enter?
804796
*
805-
* If the CPU was idle from RCU's viewpoint, update rdtp->dynticks and
797+
* If the CPU was idle from RCU's viewpoint, update rdp->dynticks and
806798
* rdp->dynticks_nmi_nesting to let the RCU grace-period handling know
807799
* that the CPU is active. This implementation permits nested NMIs, as
808800
* long as the nesting level does not overflow an int. (You will probably
@@ -814,7 +806,6 @@ void rcu_user_exit(void)
814806
static __always_inline void rcu_nmi_enter_common(bool irq)
815807
{
816808
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
817-
struct rcu_dynticks __maybe_unused *rdtp = this_cpu_ptr(&rcu_dynticks);
818809
long incby = 2;
819810

820811
/* Complain about underflow. */
@@ -842,7 +833,7 @@ static __always_inline void rcu_nmi_enter_common(bool irq)
842833
}
843834
trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
844835
rdp->dynticks_nmi_nesting,
845-
rdp->dynticks_nmi_nesting + incby, rdtp->dynticks);
836+
rdp->dynticks_nmi_nesting + incby, rdp->dynticks);
846837
WRITE_ONCE(rdp->dynticks_nmi_nesting, /* Prevent store tearing. */
847838
rdp->dynticks_nmi_nesting + incby);
848839
barrier();
@@ -995,7 +986,7 @@ static void rcu_gpnum_ovf(struct rcu_node *rnp, struct rcu_data *rdp)
995986
*/
996987
static int dyntick_save_progress_counter(struct rcu_data *rdp)
997988
{
998-
rdp->dynticks_snap = rcu_dynticks_snap(rdp->dynticks);
989+
rdp->dynticks_snap = rcu_dynticks_snap(rdp);
999990
if (rcu_dynticks_in_eqs(rdp->dynticks_snap)) {
1000991
trace_rcu_fqs(rcu_state.name, rdp->gp_seq, rdp->cpu, TPS("dti"));
1001992
rcu_gpnum_ovf(rdp->mynode, rdp);
@@ -1046,7 +1037,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
10461037
* read-side critical section that started before the beginning
10471038
* of the current RCU grace period.
10481039
*/
1049-
if (rcu_dynticks_in_eqs_since(rdp->dynticks, rdp->dynticks_snap)) {
1040+
if (rcu_dynticks_in_eqs_since(rdp, rdp->dynticks_snap)) {
10501041
trace_rcu_fqs(rcu_state.name, rdp->gp_seq, rdp->cpu, TPS("dti"));
10511042
rdp->dynticks_fqs++;
10521043
rcu_gpnum_ovf(rnp, rdp);
@@ -3198,9 +3189,8 @@ rcu_boot_init_percpu_data(int cpu)
31983189

31993190
/* Set up local state, ensuring consistent view of global state. */
32003191
rdp->grpmask = leaf_node_cpu_bit(rdp->mynode, cpu);
3201-
rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
32023192
WARN_ON_ONCE(rdp->dynticks_nesting != 1);
3203-
WARN_ON_ONCE(rcu_dynticks_in_eqs(rcu_dynticks_snap(rdp->dynticks)));
3193+
WARN_ON_ONCE(rcu_dynticks_in_eqs(rcu_dynticks_snap(rdp)));
32043194
rdp->rcu_ofl_gp_seq = rcu_state.gp_seq;
32053195
rdp->rcu_ofl_gp_flags = RCU_GP_CLEANED;
32063196
rdp->rcu_onl_gp_seq = rcu_state.gp_seq;

‎kernel/rcu/tree.h‎

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434

3535
#include "rcu_segcblist.h"
3636

37-
/*
38-
* Dynticks per-CPU state.
39-
*/
40-
struct rcu_dynticks {
41-
atomic_t dynticks; /* Even value for idle, else odd. */
42-
};
43-
4437
/* Communicate arguments to a workqueue handler. */
4538
struct rcu_exp_work {
4639
smp_call_func_t rew_func;
@@ -194,24 +187,20 @@ struct rcu_data {
194187
long blimit; /* Upper limit on a processed batch */
195188

196189
/* 3) dynticks interface. */
197-
struct rcu_dynticks *dynticks; /* Shared per-CPU dynticks state. */
198190
int dynticks_snap; /* Per-GP tracking for dynticks. */
199-
long dynticks_nesting; /* Track process nesting level. */
200-
long dynticks_nmi_nesting; /* Track irq/NMI nesting level. */
201-
// atomic_t dynticks; /* Even value for idle, else odd. */
202-
bool rcu_need_heavy_qs; /* GP old, need heavy quiescent state. */
203-
bool rcu_urgent_qs; /* GP old need light quiescent state. */
191+
long dynticks_nesting; /* Track process nesting level. */
192+
long dynticks_nmi_nesting; /* Track irq/NMI nesting level. */
193+
atomic_t dynticks; /* Even value for idle, else odd. */
194+
bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */
195+
bool rcu_urgent_qs; /* GP old need light quiescent state. */
204196
#ifdef CONFIG_RCU_FAST_NO_HZ
205-
bool all_lazy; /* Are all CPU's CBs lazy? */
206-
unsigned long nonlazy_posted;
207-
/* # times non-lazy CBs posted to CPU. */
197+
bool all_lazy; /* Are all CPU's CBs lazy? */
198+
unsigned long nonlazy_posted; /* # times non-lazy CB posted to CPU. */
208199
unsigned long nonlazy_posted_snap;
209-
/* idle-period nonlazy_posted snapshot. */
210-
unsigned long last_accelerate;
211-
/* Last jiffy CBs were accelerated. */
212-
unsigned long last_advance_all;
213-
/* Last jiffy CBs were all advanced. */
214-
int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
200+
/* Nonlazy_posted snapshot. */
201+
unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */
202+
unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */
203+
int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
215204
#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */
216205

217206
/* 4) reasons this CPU needed to be kicked by force_quiescent_state */
@@ -426,7 +415,7 @@ extern struct rcu_state rcu_bh_state;
426415
extern struct rcu_state rcu_preempt_state;
427416
#endif /* #ifdef CONFIG_PREEMPT_RCU */
428417

429-
int rcu_dynticks_snap(struct rcu_dynticks *rdtp);
418+
int rcu_dynticks_snap(struct rcu_data *rdp);
430419

431420
#ifdef CONFIG_RCU_BOOST
432421
DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);

‎kernel/rcu/tree_exp.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,13 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp)
360360
for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
361361
unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
362362
struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
363-
struct rcu_dynticks *rdtp = per_cpu_ptr(&rcu_dynticks, cpu);
364363
int snap;
365364

366365
if (raw_smp_processor_id() == cpu ||
367366
!(rnp->qsmaskinitnext & mask)) {
368367
mask_ofl_test |= mask;
369368
} else {
370-
snap = rcu_dynticks_snap(rdtp);
369+
snap = rcu_dynticks_snap(rdp);
371370
if (rcu_dynticks_in_eqs(snap))
372371
mask_ofl_test |= mask;
373372
else
@@ -393,8 +392,7 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp)
393392
if (!(mask_ofl_ipi & mask))
394393
continue;
395394
retry_ipi:
396-
if (rcu_dynticks_in_eqs_since(rdp->dynticks,
397-
rdp->exp_dynticks_snap)) {
395+
if (rcu_dynticks_in_eqs_since(rdp, rdp->exp_dynticks_snap)) {
398396
mask_ofl_test |= mask;
399397
continue;
400398
}

‎kernel/rcu/tree_plugin.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,6 @@ static void print_cpu_stall_info(int cpu)
18021802
unsigned long delta;
18031803
char fast_no_hz[72];
18041804
struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
1805-
struct rcu_dynticks *rdtp = rdp->dynticks;
18061805
char *ticks_title;
18071806
unsigned long ticks_value;
18081807

@@ -1830,7 +1829,7 @@ static void print_cpu_stall_info(int cpu)
18301829
rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
18311830
"!."[!delta],
18321831
ticks_value, ticks_title,
1833-
rcu_dynticks_snap(rdtp) & 0xfff,
1832+
rcu_dynticks_snap(rdp) & 0xfff,
18341833
rdp->dynticks_nesting, rdp->dynticks_nmi_nesting,
18351834
rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
18361835
READ_ONCE(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,

0 commit comments

Comments
 (0)