rcu: Detect stalls caused by failure to propagate up rcu_node tree
[deliverable/linux.git] / kernel / rcu / tree.c
CommitLineData
64db4cff
PM
1/*
2 * Read-Copy Update mechanism for mutual exclusion
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
87de1cfd
PM
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
64db4cff
PM
17 *
18 * Copyright IBM Corporation, 2008
19 *
20 * Authors: Dipankar Sarma <dipankar@in.ibm.com>
21 * Manfred Spraul <manfred@colorfullife.com>
22 * Paul E. McKenney <paulmck@linux.vnet.ibm.com> Hierarchical version
23 *
24 * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
25 * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
26 *
27 * For detailed explanation of Read-Copy Update mechanism see -
a71fca58 28 * Documentation/RCU
64db4cff
PM
29 */
30#include <linux/types.h>
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/spinlock.h>
34#include <linux/smp.h>
35#include <linux/rcupdate.h>
36#include <linux/interrupt.h>
37#include <linux/sched.h>
c1dc0b9c 38#include <linux/nmi.h>
8826f3b0 39#include <linux/atomic.h>
64db4cff 40#include <linux/bitops.h>
9984de1a 41#include <linux/export.h>
64db4cff
PM
42#include <linux/completion.h>
43#include <linux/moduleparam.h>
4102adab 44#include <linux/module.h>
64db4cff
PM
45#include <linux/percpu.h>
46#include <linux/notifier.h>
47#include <linux/cpu.h>
48#include <linux/mutex.h>
49#include <linux/time.h>
bbad9379 50#include <linux/kernel_stat.h>
a26ac245
PM
51#include <linux/wait.h>
52#include <linux/kthread.h>
268bb0ce 53#include <linux/prefetch.h>
3d3b7db0
PM
54#include <linux/delay.h>
55#include <linux/stop_machine.h>
661a85dc 56#include <linux/random.h>
f7f7bac9 57#include <linux/ftrace_event.h>
d1d74d14 58#include <linux/suspend.h>
64db4cff 59
4102adab 60#include "tree.h"
29c00b4a 61#include "rcu.h"
9f77da9f 62
4102adab
PM
63MODULE_ALIAS("rcutree");
64#ifdef MODULE_PARAM_PREFIX
65#undef MODULE_PARAM_PREFIX
66#endif
67#define MODULE_PARAM_PREFIX "rcutree."
68
64db4cff
PM
69/* Data structures. */
70
f885b7f2 71static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
394f2769 72static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS];
88b91c7c 73
f7f7bac9
SRRH
74/*
75 * In order to export the rcu_state name to the tracing tools, it
76 * needs to be added in the __tracepoint_string section.
77 * This requires defining a separate variable tp_<sname>_varname
78 * that points to the string being used, and this will allow
79 * the tracing userspace tools to be able to decipher the string
80 * address to the matching string.
81 */
a8a29b3b
AB
82#ifdef CONFIG_TRACING
83# define DEFINE_RCU_TPS(sname) \
f7f7bac9 84static char sname##_varname[] = #sname; \
a8a29b3b
AB
85static const char *tp_##sname##_varname __used __tracepoint_string = sname##_varname;
86# define RCU_STATE_NAME(sname) sname##_varname
87#else
88# define DEFINE_RCU_TPS(sname)
89# define RCU_STATE_NAME(sname) __stringify(sname)
90#endif
91
92#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \
93DEFINE_RCU_TPS(sname) \
a41bfeb2 94struct rcu_state sname##_state = { \
6c90cc7b 95 .level = { &sname##_state.node[0] }, \
037b64ed 96 .call = cr, \
af446b70 97 .fqs_state = RCU_GP_IDLE, \
42c3533e
PM
98 .gpnum = 0UL - 300UL, \
99 .completed = 0UL - 300UL, \
7b2e6011 100 .orphan_lock = __RAW_SPIN_LOCK_UNLOCKED(&sname##_state.orphan_lock), \
6c90cc7b
PM
101 .orphan_nxttail = &sname##_state.orphan_nxtlist, \
102 .orphan_donetail = &sname##_state.orphan_donelist, \
7be7f0be 103 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \
a4fbe35a 104 .onoff_mutex = __MUTEX_INITIALIZER(sname##_state.onoff_mutex), \
a8a29b3b 105 .name = RCU_STATE_NAME(sname), \
a4889858 106 .abbr = sabbr, \
a41bfeb2 107}; \
11bbb235 108DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, sname##_data)
64db4cff 109
a41bfeb2
SRRH
110RCU_STATE_INITIALIZER(rcu_sched, 's', call_rcu_sched);
111RCU_STATE_INITIALIZER(rcu_bh, 'b', call_rcu_bh);
b1f77b05 112
e534165b 113static struct rcu_state *rcu_state_p;
6ce75a23 114LIST_HEAD(rcu_struct_flavors);
27f4d280 115
f885b7f2
PM
116/* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */
117static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF;
7e5c2dfb 118module_param(rcu_fanout_leaf, int, 0444);
f885b7f2
PM
119int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
120static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */
121 NUM_RCU_LVL_0,
122 NUM_RCU_LVL_1,
123 NUM_RCU_LVL_2,
124 NUM_RCU_LVL_3,
125 NUM_RCU_LVL_4,
126};
127int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
128
b0d30417
PM
129/*
130 * The rcu_scheduler_active variable transitions from zero to one just
131 * before the first task is spawned. So when this variable is zero, RCU
132 * can assume that there is but one task, allowing RCU to (for example)
b44f6656 133 * optimize synchronize_sched() to a simple barrier(). When this variable
b0d30417
PM
134 * is one, RCU must actually do all the hard work required to detect real
135 * grace periods. This variable is also used to suppress boot-time false
136 * positives from lockdep-RCU error checking.
137 */
bbad9379
PM
138int rcu_scheduler_active __read_mostly;
139EXPORT_SYMBOL_GPL(rcu_scheduler_active);
140
b0d30417
PM
141/*
142 * The rcu_scheduler_fully_active variable transitions from zero to one
143 * during the early_initcall() processing, which is after the scheduler
144 * is capable of creating new tasks. So RCU processing (for example,
145 * creating tasks for RCU priority boosting) must be delayed until after
146 * rcu_scheduler_fully_active transitions from zero to one. We also
147 * currently delay invocation of any RCU callbacks until after this point.
148 *
149 * It might later prove better for people registering RCU callbacks during
150 * early boot to take responsibility for these callbacks, but one step at
151 * a time.
152 */
153static int rcu_scheduler_fully_active __read_mostly;
154
5d01bbd1 155static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
a46e0899
PM
156static void invoke_rcu_core(void);
157static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
a26ac245 158
a94844b2
PM
159/* rcuc/rcub kthread realtime priority */
160static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO;
161module_param(kthread_prio, int, 0644);
162
4a298656
PM
163/*
164 * Track the rcutorture test sequence number and the update version
165 * number within a given test. The rcutorture_testseq is incremented
166 * on every rcutorture module load and unload, so has an odd value
167 * when a test is running. The rcutorture_vernum is set to zero
168 * when rcutorture starts and is incremented on each rcutorture update.
169 * These variables enable correlating rcutorture output with the
170 * RCU tracing information.
171 */
172unsigned long rcutorture_testseq;
173unsigned long rcutorture_vernum;
174
fc2219d4
PM
175/*
176 * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s
177 * permit this function to be invoked without holding the root rcu_node
178 * structure's ->lock, but of course results can be subject to change.
179 */
180static int rcu_gp_in_progress(struct rcu_state *rsp)
181{
182 return ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum);
183}
184
b1f77b05 185/*
d6714c22 186 * Note a quiescent state. Because we do not need to know
b1f77b05 187 * how many quiescent states passed, just if there was at least
d6714c22 188 * one since the start of the grace period, this just sets a flag.
e4cc1f22 189 * The caller must have disabled preemption.
b1f77b05 190 */
284a8c93 191void rcu_sched_qs(void)
b1f77b05 192{
284a8c93
PM
193 if (!__this_cpu_read(rcu_sched_data.passed_quiesce)) {
194 trace_rcu_grace_period(TPS("rcu_sched"),
195 __this_cpu_read(rcu_sched_data.gpnum),
196 TPS("cpuqs"));
197 __this_cpu_write(rcu_sched_data.passed_quiesce, 1);
198 }
b1f77b05
IM
199}
200
284a8c93 201void rcu_bh_qs(void)
b1f77b05 202{
284a8c93
PM
203 if (!__this_cpu_read(rcu_bh_data.passed_quiesce)) {
204 trace_rcu_grace_period(TPS("rcu_bh"),
205 __this_cpu_read(rcu_bh_data.gpnum),
206 TPS("cpuqs"));
207 __this_cpu_write(rcu_bh_data.passed_quiesce, 1);
208 }
b1f77b05 209}
64db4cff 210
4a81e832
PM
211static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
212
213static DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
214 .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE,
215 .dynticks = ATOMIC_INIT(1),
216#ifdef CONFIG_NO_HZ_FULL_SYSIDLE
217 .dynticks_idle_nesting = DYNTICK_TASK_NEST_VALUE,
218 .dynticks_idle = ATOMIC_INIT(1),
219#endif /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
220};
221
5cd37193
PM
222DEFINE_PER_CPU_SHARED_ALIGNED(unsigned long, rcu_qs_ctr);
223EXPORT_PER_CPU_SYMBOL_GPL(rcu_qs_ctr);
224
4a81e832
PM
225/*
226 * Let the RCU core know that this CPU has gone through the scheduler,
227 * which is a quiescent state. This is called when the need for a
228 * quiescent state is urgent, so we burn an atomic operation and full
229 * memory barriers to let the RCU core know about it, regardless of what
230 * this CPU might (or might not) do in the near future.
231 *
232 * We inform the RCU core by emulating a zero-duration dyntick-idle
233 * period, which we in turn do by incrementing the ->dynticks counter
234 * by two.
235 */
236static void rcu_momentary_dyntick_idle(void)
237{
238 unsigned long flags;
239 struct rcu_data *rdp;
240 struct rcu_dynticks *rdtp;
241 int resched_mask;
242 struct rcu_state *rsp;
243
244 local_irq_save(flags);
245
246 /*
247 * Yes, we can lose flag-setting operations. This is OK, because
248 * the flag will be set again after some delay.
249 */
250 resched_mask = raw_cpu_read(rcu_sched_qs_mask);
251 raw_cpu_write(rcu_sched_qs_mask, 0);
252
253 /* Find the flavor that needs a quiescent state. */
254 for_each_rcu_flavor(rsp) {
255 rdp = raw_cpu_ptr(rsp->rda);
256 if (!(resched_mask & rsp->flavor_mask))
257 continue;
258 smp_mb(); /* rcu_sched_qs_mask before cond_resched_completed. */
259 if (ACCESS_ONCE(rdp->mynode->completed) !=
260 ACCESS_ONCE(rdp->cond_resched_completed))
261 continue;
262
263 /*
264 * Pretend to be momentarily idle for the quiescent state.
265 * This allows the grace-period kthread to record the
266 * quiescent state, with no need for this CPU to do anything
267 * further.
268 */
269 rdtp = this_cpu_ptr(&rcu_dynticks);
270 smp_mb__before_atomic(); /* Earlier stuff before QS. */
271 atomic_add(2, &rdtp->dynticks); /* QS. */
272 smp_mb__after_atomic(); /* Later stuff after QS. */
273 break;
274 }
275 local_irq_restore(flags);
276}
277
25502a6c
PM
278/*
279 * Note a context switch. This is a quiescent state for RCU-sched,
280 * and requires special handling for preemptible RCU.
e4cc1f22 281 * The caller must have disabled preemption.
25502a6c 282 */
38200cf2 283void rcu_note_context_switch(void)
25502a6c 284{
f7f7bac9 285 trace_rcu_utilization(TPS("Start context switch"));
284a8c93 286 rcu_sched_qs();
38200cf2 287 rcu_preempt_note_context_switch();
4a81e832
PM
288 if (unlikely(raw_cpu_read(rcu_sched_qs_mask)))
289 rcu_momentary_dyntick_idle();
f7f7bac9 290 trace_rcu_utilization(TPS("End context switch"));
25502a6c 291}
29ce8310 292EXPORT_SYMBOL_GPL(rcu_note_context_switch);
25502a6c 293
5cd37193
PM
294/*
295 * Register a quiesecent state for all RCU flavors. If there is an
296 * emergency, invoke rcu_momentary_dyntick_idle() to do a heavy-weight
297 * dyntick-idle quiescent state visible to other CPUs (but only for those
298 * RCU flavors in desparate need of a quiescent state, which will normally
299 * be none of them). Either way, do a lightweight quiescent state for
300 * all RCU flavors.
301 */
302void rcu_all_qs(void)
303{
304 if (unlikely(raw_cpu_read(rcu_sched_qs_mask)))
305 rcu_momentary_dyntick_idle();
306 this_cpu_inc(rcu_qs_ctr);
307}
308EXPORT_SYMBOL_GPL(rcu_all_qs);
309
878d7439
ED
310static long blimit = 10; /* Maximum callbacks per rcu_do_batch. */
311static long qhimark = 10000; /* If this many pending, ignore blimit. */
312static long qlowmark = 100; /* Once only this many pending, use blimit. */
64db4cff 313
878d7439
ED
314module_param(blimit, long, 0444);
315module_param(qhimark, long, 0444);
316module_param(qlowmark, long, 0444);
3d76c082 317
026ad283
PM
318static ulong jiffies_till_first_fqs = ULONG_MAX;
319static ulong jiffies_till_next_fqs = ULONG_MAX;
d40011f6
PM
320
321module_param(jiffies_till_first_fqs, ulong, 0644);
322module_param(jiffies_till_next_fqs, ulong, 0644);
323
4a81e832
PM
324/*
325 * How long the grace period must be before we start recruiting
326 * quiescent-state help from rcu_note_context_switch().
327 */
328static ulong jiffies_till_sched_qs = HZ / 20;
329module_param(jiffies_till_sched_qs, ulong, 0644);
330
48a7639c 331static bool rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
910ee45d 332 struct rcu_data *rdp);
217af2a2
PM
333static void force_qs_rnp(struct rcu_state *rsp,
334 int (*f)(struct rcu_data *rsp, bool *isidle,
335 unsigned long *maxj),
336 bool *isidle, unsigned long *maxj);
4cdfc175 337static void force_quiescent_state(struct rcu_state *rsp);
e3950ecd 338static int rcu_pending(void);
64db4cff
PM
339
340/*
917963d0 341 * Return the number of RCU batches started thus far for debug & stats.
64db4cff 342 */
917963d0
PM
343unsigned long rcu_batches_started(void)
344{
345 return rcu_state_p->gpnum;
346}
347EXPORT_SYMBOL_GPL(rcu_batches_started);
348
349/*
350 * Return the number of RCU-sched batches started thus far for debug & stats.
64db4cff 351 */
917963d0
PM
352unsigned long rcu_batches_started_sched(void)
353{
354 return rcu_sched_state.gpnum;
355}
356EXPORT_SYMBOL_GPL(rcu_batches_started_sched);
357
358/*
359 * Return the number of RCU BH batches started thus far for debug & stats.
360 */
361unsigned long rcu_batches_started_bh(void)
362{
363 return rcu_bh_state.gpnum;
364}
365EXPORT_SYMBOL_GPL(rcu_batches_started_bh);
366
367/*
368 * Return the number of RCU batches completed thus far for debug & stats.
369 */
370unsigned long rcu_batches_completed(void)
371{
372 return rcu_state_p->completed;
373}
374EXPORT_SYMBOL_GPL(rcu_batches_completed);
375
376/*
377 * Return the number of RCU-sched batches completed thus far for debug & stats.
64db4cff 378 */
9733e4f0 379unsigned long rcu_batches_completed_sched(void)
64db4cff 380{
d6714c22 381 return rcu_sched_state.completed;
64db4cff 382}
d6714c22 383EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
64db4cff
PM
384
385/*
917963d0 386 * Return the number of RCU BH batches completed thus far for debug & stats.
64db4cff 387 */
9733e4f0 388unsigned long rcu_batches_completed_bh(void)
64db4cff
PM
389{
390 return rcu_bh_state.completed;
391}
392EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
393
a381d757
ACB
394/*
395 * Force a quiescent state.
396 */
397void rcu_force_quiescent_state(void)
398{
e534165b 399 force_quiescent_state(rcu_state_p);
a381d757
ACB
400}
401EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
402
bf66f18e
PM
403/*
404 * Force a quiescent state for RCU BH.
405 */
406void rcu_bh_force_quiescent_state(void)
407{
4cdfc175 408 force_quiescent_state(&rcu_bh_state);
bf66f18e
PM
409}
410EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
411
afea227f
PM
412/*
413 * Show the state of the grace-period kthreads.
414 */
415void show_rcu_gp_kthreads(void)
416{
417 struct rcu_state *rsp;
418
419 for_each_rcu_flavor(rsp) {
420 pr_info("%s: wait state: %d ->state: %#lx\n",
421 rsp->name, rsp->gp_state, rsp->gp_kthread->state);
422 /* sched_show_task(rsp->gp_kthread); */
423 }
424}
425EXPORT_SYMBOL_GPL(show_rcu_gp_kthreads);
426
4a298656
PM
427/*
428 * Record the number of times rcutorture tests have been initiated and
429 * terminated. This information allows the debugfs tracing stats to be
430 * correlated to the rcutorture messages, even when the rcutorture module
431 * is being repeatedly loaded and unloaded. In other words, we cannot
432 * store this state in rcutorture itself.
433 */
434void rcutorture_record_test_transition(void)
435{
436 rcutorture_testseq++;
437 rcutorture_vernum = 0;
438}
439EXPORT_SYMBOL_GPL(rcutorture_record_test_transition);
440
ad0dc7f9
PM
441/*
442 * Send along grace-period-related data for rcutorture diagnostics.
443 */
444void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
445 unsigned long *gpnum, unsigned long *completed)
446{
447 struct rcu_state *rsp = NULL;
448
449 switch (test_type) {
450 case RCU_FLAVOR:
e534165b 451 rsp = rcu_state_p;
ad0dc7f9
PM
452 break;
453 case RCU_BH_FLAVOR:
454 rsp = &rcu_bh_state;
455 break;
456 case RCU_SCHED_FLAVOR:
457 rsp = &rcu_sched_state;
458 break;
459 default:
460 break;
461 }
462 if (rsp != NULL) {
463 *flags = ACCESS_ONCE(rsp->gp_flags);
464 *gpnum = ACCESS_ONCE(rsp->gpnum);
465 *completed = ACCESS_ONCE(rsp->completed);
466 return;
467 }
468 *flags = 0;
469 *gpnum = 0;
470 *completed = 0;
471}
472EXPORT_SYMBOL_GPL(rcutorture_get_gp_data);
473
4a298656
PM
474/*
475 * Record the number of writer passes through the current rcutorture test.
476 * This is also used to correlate debugfs tracing stats with the rcutorture
477 * messages.
478 */
479void rcutorture_record_progress(unsigned long vernum)
480{
481 rcutorture_vernum++;
482}
483EXPORT_SYMBOL_GPL(rcutorture_record_progress);
484
bf66f18e
PM
485/*
486 * Force a quiescent state for RCU-sched.
487 */
488void rcu_sched_force_quiescent_state(void)
489{
4cdfc175 490 force_quiescent_state(&rcu_sched_state);
bf66f18e
PM
491}
492EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state);
493
64db4cff
PM
494/*
495 * Does the CPU have callbacks ready to be invoked?
496 */
497static int
498cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp)
499{
3fbfbf7a
PM
500 return &rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL] &&
501 rdp->nxttail[RCU_DONE_TAIL] != NULL;
64db4cff
PM
502}
503
365187fb
PM
504/*
505 * Return the root node of the specified rcu_state structure.
506 */
507static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
508{
509 return &rsp->node[0];
510}
511
512/*
513 * Is there any need for future grace periods?
514 * Interrupts must be disabled. If the caller does not hold the root
515 * rnp_node structure's ->lock, the results are advisory only.
516 */
517static int rcu_future_needs_gp(struct rcu_state *rsp)
518{
519 struct rcu_node *rnp = rcu_get_root(rsp);
520 int idx = (ACCESS_ONCE(rnp->completed) + 1) & 0x1;
521 int *fp = &rnp->need_future_gp[idx];
522
523 return ACCESS_ONCE(*fp);
524}
525
64db4cff 526/*
dc35c893
PM
527 * Does the current CPU require a not-yet-started grace period?
528 * The caller must have disabled interrupts to prevent races with
529 * normal callback registry.
64db4cff
PM
530 */
531static int
532cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
533{
dc35c893 534 int i;
3fbfbf7a 535
dc35c893
PM
536 if (rcu_gp_in_progress(rsp))
537 return 0; /* No, a grace period is already in progress. */
365187fb 538 if (rcu_future_needs_gp(rsp))
34ed6246 539 return 1; /* Yes, a no-CBs CPU needs one. */
dc35c893
PM
540 if (!rdp->nxttail[RCU_NEXT_TAIL])
541 return 0; /* No, this is a no-CBs (or offline) CPU. */
542 if (*rdp->nxttail[RCU_NEXT_READY_TAIL])
543 return 1; /* Yes, this CPU has newly registered callbacks. */
544 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++)
545 if (rdp->nxttail[i - 1] != rdp->nxttail[i] &&
546 ULONG_CMP_LT(ACCESS_ONCE(rsp->completed),
547 rdp->nxtcompleted[i]))
548 return 1; /* Yes, CBs for future grace period. */
549 return 0; /* No grace period needed. */
64db4cff
PM
550}
551
9b2e4f18 552/*
adf5091e 553 * rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
9b2e4f18
PM
554 *
555 * If the new value of the ->dynticks_nesting counter now is zero,
556 * we really have entered idle, and must do the appropriate accounting.
557 * The caller must have disabled interrupts.
558 */
28ced795 559static void rcu_eqs_enter_common(long long oldval, bool user)
9b2e4f18 560{
96d3fd0d
PM
561 struct rcu_state *rsp;
562 struct rcu_data *rdp;
28ced795 563 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
96d3fd0d 564
f7f7bac9 565 trace_rcu_dyntick(TPS("Start"), oldval, rdtp->dynticks_nesting);
cb349ca9 566 if (!user && !is_idle_task(current)) {
289828e6
PM
567 struct task_struct *idle __maybe_unused =
568 idle_task(smp_processor_id());
0989cb46 569
f7f7bac9 570 trace_rcu_dyntick(TPS("Error on entry: not idle task"), oldval, 0);
bf1304e9 571 ftrace_dump(DUMP_ORIG);
0989cb46
PM
572 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
573 current->pid, current->comm,
574 idle->pid, idle->comm); /* must be idle task! */
9b2e4f18 575 }
96d3fd0d
PM
576 for_each_rcu_flavor(rsp) {
577 rdp = this_cpu_ptr(rsp->rda);
578 do_nocb_deferred_wakeup(rdp);
579 }
198bbf81 580 rcu_prepare_for_idle();
9b2e4f18 581 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
4e857c58 582 smp_mb__before_atomic(); /* See above. */
9b2e4f18 583 atomic_inc(&rdtp->dynticks);
4e857c58 584 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
9b2e4f18 585 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
176f8f7a 586 rcu_dynticks_task_enter();
c44e2cdd
PM
587
588 /*
adf5091e 589 * It is illegal to enter an extended quiescent state while
c44e2cdd
PM
590 * in an RCU read-side critical section.
591 */
592 rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
593 "Illegal idle entry in RCU read-side critical section.");
594 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map),
595 "Illegal idle entry in RCU-bh read-side critical section.");
596 rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map),
597 "Illegal idle entry in RCU-sched read-side critical section.");
9b2e4f18 598}
64db4cff 599
adf5091e
FW
600/*
601 * Enter an RCU extended quiescent state, which can be either the
602 * idle loop or adaptive-tickless usermode execution.
64db4cff 603 */
adf5091e 604static void rcu_eqs_enter(bool user)
64db4cff 605{
4145fa7f 606 long long oldval;
64db4cff
PM
607 struct rcu_dynticks *rdtp;
608
c9d4b0af 609 rdtp = this_cpu_ptr(&rcu_dynticks);
4145fa7f 610 oldval = rdtp->dynticks_nesting;
29e37d81 611 WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
3a592405 612 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) {
29e37d81 613 rdtp->dynticks_nesting = 0;
28ced795 614 rcu_eqs_enter_common(oldval, user);
3a592405 615 } else {
29e37d81 616 rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
3a592405 617 }
64db4cff 618}
adf5091e
FW
619
620/**
621 * rcu_idle_enter - inform RCU that current CPU is entering idle
622 *
623 * Enter idle mode, in other words, -leave- the mode in which RCU
624 * read-side critical sections can occur. (Though RCU read-side
625 * critical sections can occur in irq handlers in idle, a possibility
626 * handled by irq_enter() and irq_exit().)
627 *
628 * We crowbar the ->dynticks_nesting field to zero to allow for
629 * the possibility of usermode upcalls having messed up our count
630 * of interrupt nesting level during the prior busy period.
631 */
632void rcu_idle_enter(void)
633{
c5d900bf
FW
634 unsigned long flags;
635
636 local_irq_save(flags);
cb349ca9 637 rcu_eqs_enter(false);
28ced795 638 rcu_sysidle_enter(0);
c5d900bf 639 local_irq_restore(flags);
adf5091e 640}
8a2ecf47 641EXPORT_SYMBOL_GPL(rcu_idle_enter);
64db4cff 642
2b1d5024 643#ifdef CONFIG_RCU_USER_QS
adf5091e
FW
644/**
645 * rcu_user_enter - inform RCU that we are resuming userspace.
646 *
647 * Enter RCU idle mode right before resuming userspace. No use of RCU
648 * is permitted between this call and rcu_user_exit(). This way the
649 * CPU doesn't need to maintain the tick for RCU maintenance purposes
650 * when the CPU runs in userspace.
651 */
652void rcu_user_enter(void)
653{
91d1aa43 654 rcu_eqs_enter(1);
adf5091e 655}
2b1d5024 656#endif /* CONFIG_RCU_USER_QS */
19dd1591 657
9b2e4f18
PM
658/**
659 * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
660 *
661 * Exit from an interrupt handler, which might possibly result in entering
662 * idle mode, in other words, leaving the mode in which read-side critical
663 * sections can occur.
64db4cff 664 *
9b2e4f18
PM
665 * This code assumes that the idle loop never does anything that might
666 * result in unbalanced calls to irq_enter() and irq_exit(). If your
667 * architecture violates this assumption, RCU will give you what you
668 * deserve, good and hard. But very infrequently and irreproducibly.
669 *
670 * Use things like work queues to work around this limitation.
671 *
672 * You have been warned.
64db4cff 673 */
9b2e4f18 674void rcu_irq_exit(void)
64db4cff
PM
675{
676 unsigned long flags;
4145fa7f 677 long long oldval;
64db4cff
PM
678 struct rcu_dynticks *rdtp;
679
680 local_irq_save(flags);
c9d4b0af 681 rdtp = this_cpu_ptr(&rcu_dynticks);
4145fa7f 682 oldval = rdtp->dynticks_nesting;
9b2e4f18
PM
683 rdtp->dynticks_nesting--;
684 WARN_ON_ONCE(rdtp->dynticks_nesting < 0);
b6fc6020 685 if (rdtp->dynticks_nesting)
f7f7bac9 686 trace_rcu_dyntick(TPS("--="), oldval, rdtp->dynticks_nesting);
b6fc6020 687 else
28ced795
CL
688 rcu_eqs_enter_common(oldval, true);
689 rcu_sysidle_enter(1);
9b2e4f18
PM
690 local_irq_restore(flags);
691}
692
693/*
adf5091e 694 * rcu_eqs_exit_common - current CPU moving away from extended quiescent state
9b2e4f18
PM
695 *
696 * If the new value of the ->dynticks_nesting counter was previously zero,
697 * we really have exited idle, and must do the appropriate accounting.
698 * The caller must have disabled interrupts.
699 */
28ced795 700static void rcu_eqs_exit_common(long long oldval, int user)
9b2e4f18 701{
28ced795
CL
702 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
703
176f8f7a 704 rcu_dynticks_task_exit();
4e857c58 705 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
23b5c8fa
PM
706 atomic_inc(&rdtp->dynticks);
707 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
4e857c58 708 smp_mb__after_atomic(); /* See above. */
23b5c8fa 709 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
8fa7845d 710 rcu_cleanup_after_idle();
f7f7bac9 711 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
cb349ca9 712 if (!user && !is_idle_task(current)) {
289828e6
PM
713 struct task_struct *idle __maybe_unused =
714 idle_task(smp_processor_id());
0989cb46 715
f7f7bac9 716 trace_rcu_dyntick(TPS("Error on exit: not idle task"),
4145fa7f 717 oldval, rdtp->dynticks_nesting);
bf1304e9 718 ftrace_dump(DUMP_ORIG);
0989cb46
PM
719 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
720 current->pid, current->comm,
721 idle->pid, idle->comm); /* must be idle task! */
9b2e4f18
PM
722 }
723}
724
adf5091e
FW
725/*
726 * Exit an RCU extended quiescent state, which can be either the
727 * idle loop or adaptive-tickless usermode execution.
9b2e4f18 728 */
adf5091e 729static void rcu_eqs_exit(bool user)
9b2e4f18 730{
9b2e4f18
PM
731 struct rcu_dynticks *rdtp;
732 long long oldval;
733
c9d4b0af 734 rdtp = this_cpu_ptr(&rcu_dynticks);
9b2e4f18 735 oldval = rdtp->dynticks_nesting;
29e37d81 736 WARN_ON_ONCE(oldval < 0);
3a592405 737 if (oldval & DYNTICK_TASK_NEST_MASK) {
29e37d81 738 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
3a592405 739 } else {
29e37d81 740 rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
28ced795 741 rcu_eqs_exit_common(oldval, user);
3a592405 742 }
9b2e4f18 743}
adf5091e
FW
744
745/**
746 * rcu_idle_exit - inform RCU that current CPU is leaving idle
747 *
748 * Exit idle mode, in other words, -enter- the mode in which RCU
749 * read-side critical sections can occur.
750 *
751 * We crowbar the ->dynticks_nesting field to DYNTICK_TASK_NEST to
752 * allow for the possibility of usermode upcalls messing up our count
753 * of interrupt nesting level during the busy period that is just
754 * now starting.
755 */
756void rcu_idle_exit(void)
757{
c5d900bf
FW
758 unsigned long flags;
759
760 local_irq_save(flags);
cb349ca9 761 rcu_eqs_exit(false);
28ced795 762 rcu_sysidle_exit(0);
c5d900bf 763 local_irq_restore(flags);
adf5091e 764}
8a2ecf47 765EXPORT_SYMBOL_GPL(rcu_idle_exit);
9b2e4f18 766
2b1d5024 767#ifdef CONFIG_RCU_USER_QS
adf5091e
FW
768/**
769 * rcu_user_exit - inform RCU that we are exiting userspace.
770 *
771 * Exit RCU idle mode while entering the kernel because it can
772 * run a RCU read side critical section anytime.
773 */
774void rcu_user_exit(void)
775{
91d1aa43 776 rcu_eqs_exit(1);
adf5091e 777}
2b1d5024 778#endif /* CONFIG_RCU_USER_QS */
19dd1591 779
9b2e4f18
PM
780/**
781 * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle
782 *
783 * Enter an interrupt handler, which might possibly result in exiting
784 * idle mode, in other words, entering the mode in which read-side critical
785 * sections can occur.
786 *
787 * Note that the Linux kernel is fully capable of entering an interrupt
788 * handler that it never exits, for example when doing upcalls to
789 * user mode! This code assumes that the idle loop never does upcalls to
790 * user mode. If your architecture does do upcalls from the idle loop (or
791 * does anything else that results in unbalanced calls to the irq_enter()
792 * and irq_exit() functions), RCU will give you what you deserve, good
793 * and hard. But very infrequently and irreproducibly.
794 *
795 * Use things like work queues to work around this limitation.
796 *
797 * You have been warned.
798 */
799void rcu_irq_enter(void)
800{
801 unsigned long flags;
802 struct rcu_dynticks *rdtp;
803 long long oldval;
804
805 local_irq_save(flags);
c9d4b0af 806 rdtp = this_cpu_ptr(&rcu_dynticks);
9b2e4f18
PM
807 oldval = rdtp->dynticks_nesting;
808 rdtp->dynticks_nesting++;
809 WARN_ON_ONCE(rdtp->dynticks_nesting == 0);
b6fc6020 810 if (oldval)
f7f7bac9 811 trace_rcu_dyntick(TPS("++="), oldval, rdtp->dynticks_nesting);
b6fc6020 812 else
28ced795
CL
813 rcu_eqs_exit_common(oldval, true);
814 rcu_sysidle_exit(1);
64db4cff 815 local_irq_restore(flags);
64db4cff
PM
816}
817
818/**
819 * rcu_nmi_enter - inform RCU of entry to NMI context
820 *
734d1680
PM
821 * If the CPU was idle from RCU's viewpoint, update rdtp->dynticks and
822 * rdtp->dynticks_nmi_nesting to let the RCU grace-period handling know
823 * that the CPU is active. This implementation permits nested NMIs, as
824 * long as the nesting level does not overflow an int. (You will probably
825 * run out of stack space first.)
64db4cff
PM
826 */
827void rcu_nmi_enter(void)
828{
c9d4b0af 829 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
734d1680 830 int incby = 2;
64db4cff 831
734d1680
PM
832 /* Complain about underflow. */
833 WARN_ON_ONCE(rdtp->dynticks_nmi_nesting < 0);
834
835 /*
836 * If idle from RCU viewpoint, atomically increment ->dynticks
837 * to mark non-idle and increment ->dynticks_nmi_nesting by one.
838 * Otherwise, increment ->dynticks_nmi_nesting by two. This means
839 * if ->dynticks_nmi_nesting is equal to one, we are guaranteed
840 * to be in the outermost NMI handler that interrupted an RCU-idle
841 * period (observation due to Andy Lutomirski).
842 */
843 if (!(atomic_read(&rdtp->dynticks) & 0x1)) {
844 smp_mb__before_atomic(); /* Force delay from prior write. */
845 atomic_inc(&rdtp->dynticks);
846 /* atomic_inc() before later RCU read-side crit sects */
847 smp_mb__after_atomic(); /* See above. */
848 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
849 incby = 1;
850 }
851 rdtp->dynticks_nmi_nesting += incby;
852 barrier();
64db4cff
PM
853}
854
855/**
856 * rcu_nmi_exit - inform RCU of exit from NMI context
857 *
734d1680
PM
858 * If we are returning from the outermost NMI handler that interrupted an
859 * RCU-idle period, update rdtp->dynticks and rdtp->dynticks_nmi_nesting
860 * to let the RCU grace-period handling know that the CPU is back to
861 * being RCU-idle.
64db4cff
PM
862 */
863void rcu_nmi_exit(void)
864{
c9d4b0af 865 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
64db4cff 866
734d1680
PM
867 /*
868 * Check for ->dynticks_nmi_nesting underflow and bad ->dynticks.
869 * (We are exiting an NMI handler, so RCU better be paying attention
870 * to us!)
871 */
872 WARN_ON_ONCE(rdtp->dynticks_nmi_nesting <= 0);
873 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
874
875 /*
876 * If the nesting level is not 1, the CPU wasn't RCU-idle, so
877 * leave it in non-RCU-idle state.
878 */
879 if (rdtp->dynticks_nmi_nesting != 1) {
880 rdtp->dynticks_nmi_nesting -= 2;
64db4cff 881 return;
734d1680
PM
882 }
883
884 /* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */
885 rdtp->dynticks_nmi_nesting = 0;
23b5c8fa 886 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
4e857c58 887 smp_mb__before_atomic(); /* See above. */
23b5c8fa 888 atomic_inc(&rdtp->dynticks);
4e857c58 889 smp_mb__after_atomic(); /* Force delay to next write. */
23b5c8fa 890 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
64db4cff
PM
891}
892
893/**
5c173eb8
PM
894 * __rcu_is_watching - are RCU read-side critical sections safe?
895 *
896 * Return true if RCU is watching the running CPU, which means that
897 * this CPU can safely enter RCU read-side critical sections. Unlike
898 * rcu_is_watching(), the caller of __rcu_is_watching() must have at
899 * least disabled preemption.
900 */
9418fb20 901bool notrace __rcu_is_watching(void)
5c173eb8
PM
902{
903 return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
904}
905
906/**
907 * rcu_is_watching - see if RCU thinks that the current CPU is idle
64db4cff 908 *
9b2e4f18 909 * If the current CPU is in its idle loop and is neither in an interrupt
34240697 910 * or NMI handler, return true.
64db4cff 911 */
9418fb20 912bool notrace rcu_is_watching(void)
64db4cff 913{
f534ed1f 914 bool ret;
34240697
PM
915
916 preempt_disable();
5c173eb8 917 ret = __rcu_is_watching();
34240697
PM
918 preempt_enable();
919 return ret;
64db4cff 920}
5c173eb8 921EXPORT_SYMBOL_GPL(rcu_is_watching);
64db4cff 922
62fde6ed 923#if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU)
c0d6d01b
PM
924
925/*
926 * Is the current CPU online? Disable preemption to avoid false positives
927 * that could otherwise happen due to the current CPU number being sampled,
928 * this task being preempted, its old CPU being taken offline, resuming
929 * on some other CPU, then determining that its old CPU is now offline.
930 * It is OK to use RCU on an offline processor during initial boot, hence
2036d94a
PM
931 * the check for rcu_scheduler_fully_active. Note also that it is OK
932 * for a CPU coming online to use RCU for one jiffy prior to marking itself
933 * online in the cpu_online_mask. Similarly, it is OK for a CPU going
934 * offline to continue to use RCU for one jiffy after marking itself
935 * offline in the cpu_online_mask. This leniency is necessary given the
936 * non-atomic nature of the online and offline processing, for example,
937 * the fact that a CPU enters the scheduler after completing the CPU_DYING
938 * notifiers.
939 *
940 * This is also why RCU internally marks CPUs online during the
941 * CPU_UP_PREPARE phase and offline during the CPU_DEAD phase.
c0d6d01b
PM
942 *
943 * Disable checking if in an NMI handler because we cannot safely report
944 * errors from NMI handlers anyway.
945 */
946bool rcu_lockdep_current_cpu_online(void)
947{
2036d94a
PM
948 struct rcu_data *rdp;
949 struct rcu_node *rnp;
c0d6d01b
PM
950 bool ret;
951
952 if (in_nmi())
f6f7ee9a 953 return true;
c0d6d01b 954 preempt_disable();
c9d4b0af 955 rdp = this_cpu_ptr(&rcu_sched_data);
2036d94a
PM
956 rnp = rdp->mynode;
957 ret = (rdp->grpmask & rnp->qsmaskinit) ||
c0d6d01b
PM
958 !rcu_scheduler_fully_active;
959 preempt_enable();
960 return ret;
961}
962EXPORT_SYMBOL_GPL(rcu_lockdep_current_cpu_online);
963
62fde6ed 964#endif /* #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU) */
9b2e4f18 965
64db4cff 966/**
9b2e4f18 967 * rcu_is_cpu_rrupt_from_idle - see if idle or immediately interrupted from idle
64db4cff 968 *
9b2e4f18
PM
969 * If the current CPU is idle or running at a first-level (not nested)
970 * interrupt from idle, return true. The caller must have at least
971 * disabled preemption.
64db4cff 972 */
62e3cb14 973static int rcu_is_cpu_rrupt_from_idle(void)
64db4cff 974{
c9d4b0af 975 return __this_cpu_read(rcu_dynticks.dynticks_nesting) <= 1;
64db4cff
PM
976}
977
64db4cff
PM
978/*
979 * Snapshot the specified CPU's dynticks counter so that we can later
980 * credit them with an implicit quiescent state. Return 1 if this CPU
1eba8f84 981 * is in dynticks idle mode, which is an extended quiescent state.
64db4cff 982 */
217af2a2
PM
983static int dyntick_save_progress_counter(struct rcu_data *rdp,
984 bool *isidle, unsigned long *maxj)
64db4cff 985{
23b5c8fa 986 rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
0edd1b17 987 rcu_sysidle_check_cpu(rdp, isidle, maxj);
7941dbde
ACB
988 if ((rdp->dynticks_snap & 0x1) == 0) {
989 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
990 return 1;
991 } else {
e3663b10
PM
992 if (ULONG_CMP_LT(ACCESS_ONCE(rdp->gpnum) + ULONG_MAX / 4,
993 rdp->mynode->gpnum))
994 ACCESS_ONCE(rdp->gpwrap) = true;
7941dbde
ACB
995 return 0;
996 }
64db4cff
PM
997}
998
999/*
1000 * Return true if the specified CPU has passed through a quiescent
1001 * state by virtue of being in or having passed through an dynticks
1002 * idle state since the last call to dyntick_save_progress_counter()
a82dcc76 1003 * for this same CPU, or by virtue of having been offline.
64db4cff 1004 */
217af2a2
PM
1005static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
1006 bool *isidle, unsigned long *maxj)
64db4cff 1007{
7eb4f455 1008 unsigned int curr;
4a81e832 1009 int *rcrmp;
7eb4f455 1010 unsigned int snap;
64db4cff 1011
7eb4f455
PM
1012 curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
1013 snap = (unsigned int)rdp->dynticks_snap;
64db4cff
PM
1014
1015 /*
1016 * If the CPU passed through or entered a dynticks idle phase with
1017 * no active irq/NMI handlers, then we can safely pretend that the CPU
1018 * already acknowledged the request to pass through a quiescent
1019 * state. Either way, that CPU cannot possibly be in an RCU
1020 * read-side critical section that started before the beginning
1021 * of the current RCU grace period.
1022 */
7eb4f455 1023 if ((curr & 0x1) == 0 || UINT_CMP_GE(curr, snap + 2)) {
f7f7bac9 1024 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
64db4cff
PM
1025 rdp->dynticks_fqs++;
1026 return 1;
1027 }
1028
a82dcc76
PM
1029 /*
1030 * Check for the CPU being offline, but only if the grace period
1031 * is old enough. We don't need to worry about the CPU changing
1032 * state: If we see it offline even once, it has been through a
1033 * quiescent state.
1034 *
1035 * The reason for insisting that the grace period be at least
1036 * one jiffy old is that CPUs that are not quite online and that
1037 * have just gone offline can still execute RCU read-side critical
1038 * sections.
1039 */
1040 if (ULONG_CMP_GE(rdp->rsp->gp_start + 2, jiffies))
1041 return 0; /* Grace period is not old enough. */
1042 barrier();
1043 if (cpu_is_offline(rdp->cpu)) {
f7f7bac9 1044 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("ofl"));
a82dcc76
PM
1045 rdp->offline_fqs++;
1046 return 1;
1047 }
65d798f0
PM
1048
1049 /*
4a81e832
PM
1050 * A CPU running for an extended time within the kernel can
1051 * delay RCU grace periods. When the CPU is in NO_HZ_FULL mode,
1052 * even context-switching back and forth between a pair of
1053 * in-kernel CPU-bound tasks cannot advance grace periods.
1054 * So if the grace period is old enough, make the CPU pay attention.
1055 * Note that the unsynchronized assignments to the per-CPU
1056 * rcu_sched_qs_mask variable are safe. Yes, setting of
1057 * bits can be lost, but they will be set again on the next
1058 * force-quiescent-state pass. So lost bit sets do not result
1059 * in incorrect behavior, merely in a grace period lasting
1060 * a few jiffies longer than it might otherwise. Because
1061 * there are at most four threads involved, and because the
1062 * updates are only once every few jiffies, the probability of
1063 * lossage (and thus of slight grace-period extension) is
1064 * quite low.
1065 *
1066 * Note that if the jiffies_till_sched_qs boot/sysfs parameter
1067 * is set too high, we override with half of the RCU CPU stall
1068 * warning delay.
6193c76a 1069 */
4a81e832
PM
1070 rcrmp = &per_cpu(rcu_sched_qs_mask, rdp->cpu);
1071 if (ULONG_CMP_GE(jiffies,
1072 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
cb1e78cf 1073 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
4a81e832
PM
1074 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
1075 ACCESS_ONCE(rdp->cond_resched_completed) =
1076 ACCESS_ONCE(rdp->mynode->completed);
1077 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
1078 ACCESS_ONCE(*rcrmp) =
1079 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
1080 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
1081 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
1082 } else if (ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
1083 /* Time to beat on that CPU again! */
1084 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
1085 rdp->rsp->jiffies_resched += 5; /* Re-enable beating. */
1086 }
6193c76a
PM
1087 }
1088
a82dcc76 1089 return 0;
64db4cff
PM
1090}
1091
64db4cff
PM
1092static void record_gp_stall_check_time(struct rcu_state *rsp)
1093{
cb1e78cf 1094 unsigned long j = jiffies;
6193c76a 1095 unsigned long j1;
26cdfedf
PM
1096
1097 rsp->gp_start = j;
1098 smp_wmb(); /* Record start time before stall time. */
6193c76a 1099 j1 = rcu_jiffies_till_stall_check();
4fc5b755 1100 ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
6193c76a 1101 rsp->jiffies_resched = j + j1 / 2;
fc908ed3 1102 rsp->n_force_qs_gpstart = ACCESS_ONCE(rsp->n_force_qs);
64db4cff
PM
1103}
1104
fb81a44b
PM
1105/*
1106 * Complain about starvation of grace-period kthread.
1107 */
1108static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
1109{
1110 unsigned long gpa;
1111 unsigned long j;
1112
1113 j = jiffies;
1114 gpa = ACCESS_ONCE(rsp->gp_activity);
1115 if (j - gpa > 2 * HZ)
1116 pr_err("%s kthread starved for %ld jiffies!\n",
1117 rsp->name, j - gpa);
64db4cff
PM
1118}
1119
b637a328 1120/*
bc1dce51 1121 * Dump stacks of all tasks running on stalled CPUs.
b637a328
PM
1122 */
1123static void rcu_dump_cpu_stacks(struct rcu_state *rsp)
1124{
1125 int cpu;
1126 unsigned long flags;
1127 struct rcu_node *rnp;
1128
1129 rcu_for_each_leaf_node(rsp, rnp) {
1130 raw_spin_lock_irqsave(&rnp->lock, flags);
1131 if (rnp->qsmask != 0) {
1132 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
1133 if (rnp->qsmask & (1UL << cpu))
1134 dump_cpu_task(rnp->grplo + cpu);
1135 }
1136 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1137 }
1138}
1139
6ccd2ecd 1140static void print_other_cpu_stall(struct rcu_state *rsp, unsigned long gpnum)
64db4cff
PM
1141{
1142 int cpu;
1143 long delta;
1144 unsigned long flags;
6ccd2ecd
PM
1145 unsigned long gpa;
1146 unsigned long j;
285fe294 1147 int ndetected = 0;
64db4cff 1148 struct rcu_node *rnp = rcu_get_root(rsp);
53bb857c 1149 long totqlen = 0;
64db4cff
PM
1150
1151 /* Only let one CPU complain about others per time interval. */
1152
1304afb2 1153 raw_spin_lock_irqsave(&rnp->lock, flags);
4fc5b755 1154 delta = jiffies - ACCESS_ONCE(rsp->jiffies_stall);
fc2219d4 1155 if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
1304afb2 1156 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff
PM
1157 return;
1158 }
4fc5b755 1159 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
1304afb2 1160 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff 1161
8cdd32a9
PM
1162 /*
1163 * OK, time to rat on our buddy...
1164 * See Documentation/RCU/stallwarn.txt for info on how to debug
1165 * RCU CPU stall warnings.
1166 */
d7f3e207 1167 pr_err("INFO: %s detected stalls on CPUs/tasks:",
4300aa64 1168 rsp->name);
a858af28 1169 print_cpu_stall_info_begin();
a0b6c9a7 1170 rcu_for_each_leaf_node(rsp, rnp) {
3acd9eb3 1171 raw_spin_lock_irqsave(&rnp->lock, flags);
9bc8b558 1172 ndetected += rcu_print_task_stall(rnp);
c8020a67
PM
1173 if (rnp->qsmask != 0) {
1174 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
1175 if (rnp->qsmask & (1UL << cpu)) {
1176 print_cpu_stall_info(rsp,
1177 rnp->grplo + cpu);
1178 ndetected++;
1179 }
1180 }
3acd9eb3 1181 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff 1182 }
a858af28 1183
a858af28 1184 print_cpu_stall_info_end();
53bb857c
PM
1185 for_each_possible_cpu(cpu)
1186 totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
83ebe63e 1187 pr_cont("(detected by %d, t=%ld jiffies, g=%ld, c=%ld, q=%lu)\n",
eee05882 1188 smp_processor_id(), (long)(jiffies - rsp->gp_start),
83ebe63e 1189 (long)rsp->gpnum, (long)rsp->completed, totqlen);
6ccd2ecd 1190 if (ndetected) {
b637a328 1191 rcu_dump_cpu_stacks(rsp);
6ccd2ecd
PM
1192 } else {
1193 if (ACCESS_ONCE(rsp->gpnum) != gpnum ||
1194 ACCESS_ONCE(rsp->completed) == gpnum) {
1195 pr_err("INFO: Stall ended before state dump start\n");
1196 } else {
1197 j = jiffies;
1198 gpa = ACCESS_ONCE(rsp->gp_activity);
237a0f21 1199 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
6ccd2ecd 1200 rsp->name, j - gpa, j, gpa,
237a0f21
PM
1201 jiffies_till_next_fqs,
1202 rcu_get_root(rsp)->qsmask);
6ccd2ecd
PM
1203 /* In this case, the current CPU might be at fault. */
1204 sched_show_task(current);
1205 }
1206 }
c1dc0b9c 1207
4cdfc175 1208 /* Complain about tasks blocking the grace period. */
1ed509a2
PM
1209 rcu_print_detail_task_stall(rsp);
1210
fb81a44b
PM
1211 rcu_check_gp_kthread_starvation(rsp);
1212
4cdfc175 1213 force_quiescent_state(rsp); /* Kick them all. */
64db4cff
PM
1214}
1215
1216static void print_cpu_stall(struct rcu_state *rsp)
1217{
53bb857c 1218 int cpu;
64db4cff
PM
1219 unsigned long flags;
1220 struct rcu_node *rnp = rcu_get_root(rsp);
53bb857c 1221 long totqlen = 0;
64db4cff 1222
8cdd32a9
PM
1223 /*
1224 * OK, time to rat on ourselves...
1225 * See Documentation/RCU/stallwarn.txt for info on how to debug
1226 * RCU CPU stall warnings.
1227 */
d7f3e207 1228 pr_err("INFO: %s self-detected stall on CPU", rsp->name);
a858af28
PM
1229 print_cpu_stall_info_begin();
1230 print_cpu_stall_info(rsp, smp_processor_id());
1231 print_cpu_stall_info_end();
53bb857c
PM
1232 for_each_possible_cpu(cpu)
1233 totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
83ebe63e
PM
1234 pr_cont(" (t=%lu jiffies g=%ld c=%ld q=%lu)\n",
1235 jiffies - rsp->gp_start,
1236 (long)rsp->gpnum, (long)rsp->completed, totqlen);
fb81a44b
PM
1237
1238 rcu_check_gp_kthread_starvation(rsp);
1239
bc1dce51 1240 rcu_dump_cpu_stacks(rsp);
c1dc0b9c 1241
1304afb2 1242 raw_spin_lock_irqsave(&rnp->lock, flags);
4fc5b755
IM
1243 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
1244 ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
6bfc09e2 1245 3 * rcu_jiffies_till_stall_check() + 3;
1304afb2 1246 raw_spin_unlock_irqrestore(&rnp->lock, flags);
c1dc0b9c 1247
b021fe3e
PZ
1248 /*
1249 * Attempt to revive the RCU machinery by forcing a context switch.
1250 *
1251 * A context switch would normally allow the RCU state machine to make
1252 * progress and it could be we're stuck in kernel space without context
1253 * switches for an entirely unreasonable amount of time.
1254 */
1255 resched_cpu(smp_processor_id());
64db4cff
PM
1256}
1257
1258static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
1259{
26cdfedf
PM
1260 unsigned long completed;
1261 unsigned long gpnum;
1262 unsigned long gps;
bad6e139
PM
1263 unsigned long j;
1264 unsigned long js;
64db4cff
PM
1265 struct rcu_node *rnp;
1266
26cdfedf 1267 if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp))
c68de209 1268 return;
cb1e78cf 1269 j = jiffies;
26cdfedf
PM
1270
1271 /*
1272 * Lots of memory barriers to reject false positives.
1273 *
1274 * The idea is to pick up rsp->gpnum, then rsp->jiffies_stall,
1275 * then rsp->gp_start, and finally rsp->completed. These values
1276 * are updated in the opposite order with memory barriers (or
1277 * equivalent) during grace-period initialization and cleanup.
1278 * Now, a false positive can occur if we get an new value of
1279 * rsp->gp_start and a old value of rsp->jiffies_stall. But given
1280 * the memory barriers, the only way that this can happen is if one
1281 * grace period ends and another starts between these two fetches.
1282 * Detect this by comparing rsp->completed with the previous fetch
1283 * from rsp->gpnum.
1284 *
1285 * Given this check, comparisons of jiffies, rsp->jiffies_stall,
1286 * and rsp->gp_start suffice to forestall false positives.
1287 */
1288 gpnum = ACCESS_ONCE(rsp->gpnum);
1289 smp_rmb(); /* Pick up ->gpnum first... */
bad6e139 1290 js = ACCESS_ONCE(rsp->jiffies_stall);
26cdfedf
PM
1291 smp_rmb(); /* ...then ->jiffies_stall before the rest... */
1292 gps = ACCESS_ONCE(rsp->gp_start);
1293 smp_rmb(); /* ...and finally ->gp_start before ->completed. */
1294 completed = ACCESS_ONCE(rsp->completed);
1295 if (ULONG_CMP_GE(completed, gpnum) ||
1296 ULONG_CMP_LT(j, js) ||
1297 ULONG_CMP_GE(gps, js))
1298 return; /* No stall or GP completed since entering function. */
64db4cff 1299 rnp = rdp->mynode;
c96ea7cf 1300 if (rcu_gp_in_progress(rsp) &&
26cdfedf 1301 (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask)) {
64db4cff
PM
1302
1303 /* We haven't checked in, so go dump stack. */
1304 print_cpu_stall(rsp);
1305
bad6e139
PM
1306 } else if (rcu_gp_in_progress(rsp) &&
1307 ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) {
64db4cff 1308
bad6e139 1309 /* They had a few time units to dump stack, so complain. */
6ccd2ecd 1310 print_other_cpu_stall(rsp, gpnum);
64db4cff
PM
1311 }
1312}
1313
53d84e00
PM
1314/**
1315 * rcu_cpu_stall_reset - prevent further stall warnings in current grace period
1316 *
1317 * Set the stall-warning timeout way off into the future, thus preventing
1318 * any RCU CPU stall-warning messages from appearing in the current set of
1319 * RCU grace periods.
1320 *
1321 * The caller must disable hard irqs.
1322 */
1323void rcu_cpu_stall_reset(void)
1324{
6ce75a23
PM
1325 struct rcu_state *rsp;
1326
1327 for_each_rcu_flavor(rsp)
4fc5b755 1328 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
53d84e00
PM
1329}
1330
3f5d3ea6
PM
1331/*
1332 * Initialize the specified rcu_data structure's callback list to empty.
1333 */
1334static void init_callback_list(struct rcu_data *rdp)
1335{
1336 int i;
1337
34ed6246
PM
1338 if (init_nocb_callback_list(rdp))
1339 return;
3f5d3ea6
PM
1340 rdp->nxtlist = NULL;
1341 for (i = 0; i < RCU_NEXT_SIZE; i++)
1342 rdp->nxttail[i] = &rdp->nxtlist;
1343}
1344
dc35c893
PM
1345/*
1346 * Determine the value that ->completed will have at the end of the
1347 * next subsequent grace period. This is used to tag callbacks so that
1348 * a CPU can invoke callbacks in a timely fashion even if that CPU has
1349 * been dyntick-idle for an extended period with callbacks under the
1350 * influence of RCU_FAST_NO_HZ.
1351 *
1352 * The caller must hold rnp->lock with interrupts disabled.
1353 */
1354static unsigned long rcu_cbs_completed(struct rcu_state *rsp,
1355 struct rcu_node *rnp)
1356{
1357 /*
1358 * If RCU is idle, we just wait for the next grace period.
1359 * But we can only be sure that RCU is idle if we are looking
1360 * at the root rcu_node structure -- otherwise, a new grace
1361 * period might have started, but just not yet gotten around
1362 * to initializing the current non-root rcu_node structure.
1363 */
1364 if (rcu_get_root(rsp) == rnp && rnp->gpnum == rnp->completed)
1365 return rnp->completed + 1;
1366
1367 /*
1368 * Otherwise, wait for a possible partial grace period and
1369 * then the subsequent full grace period.
1370 */
1371 return rnp->completed + 2;
1372}
1373
0446be48
PM
1374/*
1375 * Trace-event helper function for rcu_start_future_gp() and
1376 * rcu_nocb_wait_gp().
1377 */
1378static void trace_rcu_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
e66c33d5 1379 unsigned long c, const char *s)
0446be48
PM
1380{
1381 trace_rcu_future_grace_period(rdp->rsp->name, rnp->gpnum,
1382 rnp->completed, c, rnp->level,
1383 rnp->grplo, rnp->grphi, s);
1384}
1385
1386/*
1387 * Start some future grace period, as needed to handle newly arrived
1388 * callbacks. The required future grace periods are recorded in each
48a7639c
PM
1389 * rcu_node structure's ->need_future_gp field. Returns true if there
1390 * is reason to awaken the grace-period kthread.
0446be48
PM
1391 *
1392 * The caller must hold the specified rcu_node structure's ->lock.
1393 */
48a7639c
PM
1394static bool __maybe_unused
1395rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1396 unsigned long *c_out)
0446be48
PM
1397{
1398 unsigned long c;
1399 int i;
48a7639c 1400 bool ret = false;
0446be48
PM
1401 struct rcu_node *rnp_root = rcu_get_root(rdp->rsp);
1402
1403 /*
1404 * Pick up grace-period number for new callbacks. If this
1405 * grace period is already marked as needed, return to the caller.
1406 */
1407 c = rcu_cbs_completed(rdp->rsp, rnp);
f7f7bac9 1408 trace_rcu_future_gp(rnp, rdp, c, TPS("Startleaf"));
0446be48 1409 if (rnp->need_future_gp[c & 0x1]) {
f7f7bac9 1410 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartleaf"));
48a7639c 1411 goto out;
0446be48
PM
1412 }
1413
1414 /*
1415 * If either this rcu_node structure or the root rcu_node structure
1416 * believe that a grace period is in progress, then we must wait
1417 * for the one following, which is in "c". Because our request
1418 * will be noticed at the end of the current grace period, we don't
48bd8e9b
PK
1419 * need to explicitly start one. We only do the lockless check
1420 * of rnp_root's fields if the current rcu_node structure thinks
1421 * there is no grace period in flight, and because we hold rnp->lock,
1422 * the only possible change is when rnp_root's two fields are
1423 * equal, in which case rnp_root->gpnum might be concurrently
1424 * incremented. But that is OK, as it will just result in our
1425 * doing some extra useless work.
0446be48
PM
1426 */
1427 if (rnp->gpnum != rnp->completed ||
48bd8e9b 1428 ACCESS_ONCE(rnp_root->gpnum) != ACCESS_ONCE(rnp_root->completed)) {
0446be48 1429 rnp->need_future_gp[c & 0x1]++;
f7f7bac9 1430 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf"));
48a7639c 1431 goto out;
0446be48
PM
1432 }
1433
1434 /*
1435 * There might be no grace period in progress. If we don't already
1436 * hold it, acquire the root rcu_node structure's lock in order to
1437 * start one (if needed).
1438 */
6303b9c8 1439 if (rnp != rnp_root) {
0446be48 1440 raw_spin_lock(&rnp_root->lock);
6303b9c8
PM
1441 smp_mb__after_unlock_lock();
1442 }
0446be48
PM
1443
1444 /*
1445 * Get a new grace-period number. If there really is no grace
1446 * period in progress, it will be smaller than the one we obtained
1447 * earlier. Adjust callbacks as needed. Note that even no-CBs
1448 * CPUs have a ->nxtcompleted[] array, so no no-CBs checks needed.
1449 */
1450 c = rcu_cbs_completed(rdp->rsp, rnp_root);
1451 for (i = RCU_DONE_TAIL; i < RCU_NEXT_TAIL; i++)
1452 if (ULONG_CMP_LT(c, rdp->nxtcompleted[i]))
1453 rdp->nxtcompleted[i] = c;
1454
1455 /*
1456 * If the needed for the required grace period is already
1457 * recorded, trace and leave.
1458 */
1459 if (rnp_root->need_future_gp[c & 0x1]) {
f7f7bac9 1460 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartedroot"));
0446be48
PM
1461 goto unlock_out;
1462 }
1463
1464 /* Record the need for the future grace period. */
1465 rnp_root->need_future_gp[c & 0x1]++;
1466
1467 /* If a grace period is not already in progress, start one. */
1468 if (rnp_root->gpnum != rnp_root->completed) {
f7f7bac9 1469 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleafroot"));
0446be48 1470 } else {
f7f7bac9 1471 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedroot"));
48a7639c 1472 ret = rcu_start_gp_advanced(rdp->rsp, rnp_root, rdp);
0446be48
PM
1473 }
1474unlock_out:
1475 if (rnp != rnp_root)
1476 raw_spin_unlock(&rnp_root->lock);
48a7639c
PM
1477out:
1478 if (c_out != NULL)
1479 *c_out = c;
1480 return ret;
0446be48
PM
1481}
1482
1483/*
1484 * Clean up any old requests for the just-ended grace period. Also return
1485 * whether any additional grace periods have been requested. Also invoke
1486 * rcu_nocb_gp_cleanup() in order to wake up any no-callbacks kthreads
1487 * waiting for this grace period to complete.
1488 */
1489static int rcu_future_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
1490{
1491 int c = rnp->completed;
1492 int needmore;
1493 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
1494
1495 rcu_nocb_gp_cleanup(rsp, rnp);
1496 rnp->need_future_gp[c & 0x1] = 0;
1497 needmore = rnp->need_future_gp[(c + 1) & 0x1];
f7f7bac9
SRRH
1498 trace_rcu_future_gp(rnp, rdp, c,
1499 needmore ? TPS("CleanupMore") : TPS("Cleanup"));
0446be48
PM
1500 return needmore;
1501}
1502
48a7639c
PM
1503/*
1504 * Awaken the grace-period kthread for the specified flavor of RCU.
1505 * Don't do a self-awaken, and don't bother awakening when there is
1506 * nothing for the grace-period kthread to do (as in several CPUs
1507 * raced to awaken, and we lost), and finally don't try to awaken
1508 * a kthread that has not yet been created.
1509 */
1510static void rcu_gp_kthread_wake(struct rcu_state *rsp)
1511{
1512 if (current == rsp->gp_kthread ||
1513 !ACCESS_ONCE(rsp->gp_flags) ||
1514 !rsp->gp_kthread)
1515 return;
1516 wake_up(&rsp->gp_wq);
1517}
1518
dc35c893
PM
1519/*
1520 * If there is room, assign a ->completed number to any callbacks on
1521 * this CPU that have not already been assigned. Also accelerate any
1522 * callbacks that were previously assigned a ->completed number that has
1523 * since proven to be too conservative, which can happen if callbacks get
1524 * assigned a ->completed number while RCU is idle, but with reference to
1525 * a non-root rcu_node structure. This function is idempotent, so it does
48a7639c
PM
1526 * not hurt to call it repeatedly. Returns an flag saying that we should
1527 * awaken the RCU grace-period kthread.
dc35c893
PM
1528 *
1529 * The caller must hold rnp->lock with interrupts disabled.
1530 */
48a7639c 1531static bool rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
dc35c893
PM
1532 struct rcu_data *rdp)
1533{
1534 unsigned long c;
1535 int i;
48a7639c 1536 bool ret;
dc35c893
PM
1537
1538 /* If the CPU has no callbacks, nothing to do. */
1539 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
48a7639c 1540 return false;
dc35c893
PM
1541
1542 /*
1543 * Starting from the sublist containing the callbacks most
1544 * recently assigned a ->completed number and working down, find the
1545 * first sublist that is not assignable to an upcoming grace period.
1546 * Such a sublist has something in it (first two tests) and has
1547 * a ->completed number assigned that will complete sooner than
1548 * the ->completed number for newly arrived callbacks (last test).
1549 *
1550 * The key point is that any later sublist can be assigned the
1551 * same ->completed number as the newly arrived callbacks, which
1552 * means that the callbacks in any of these later sublist can be
1553 * grouped into a single sublist, whether or not they have already
1554 * been assigned a ->completed number.
1555 */
1556 c = rcu_cbs_completed(rsp, rnp);
1557 for (i = RCU_NEXT_TAIL - 1; i > RCU_DONE_TAIL; i--)
1558 if (rdp->nxttail[i] != rdp->nxttail[i - 1] &&
1559 !ULONG_CMP_GE(rdp->nxtcompleted[i], c))
1560 break;
1561
1562 /*
1563 * If there are no sublist for unassigned callbacks, leave.
1564 * At the same time, advance "i" one sublist, so that "i" will
1565 * index into the sublist where all the remaining callbacks should
1566 * be grouped into.
1567 */
1568 if (++i >= RCU_NEXT_TAIL)
48a7639c 1569 return false;
dc35c893
PM
1570
1571 /*
1572 * Assign all subsequent callbacks' ->completed number to the next
1573 * full grace period and group them all in the sublist initially
1574 * indexed by "i".
1575 */
1576 for (; i <= RCU_NEXT_TAIL; i++) {
1577 rdp->nxttail[i] = rdp->nxttail[RCU_NEXT_TAIL];
1578 rdp->nxtcompleted[i] = c;
1579 }
910ee45d 1580 /* Record any needed additional grace periods. */
48a7639c 1581 ret = rcu_start_future_gp(rnp, rdp, NULL);
6d4b418c
PM
1582
1583 /* Trace depending on how much we were able to accelerate. */
1584 if (!*rdp->nxttail[RCU_WAIT_TAIL])
f7f7bac9 1585 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccWaitCB"));
6d4b418c 1586 else
f7f7bac9 1587 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccReadyCB"));
48a7639c 1588 return ret;
dc35c893
PM
1589}
1590
1591/*
1592 * Move any callbacks whose grace period has completed to the
1593 * RCU_DONE_TAIL sublist, then compact the remaining sublists and
1594 * assign ->completed numbers to any callbacks in the RCU_NEXT_TAIL
1595 * sublist. This function is idempotent, so it does not hurt to
1596 * invoke it repeatedly. As long as it is not invoked -too- often...
48a7639c 1597 * Returns true if the RCU grace-period kthread needs to be awakened.
dc35c893
PM
1598 *
1599 * The caller must hold rnp->lock with interrupts disabled.
1600 */
48a7639c 1601static bool rcu_advance_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
dc35c893
PM
1602 struct rcu_data *rdp)
1603{
1604 int i, j;
1605
1606 /* If the CPU has no callbacks, nothing to do. */
1607 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
48a7639c 1608 return false;
dc35c893
PM
1609
1610 /*
1611 * Find all callbacks whose ->completed numbers indicate that they
1612 * are ready to invoke, and put them into the RCU_DONE_TAIL sublist.
1613 */
1614 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++) {
1615 if (ULONG_CMP_LT(rnp->completed, rdp->nxtcompleted[i]))
1616 break;
1617 rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[i];
1618 }
1619 /* Clean up any sublist tail pointers that were misordered above. */
1620 for (j = RCU_WAIT_TAIL; j < i; j++)
1621 rdp->nxttail[j] = rdp->nxttail[RCU_DONE_TAIL];
1622
1623 /* Copy down callbacks to fill in empty sublists. */
1624 for (j = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++, j++) {
1625 if (rdp->nxttail[j] == rdp->nxttail[RCU_NEXT_TAIL])
1626 break;
1627 rdp->nxttail[j] = rdp->nxttail[i];
1628 rdp->nxtcompleted[j] = rdp->nxtcompleted[i];
1629 }
1630
1631 /* Classify any remaining callbacks. */
48a7639c 1632 return rcu_accelerate_cbs(rsp, rnp, rdp);
dc35c893
PM
1633}
1634
d09b62df 1635/*
ba9fbe95
PM
1636 * Update CPU-local rcu_data state to record the beginnings and ends of
1637 * grace periods. The caller must hold the ->lock of the leaf rcu_node
1638 * structure corresponding to the current CPU, and must have irqs disabled.
48a7639c 1639 * Returns true if the grace-period kthread needs to be awakened.
d09b62df 1640 */
48a7639c
PM
1641static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,
1642 struct rcu_data *rdp)
d09b62df 1643{
48a7639c
PM
1644 bool ret;
1645
ba9fbe95 1646 /* Handle the ends of any preceding grace periods first. */
e3663b10
PM
1647 if (rdp->completed == rnp->completed &&
1648 !unlikely(ACCESS_ONCE(rdp->gpwrap))) {
d09b62df 1649
ba9fbe95 1650 /* No grace period end, so just accelerate recent callbacks. */
48a7639c 1651 ret = rcu_accelerate_cbs(rsp, rnp, rdp);
d09b62df 1652
dc35c893
PM
1653 } else {
1654
1655 /* Advance callbacks. */
48a7639c 1656 ret = rcu_advance_cbs(rsp, rnp, rdp);
d09b62df
PM
1657
1658 /* Remember that we saw this grace-period completion. */
1659 rdp->completed = rnp->completed;
f7f7bac9 1660 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuend"));
d09b62df 1661 }
398ebe60 1662
e3663b10 1663 if (rdp->gpnum != rnp->gpnum || unlikely(ACCESS_ONCE(rdp->gpwrap))) {
6eaef633
PM
1664 /*
1665 * If the current grace period is waiting for this CPU,
1666 * set up to detect a quiescent state, otherwise don't
1667 * go looking for one.
1668 */
1669 rdp->gpnum = rnp->gpnum;
f7f7bac9 1670 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpustart"));
6eaef633 1671 rdp->passed_quiesce = 0;
5cd37193 1672 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
6eaef633
PM
1673 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
1674 zero_cpu_stall_ticks(rdp);
e3663b10 1675 ACCESS_ONCE(rdp->gpwrap) = false;
6eaef633 1676 }
48a7639c 1677 return ret;
6eaef633
PM
1678}
1679
d34ea322 1680static void note_gp_changes(struct rcu_state *rsp, struct rcu_data *rdp)
6eaef633
PM
1681{
1682 unsigned long flags;
48a7639c 1683 bool needwake;
6eaef633
PM
1684 struct rcu_node *rnp;
1685
1686 local_irq_save(flags);
1687 rnp = rdp->mynode;
d34ea322 1688 if ((rdp->gpnum == ACCESS_ONCE(rnp->gpnum) &&
e3663b10
PM
1689 rdp->completed == ACCESS_ONCE(rnp->completed) &&
1690 !unlikely(ACCESS_ONCE(rdp->gpwrap))) || /* w/out lock. */
6eaef633
PM
1691 !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
1692 local_irq_restore(flags);
1693 return;
1694 }
6303b9c8 1695 smp_mb__after_unlock_lock();
48a7639c 1696 needwake = __note_gp_changes(rsp, rnp, rdp);
6eaef633 1697 raw_spin_unlock_irqrestore(&rnp->lock, flags);
48a7639c
PM
1698 if (needwake)
1699 rcu_gp_kthread_wake(rsp);
6eaef633
PM
1700}
1701
b3dbec76 1702/*
f7be8209 1703 * Initialize a new grace period. Return 0 if no grace period required.
b3dbec76 1704 */
7fdefc10 1705static int rcu_gp_init(struct rcu_state *rsp)
b3dbec76
PM
1706{
1707 struct rcu_data *rdp;
7fdefc10 1708 struct rcu_node *rnp = rcu_get_root(rsp);
b3dbec76 1709
6ccd2ecd 1710 ACCESS_ONCE(rsp->gp_activity) = jiffies;
eb75767b 1711 rcu_bind_gp_kthread();
7fdefc10 1712 raw_spin_lock_irq(&rnp->lock);
6303b9c8 1713 smp_mb__after_unlock_lock();
91dc9542 1714 if (!ACCESS_ONCE(rsp->gp_flags)) {
f7be8209
PM
1715 /* Spurious wakeup, tell caller to go back to sleep. */
1716 raw_spin_unlock_irq(&rnp->lock);
1717 return 0;
1718 }
91dc9542 1719 ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
b3dbec76 1720
f7be8209
PM
1721 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
1722 /*
1723 * Grace period already in progress, don't start another.
1724 * Not supposed to be able to happen.
1725 */
7fdefc10
PM
1726 raw_spin_unlock_irq(&rnp->lock);
1727 return 0;
1728 }
1729
7fdefc10 1730 /* Advance to a new grace period and initialize state. */
26cdfedf 1731 record_gp_stall_check_time(rsp);
765a3f4f
PM
1732 /* Record GP times before starting GP, hence smp_store_release(). */
1733 smp_store_release(&rsp->gpnum, rsp->gpnum + 1);
f7f7bac9 1734 trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start"));
7fdefc10
PM
1735 raw_spin_unlock_irq(&rnp->lock);
1736
1737 /* Exclude any concurrent CPU-hotplug operations. */
a4fbe35a 1738 mutex_lock(&rsp->onoff_mutex);
765a3f4f 1739 smp_mb__after_unlock_lock(); /* ->gpnum increment before GP! */
7fdefc10
PM
1740
1741 /*
1742 * Set the quiescent-state-needed bits in all the rcu_node
1743 * structures for all currently online CPUs in breadth-first order,
1744 * starting from the root rcu_node structure, relying on the layout
1745 * of the tree within the rsp->node[] array. Note that other CPUs
1746 * will access only the leaves of the hierarchy, thus seeing that no
1747 * grace period is in progress, at least until the corresponding
1748 * leaf node has been initialized. In addition, we have excluded
1749 * CPU-hotplug operations.
1750 *
1751 * The grace period cannot complete until the initialization
1752 * process finishes, because this kthread handles both.
1753 */
1754 rcu_for_each_node_breadth_first(rsp, rnp) {
b3dbec76 1755 raw_spin_lock_irq(&rnp->lock);
6303b9c8 1756 smp_mb__after_unlock_lock();
b3dbec76 1757 rdp = this_cpu_ptr(rsp->rda);
7fdefc10
PM
1758 rcu_preempt_check_blocked_tasks(rnp);
1759 rnp->qsmask = rnp->qsmaskinit;
0446be48 1760 ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
25d30cf4 1761 WARN_ON_ONCE(rnp->completed != rsp->completed);
0446be48 1762 ACCESS_ONCE(rnp->completed) = rsp->completed;
7fdefc10 1763 if (rnp == rdp->mynode)
48a7639c 1764 (void)__note_gp_changes(rsp, rnp, rdp);
7fdefc10
PM
1765 rcu_preempt_boost_start_gp(rnp);
1766 trace_rcu_grace_period_init(rsp->name, rnp->gpnum,
1767 rnp->level, rnp->grplo,
1768 rnp->grphi, rnp->qsmask);
1769 raw_spin_unlock_irq(&rnp->lock);
bde6c3aa 1770 cond_resched_rcu_qs();
6ccd2ecd 1771 ACCESS_ONCE(rsp->gp_activity) = jiffies;
7fdefc10 1772 }
b3dbec76 1773
a4fbe35a 1774 mutex_unlock(&rsp->onoff_mutex);
7fdefc10
PM
1775 return 1;
1776}
b3dbec76 1777
4cdfc175
PM
1778/*
1779 * Do one round of quiescent-state forcing.
1780 */
01896f7e 1781static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
4cdfc175
PM
1782{
1783 int fqs_state = fqs_state_in;
217af2a2
PM
1784 bool isidle = false;
1785 unsigned long maxj;
4cdfc175
PM
1786 struct rcu_node *rnp = rcu_get_root(rsp);
1787
6ccd2ecd 1788 ACCESS_ONCE(rsp->gp_activity) = jiffies;
4cdfc175
PM
1789 rsp->n_force_qs++;
1790 if (fqs_state == RCU_SAVE_DYNTICK) {
1791 /* Collect dyntick-idle snapshots. */
0edd1b17 1792 if (is_sysidle_rcu_state(rsp)) {
e02b2edf 1793 isidle = true;
0edd1b17
PM
1794 maxj = jiffies - ULONG_MAX / 4;
1795 }
217af2a2
PM
1796 force_qs_rnp(rsp, dyntick_save_progress_counter,
1797 &isidle, &maxj);
0edd1b17 1798 rcu_sysidle_report_gp(rsp, isidle, maxj);
4cdfc175
PM
1799 fqs_state = RCU_FORCE_QS;
1800 } else {
1801 /* Handle dyntick-idle and offline CPUs. */
e02b2edf 1802 isidle = false;
217af2a2 1803 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj);
4cdfc175
PM
1804 }
1805 /* Clear flag to prevent immediate re-entry. */
1806 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1807 raw_spin_lock_irq(&rnp->lock);
6303b9c8 1808 smp_mb__after_unlock_lock();
4de376a1
PK
1809 ACCESS_ONCE(rsp->gp_flags) =
1810 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
4cdfc175
PM
1811 raw_spin_unlock_irq(&rnp->lock);
1812 }
1813 return fqs_state;
1814}
1815
7fdefc10
PM
1816/*
1817 * Clean up after the old grace period.
1818 */
4cdfc175 1819static void rcu_gp_cleanup(struct rcu_state *rsp)
7fdefc10
PM
1820{
1821 unsigned long gp_duration;
48a7639c 1822 bool needgp = false;
dae6e64d 1823 int nocb = 0;
7fdefc10
PM
1824 struct rcu_data *rdp;
1825 struct rcu_node *rnp = rcu_get_root(rsp);
b3dbec76 1826
6ccd2ecd 1827 ACCESS_ONCE(rsp->gp_activity) = jiffies;
7fdefc10 1828 raw_spin_lock_irq(&rnp->lock);
6303b9c8 1829 smp_mb__after_unlock_lock();
7fdefc10
PM
1830 gp_duration = jiffies - rsp->gp_start;
1831 if (gp_duration > rsp->gp_max)
1832 rsp->gp_max = gp_duration;
b3dbec76 1833
7fdefc10
PM
1834 /*
1835 * We know the grace period is complete, but to everyone else
1836 * it appears to still be ongoing. But it is also the case
1837 * that to everyone else it looks like there is nothing that
1838 * they can do to advance the grace period. It is therefore
1839 * safe for us to drop the lock in order to mark the grace
1840 * period as completed in all of the rcu_node structures.
7fdefc10 1841 */
5d4b8659 1842 raw_spin_unlock_irq(&rnp->lock);
b3dbec76 1843
5d4b8659
PM
1844 /*
1845 * Propagate new ->completed value to rcu_node structures so
1846 * that other CPUs don't have to wait until the start of the next
1847 * grace period to process their callbacks. This also avoids
1848 * some nasty RCU grace-period initialization races by forcing
1849 * the end of the current grace period to be completely recorded in
1850 * all of the rcu_node structures before the beginning of the next
1851 * grace period is recorded in any of the rcu_node structures.
1852 */
1853 rcu_for_each_node_breadth_first(rsp, rnp) {
755609a9 1854 raw_spin_lock_irq(&rnp->lock);
6303b9c8 1855 smp_mb__after_unlock_lock();
0446be48 1856 ACCESS_ONCE(rnp->completed) = rsp->gpnum;
b11cc576
PM
1857 rdp = this_cpu_ptr(rsp->rda);
1858 if (rnp == rdp->mynode)
48a7639c 1859 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
78e4bc34 1860 /* smp_mb() provided by prior unlock-lock pair. */
0446be48 1861 nocb += rcu_future_gp_cleanup(rsp, rnp);
5d4b8659 1862 raw_spin_unlock_irq(&rnp->lock);
bde6c3aa 1863 cond_resched_rcu_qs();
6ccd2ecd 1864 ACCESS_ONCE(rsp->gp_activity) = jiffies;
7fdefc10 1865 }
5d4b8659
PM
1866 rnp = rcu_get_root(rsp);
1867 raw_spin_lock_irq(&rnp->lock);
765a3f4f 1868 smp_mb__after_unlock_lock(); /* Order GP before ->completed update. */
dae6e64d 1869 rcu_nocb_gp_set(rnp, nocb);
7fdefc10 1870
765a3f4f
PM
1871 /* Declare grace period done. */
1872 ACCESS_ONCE(rsp->completed) = rsp->gpnum;
f7f7bac9 1873 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
7fdefc10 1874 rsp->fqs_state = RCU_GP_IDLE;
5d4b8659 1875 rdp = this_cpu_ptr(rsp->rda);
48a7639c
PM
1876 /* Advance CBs to reduce false positives below. */
1877 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
1878 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91dc9542 1879 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
bb311ecc
PM
1880 trace_rcu_grace_period(rsp->name,
1881 ACCESS_ONCE(rsp->gpnum),
1882 TPS("newreq"));
1883 }
7fdefc10 1884 raw_spin_unlock_irq(&rnp->lock);
7fdefc10
PM
1885}
1886
1887/*
1888 * Body of kthread that handles grace periods.
1889 */
1890static int __noreturn rcu_gp_kthread(void *arg)
1891{
4cdfc175 1892 int fqs_state;
88d6df61 1893 int gf;
d40011f6 1894 unsigned long j;
4cdfc175 1895 int ret;
7fdefc10
PM
1896 struct rcu_state *rsp = arg;
1897 struct rcu_node *rnp = rcu_get_root(rsp);
1898
1899 for (;;) {
1900
1901 /* Handle grace-period start. */
1902 for (;;) {
63c4db78
PM
1903 trace_rcu_grace_period(rsp->name,
1904 ACCESS_ONCE(rsp->gpnum),
1905 TPS("reqwait"));
afea227f 1906 rsp->gp_state = RCU_GP_WAIT_GPS;
4cdfc175 1907 wait_event_interruptible(rsp->gp_wq,
591c6d17 1908 ACCESS_ONCE(rsp->gp_flags) &
4cdfc175 1909 RCU_GP_FLAG_INIT);
78e4bc34 1910 /* Locking provides needed memory barrier. */
f7be8209 1911 if (rcu_gp_init(rsp))
7fdefc10 1912 break;
bde6c3aa 1913 cond_resched_rcu_qs();
6ccd2ecd 1914 ACCESS_ONCE(rsp->gp_activity) = jiffies;
73a860cd 1915 WARN_ON(signal_pending(current));
63c4db78
PM
1916 trace_rcu_grace_period(rsp->name,
1917 ACCESS_ONCE(rsp->gpnum),
1918 TPS("reqwaitsig"));
7fdefc10 1919 }
cabc49c1 1920
4cdfc175
PM
1921 /* Handle quiescent-state forcing. */
1922 fqs_state = RCU_SAVE_DYNTICK;
d40011f6
PM
1923 j = jiffies_till_first_fqs;
1924 if (j > HZ) {
1925 j = HZ;
1926 jiffies_till_first_fqs = HZ;
1927 }
88d6df61 1928 ret = 0;
cabc49c1 1929 for (;;) {
88d6df61
PM
1930 if (!ret)
1931 rsp->jiffies_force_qs = jiffies + j;
63c4db78
PM
1932 trace_rcu_grace_period(rsp->name,
1933 ACCESS_ONCE(rsp->gpnum),
1934 TPS("fqswait"));
afea227f 1935 rsp->gp_state = RCU_GP_WAIT_FQS;
4cdfc175 1936 ret = wait_event_interruptible_timeout(rsp->gp_wq,
88d6df61
PM
1937 ((gf = ACCESS_ONCE(rsp->gp_flags)) &
1938 RCU_GP_FLAG_FQS) ||
4cdfc175
PM
1939 (!ACCESS_ONCE(rnp->qsmask) &&
1940 !rcu_preempt_blocked_readers_cgp(rnp)),
d40011f6 1941 j);
78e4bc34 1942 /* Locking provides needed memory barriers. */
4cdfc175 1943 /* If grace period done, leave loop. */
cabc49c1 1944 if (!ACCESS_ONCE(rnp->qsmask) &&
4cdfc175 1945 !rcu_preempt_blocked_readers_cgp(rnp))
cabc49c1 1946 break;
4cdfc175 1947 /* If time for quiescent-state forcing, do it. */
88d6df61
PM
1948 if (ULONG_CMP_GE(jiffies, rsp->jiffies_force_qs) ||
1949 (gf & RCU_GP_FLAG_FQS)) {
63c4db78
PM
1950 trace_rcu_grace_period(rsp->name,
1951 ACCESS_ONCE(rsp->gpnum),
1952 TPS("fqsstart"));
4cdfc175 1953 fqs_state = rcu_gp_fqs(rsp, fqs_state);
63c4db78
PM
1954 trace_rcu_grace_period(rsp->name,
1955 ACCESS_ONCE(rsp->gpnum),
1956 TPS("fqsend"));
bde6c3aa 1957 cond_resched_rcu_qs();
6ccd2ecd 1958 ACCESS_ONCE(rsp->gp_activity) = jiffies;
4cdfc175
PM
1959 } else {
1960 /* Deal with stray signal. */
bde6c3aa 1961 cond_resched_rcu_qs();
6ccd2ecd 1962 ACCESS_ONCE(rsp->gp_activity) = jiffies;
73a860cd 1963 WARN_ON(signal_pending(current));
63c4db78
PM
1964 trace_rcu_grace_period(rsp->name,
1965 ACCESS_ONCE(rsp->gpnum),
1966 TPS("fqswaitsig"));
4cdfc175 1967 }
d40011f6
PM
1968 j = jiffies_till_next_fqs;
1969 if (j > HZ) {
1970 j = HZ;
1971 jiffies_till_next_fqs = HZ;
1972 } else if (j < 1) {
1973 j = 1;
1974 jiffies_till_next_fqs = 1;
1975 }
cabc49c1 1976 }
4cdfc175
PM
1977
1978 /* Handle grace-period end. */
1979 rcu_gp_cleanup(rsp);
b3dbec76 1980 }
b3dbec76
PM
1981}
1982
64db4cff
PM
1983/*
1984 * Start a new RCU grace period if warranted, re-initializing the hierarchy
1985 * in preparation for detecting the next grace period. The caller must hold
b8462084 1986 * the root node's ->lock and hard irqs must be disabled.
e5601400
PM
1987 *
1988 * Note that it is legal for a dying CPU (which is marked as offline) to
1989 * invoke this function. This can happen when the dying CPU reports its
1990 * quiescent state.
48a7639c
PM
1991 *
1992 * Returns true if the grace-period kthread must be awakened.
64db4cff 1993 */
48a7639c 1994static bool
910ee45d
PM
1995rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
1996 struct rcu_data *rdp)
64db4cff 1997{
b8462084 1998 if (!rsp->gp_kthread || !cpu_needs_another_gp(rsp, rdp)) {
afe24b12 1999 /*
b3dbec76 2000 * Either we have not yet spawned the grace-period
62da1921
PM
2001 * task, this CPU does not need another grace period,
2002 * or a grace period is already in progress.
b3dbec76 2003 * Either way, don't start a new grace period.
afe24b12 2004 */
48a7639c 2005 return false;
afe24b12 2006 }
91dc9542 2007 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
bb311ecc
PM
2008 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
2009 TPS("newreq"));
62da1921 2010
016a8d5b
SR
2011 /*
2012 * We can't do wakeups while holding the rnp->lock, as that
1eafd31c 2013 * could cause possible deadlocks with the rq->lock. Defer
48a7639c 2014 * the wakeup to our caller.
016a8d5b 2015 */
48a7639c 2016 return true;
64db4cff
PM
2017}
2018
910ee45d
PM
2019/*
2020 * Similar to rcu_start_gp_advanced(), but also advance the calling CPU's
2021 * callbacks. Note that rcu_start_gp_advanced() cannot do this because it
2022 * is invoked indirectly from rcu_advance_cbs(), which would result in
2023 * endless recursion -- or would do so if it wasn't for the self-deadlock
2024 * that is encountered beforehand.
48a7639c
PM
2025 *
2026 * Returns true if the grace-period kthread needs to be awakened.
910ee45d 2027 */
48a7639c 2028static bool rcu_start_gp(struct rcu_state *rsp)
910ee45d
PM
2029{
2030 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
2031 struct rcu_node *rnp = rcu_get_root(rsp);
48a7639c 2032 bool ret = false;
910ee45d
PM
2033
2034 /*
2035 * If there is no grace period in progress right now, any
2036 * callbacks we have up to this point will be satisfied by the
2037 * next grace period. Also, advancing the callbacks reduces the
2038 * probability of false positives from cpu_needs_another_gp()
2039 * resulting in pointless grace periods. So, advance callbacks
2040 * then start the grace period!
2041 */
48a7639c
PM
2042 ret = rcu_advance_cbs(rsp, rnp, rdp) || ret;
2043 ret = rcu_start_gp_advanced(rsp, rnp, rdp) || ret;
2044 return ret;
910ee45d
PM
2045}
2046
f41d911f 2047/*
d3f6bad3
PM
2048 * Report a full set of quiescent states to the specified rcu_state
2049 * data structure. This involves cleaning up after the prior grace
2050 * period and letting rcu_start_gp() start up the next grace period
b8462084
PM
2051 * if one is needed. Note that the caller must hold rnp->lock, which
2052 * is released before return.
f41d911f 2053 */
d3f6bad3 2054static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
fc2219d4 2055 __releases(rcu_get_root(rsp)->lock)
f41d911f 2056{
fc2219d4 2057 WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
cabc49c1 2058 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
2aa792e6 2059 rcu_gp_kthread_wake(rsp);
f41d911f
PM
2060}
2061
64db4cff 2062/*
d3f6bad3
PM
2063 * Similar to rcu_report_qs_rdp(), for which it is a helper function.
2064 * Allows quiescent states for a group of CPUs to be reported at one go
2065 * to the specified rcu_node structure, though all the CPUs in the group
2066 * must be represented by the same rcu_node structure (which need not be
2067 * a leaf rcu_node structure, though it often will be). That structure's
2068 * lock must be held upon entry, and it is released before return.
64db4cff
PM
2069 */
2070static void
d3f6bad3
PM
2071rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp,
2072 struct rcu_node *rnp, unsigned long flags)
64db4cff
PM
2073 __releases(rnp->lock)
2074{
28ecd580
PM
2075 struct rcu_node *rnp_c;
2076
64db4cff
PM
2077 /* Walk up the rcu_node hierarchy. */
2078 for (;;) {
2079 if (!(rnp->qsmask & mask)) {
2080
2081 /* Our bit has already been cleared, so done. */
1304afb2 2082 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff
PM
2083 return;
2084 }
2085 rnp->qsmask &= ~mask;
d4c08f2a
PM
2086 trace_rcu_quiescent_state_report(rsp->name, rnp->gpnum,
2087 mask, rnp->qsmask, rnp->level,
2088 rnp->grplo, rnp->grphi,
2089 !!rnp->gp_tasks);
27f4d280 2090 if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
64db4cff
PM
2091
2092 /* Other bits still set at this level, so done. */
1304afb2 2093 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff
PM
2094 return;
2095 }
2096 mask = rnp->grpmask;
2097 if (rnp->parent == NULL) {
2098
2099 /* No more levels. Exit loop holding root lock. */
2100
2101 break;
2102 }
1304afb2 2103 raw_spin_unlock_irqrestore(&rnp->lock, flags);
28ecd580 2104 rnp_c = rnp;
64db4cff 2105 rnp = rnp->parent;
1304afb2 2106 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 2107 smp_mb__after_unlock_lock();
28ecd580 2108 WARN_ON_ONCE(rnp_c->qsmask);
64db4cff
PM
2109 }
2110
2111 /*
2112 * Get here if we are the last CPU to pass through a quiescent
d3f6bad3 2113 * state for this grace period. Invoke rcu_report_qs_rsp()
f41d911f 2114 * to clean up and start the next grace period if one is needed.
64db4cff 2115 */
d3f6bad3 2116 rcu_report_qs_rsp(rsp, flags); /* releases rnp->lock. */
64db4cff
PM
2117}
2118
2119/*
d3f6bad3
PM
2120 * Record a quiescent state for the specified CPU to that CPU's rcu_data
2121 * structure. This must be either called from the specified CPU, or
2122 * called when the specified CPU is known to be offline (and when it is
2123 * also known that no other CPU is concurrently trying to help the offline
2124 * CPU). The lastcomp argument is used to make sure we are still in the
2125 * grace period of interest. We don't want to end the current grace period
2126 * based on quiescent states detected in an earlier grace period!
64db4cff
PM
2127 */
2128static void
d7d6a11e 2129rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
64db4cff
PM
2130{
2131 unsigned long flags;
2132 unsigned long mask;
48a7639c 2133 bool needwake;
64db4cff
PM
2134 struct rcu_node *rnp;
2135
2136 rnp = rdp->mynode;
1304afb2 2137 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 2138 smp_mb__after_unlock_lock();
5cd37193
PM
2139 if ((rdp->passed_quiesce == 0 &&
2140 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr)) ||
2141 rdp->gpnum != rnp->gpnum || rnp->completed == rnp->gpnum ||
2142 rdp->gpwrap) {
64db4cff
PM
2143
2144 /*
e4cc1f22
PM
2145 * The grace period in which this quiescent state was
2146 * recorded has ended, so don't report it upwards.
2147 * We will instead need a new quiescent state that lies
2148 * within the current grace period.
64db4cff 2149 */
e4cc1f22 2150 rdp->passed_quiesce = 0; /* need qs for new gp. */
5cd37193 2151 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
1304afb2 2152 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff
PM
2153 return;
2154 }
2155 mask = rdp->grpmask;
2156 if ((rnp->qsmask & mask) == 0) {
1304afb2 2157 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff
PM
2158 } else {
2159 rdp->qs_pending = 0;
2160
2161 /*
2162 * This GP can't end until cpu checks in, so all of our
2163 * callbacks can be processed during the next GP.
2164 */
48a7639c 2165 needwake = rcu_accelerate_cbs(rsp, rnp, rdp);
64db4cff 2166
d3f6bad3 2167 rcu_report_qs_rnp(mask, rsp, rnp, flags); /* rlses rnp->lock */
48a7639c
PM
2168 if (needwake)
2169 rcu_gp_kthread_wake(rsp);
64db4cff
PM
2170 }
2171}
2172
2173/*
2174 * Check to see if there is a new grace period of which this CPU
2175 * is not yet aware, and if so, set up local rcu_data state for it.
2176 * Otherwise, see if this CPU has just passed through its first
2177 * quiescent state for this grace period, and record that fact if so.
2178 */
2179static void
2180rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
2181{
05eb552b
PM
2182 /* Check for grace-period ends and beginnings. */
2183 note_gp_changes(rsp, rdp);
64db4cff
PM
2184
2185 /*
2186 * Does this CPU still need to do its part for current grace period?
2187 * If no, return and let the other CPUs do their part as well.
2188 */
2189 if (!rdp->qs_pending)
2190 return;
2191
2192 /*
2193 * Was there a quiescent state since the beginning of the grace
2194 * period? If no, then exit and wait for the next call.
2195 */
5cd37193
PM
2196 if (!rdp->passed_quiesce &&
2197 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr))
64db4cff
PM
2198 return;
2199
d3f6bad3
PM
2200 /*
2201 * Tell RCU we are done (but rcu_report_qs_rdp() will be the
2202 * judge of that).
2203 */
d7d6a11e 2204 rcu_report_qs_rdp(rdp->cpu, rsp, rdp);
64db4cff
PM
2205}
2206
2207#ifdef CONFIG_HOTPLUG_CPU
2208
e74f4c45 2209/*
b1420f1c
PM
2210 * Send the specified CPU's RCU callbacks to the orphanage. The
2211 * specified CPU must be offline, and the caller must hold the
7b2e6011 2212 * ->orphan_lock.
e74f4c45 2213 */
b1420f1c
PM
2214static void
2215rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
2216 struct rcu_node *rnp, struct rcu_data *rdp)
e74f4c45 2217{
3fbfbf7a 2218 /* No-CBs CPUs do not have orphanable callbacks. */
d1e43fa5 2219 if (rcu_is_nocb_cpu(rdp->cpu))
3fbfbf7a
PM
2220 return;
2221
b1420f1c
PM
2222 /*
2223 * Orphan the callbacks. First adjust the counts. This is safe
abfd6e58
PM
2224 * because _rcu_barrier() excludes CPU-hotplug operations, so it
2225 * cannot be running now. Thus no memory barrier is required.
b1420f1c 2226 */
a50c3af9 2227 if (rdp->nxtlist != NULL) {
b1420f1c
PM
2228 rsp->qlen_lazy += rdp->qlen_lazy;
2229 rsp->qlen += rdp->qlen;
2230 rdp->n_cbs_orphaned += rdp->qlen;
a50c3af9 2231 rdp->qlen_lazy = 0;
1d1fb395 2232 ACCESS_ONCE(rdp->qlen) = 0;
a50c3af9
PM
2233 }
2234
2235 /*
b1420f1c
PM
2236 * Next, move those callbacks still needing a grace period to
2237 * the orphanage, where some other CPU will pick them up.
2238 * Some of the callbacks might have gone partway through a grace
2239 * period, but that is too bad. They get to start over because we
2240 * cannot assume that grace periods are synchronized across CPUs.
2241 * We don't bother updating the ->nxttail[] array yet, instead
2242 * we just reset the whole thing later on.
a50c3af9 2243 */
b1420f1c
PM
2244 if (*rdp->nxttail[RCU_DONE_TAIL] != NULL) {
2245 *rsp->orphan_nxttail = *rdp->nxttail[RCU_DONE_TAIL];
2246 rsp->orphan_nxttail = rdp->nxttail[RCU_NEXT_TAIL];
2247 *rdp->nxttail[RCU_DONE_TAIL] = NULL;
a50c3af9
PM
2248 }
2249
2250 /*
b1420f1c
PM
2251 * Then move the ready-to-invoke callbacks to the orphanage,
2252 * where some other CPU will pick them up. These will not be
2253 * required to pass though another grace period: They are done.
a50c3af9 2254 */
e5601400 2255 if (rdp->nxtlist != NULL) {
b1420f1c
PM
2256 *rsp->orphan_donetail = rdp->nxtlist;
2257 rsp->orphan_donetail = rdp->nxttail[RCU_DONE_TAIL];
e5601400 2258 }
e74f4c45 2259
b33078b6
PM
2260 /*
2261 * Finally, initialize the rcu_data structure's list to empty and
2262 * disallow further callbacks on this CPU.
2263 */
3f5d3ea6 2264 init_callback_list(rdp);
b33078b6 2265 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
b1420f1c
PM
2266}
2267
2268/*
2269 * Adopt the RCU callbacks from the specified rcu_state structure's
7b2e6011 2270 * orphanage. The caller must hold the ->orphan_lock.
b1420f1c 2271 */
96d3fd0d 2272static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)
b1420f1c
PM
2273{
2274 int i;
fa07a58f 2275 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
b1420f1c 2276
3fbfbf7a 2277 /* No-CBs CPUs are handled specially. */
96d3fd0d 2278 if (rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags))
3fbfbf7a
PM
2279 return;
2280
b1420f1c
PM
2281 /* Do the accounting first. */
2282 rdp->qlen_lazy += rsp->qlen_lazy;
2283 rdp->qlen += rsp->qlen;
2284 rdp->n_cbs_adopted += rsp->qlen;
8f5af6f1
PM
2285 if (rsp->qlen_lazy != rsp->qlen)
2286 rcu_idle_count_callbacks_posted();
b1420f1c
PM
2287 rsp->qlen_lazy = 0;
2288 rsp->qlen = 0;
2289
2290 /*
2291 * We do not need a memory barrier here because the only way we
2292 * can get here if there is an rcu_barrier() in flight is if
2293 * we are the task doing the rcu_barrier().
2294 */
2295
2296 /* First adopt the ready-to-invoke callbacks. */
2297 if (rsp->orphan_donelist != NULL) {
2298 *rsp->orphan_donetail = *rdp->nxttail[RCU_DONE_TAIL];
2299 *rdp->nxttail[RCU_DONE_TAIL] = rsp->orphan_donelist;
2300 for (i = RCU_NEXT_SIZE - 1; i >= RCU_DONE_TAIL; i--)
2301 if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
2302 rdp->nxttail[i] = rsp->orphan_donetail;
2303 rsp->orphan_donelist = NULL;
2304 rsp->orphan_donetail = &rsp->orphan_donelist;
2305 }
2306
2307 /* And then adopt the callbacks that still need a grace period. */
2308 if (rsp->orphan_nxtlist != NULL) {
2309 *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxtlist;
2310 rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxttail;
2311 rsp->orphan_nxtlist = NULL;
2312 rsp->orphan_nxttail = &rsp->orphan_nxtlist;
2313 }
2314}
2315
2316/*
2317 * Trace the fact that this CPU is going offline.
2318 */
2319static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
2320{
2321 RCU_TRACE(unsigned long mask);
2322 RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda));
2323 RCU_TRACE(struct rcu_node *rnp = rdp->mynode);
2324
2325 RCU_TRACE(mask = rdp->grpmask);
e5601400
PM
2326 trace_rcu_grace_period(rsp->name,
2327 rnp->gpnum + 1 - !!(rnp->qsmask & mask),
f7f7bac9 2328 TPS("cpuofl"));
64db4cff
PM
2329}
2330
8af3a5e7
PM
2331/*
2332 * All CPUs for the specified rcu_node structure have gone offline,
2333 * and all tasks that were preempted within an RCU read-side critical
2334 * section while running on one of those CPUs have since exited their RCU
2335 * read-side critical section. Some other CPU is reporting this fact with
2336 * the specified rcu_node structure's ->lock held and interrupts disabled.
2337 * This function therefore goes up the tree of rcu_node structures,
2338 * clearing the corresponding bits in the ->qsmaskinit fields. Note that
2339 * the leaf rcu_node structure's ->qsmaskinit field has already been
2340 * updated
2341 *
2342 * This function does check that the specified rcu_node structure has
2343 * all CPUs offline and no blocked tasks, so it is OK to invoke it
2344 * prematurely. That said, invoking it after the fact will cost you
2345 * a needless lock acquisition. So once it has done its work, don't
2346 * invoke it again.
2347 */
2348static void rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
2349{
2350 long mask;
2351 struct rcu_node *rnp = rnp_leaf;
2352
2353 if (rnp->qsmaskinit || rcu_preempt_has_tasks(rnp))
2354 return;
2355 for (;;) {
2356 mask = rnp->grpmask;
2357 rnp = rnp->parent;
2358 if (!rnp)
2359 break;
2360 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
2361 smp_mb__after_unlock_lock(); /* GP memory ordering. */
2362 rnp->qsmaskinit &= ~mask;
2363 if (rnp->qsmaskinit) {
2364 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
2365 return;
2366 }
2367 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
2368 }
2369}
2370
64db4cff 2371/*
e5601400 2372 * The CPU has been completely removed, and some other CPU is reporting
b1420f1c
PM
2373 * this fact from process context. Do the remainder of the cleanup,
2374 * including orphaning the outgoing CPU's RCU callbacks, and also
1331e7a1
PM
2375 * adopting them. There can only be one CPU hotplug operation at a time,
2376 * so no other CPU can be attempting to update rcu_cpu_kthread_task.
64db4cff 2377 */
e5601400 2378static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
64db4cff 2379{
2036d94a 2380 unsigned long flags;
e5601400 2381 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
b1420f1c 2382 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
e5601400 2383
2036d94a 2384 /* Adjust any no-longer-needed kthreads. */
5d01bbd1 2385 rcu_boost_kthread_setaffinity(rnp, -1);
2036d94a 2386
2036d94a 2387 /* Exclude any attempts to start a new grace period. */
a4fbe35a 2388 mutex_lock(&rsp->onoff_mutex);
2036d94a 2389
b1420f1c 2390 /* Orphan the dead CPU's callbacks, and adopt them if appropriate. */
78043c46 2391 raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
b1420f1c 2392 rcu_send_cbs_to_orphanage(cpu, rsp, rnp, rdp);
96d3fd0d 2393 rcu_adopt_orphan_cbs(rsp, flags);
a8f4cbad 2394 raw_spin_unlock_irqrestore(&rsp->orphan_lock, flags);
b1420f1c 2395
8af3a5e7 2396 /* Remove outgoing CPU from mask in the leaf rcu_node structure. */
a8f4cbad 2397 raw_spin_lock_irqsave(&rnp->lock, flags);
8af3a5e7
PM
2398 smp_mb__after_unlock_lock(); /* Enforce GP memory-order guarantee. */
2399 rnp->qsmaskinit &= ~rdp->grpmask;
d19fb8d1 2400 if (rnp->qsmaskinit == 0 && !rcu_preempt_has_tasks(rnp))
8af3a5e7 2401 rcu_cleanup_dead_rnp(rnp);
3ba4d0e0 2402 rcu_report_qs_rnp(rdp->grpmask, rsp, rnp, flags); /* Rlses rnp->lock. */
cf01537e
PM
2403 WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL,
2404 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n",
2405 cpu, rdp->qlen, rdp->nxtlist);
a4fbe35a 2406 mutex_unlock(&rsp->onoff_mutex);
64db4cff
PM
2407}
2408
2409#else /* #ifdef CONFIG_HOTPLUG_CPU */
2410
e5601400 2411static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
e74f4c45
PM
2412{
2413}
2414
b6a932d1
PM
2415static void __maybe_unused rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
2416{
2417}
2418
e5601400 2419static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
64db4cff
PM
2420{
2421}
2422
2423#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
2424
2425/*
2426 * Invoke any RCU callbacks that have made it to the end of their grace
2427 * period. Thottle as specified by rdp->blimit.
2428 */
37c72e56 2429static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
64db4cff
PM
2430{
2431 unsigned long flags;
2432 struct rcu_head *next, *list, **tail;
878d7439
ED
2433 long bl, count, count_lazy;
2434 int i;
64db4cff 2435
dc35c893 2436 /* If no callbacks are ready, just return. */
29c00b4a 2437 if (!cpu_has_callbacks_ready_to_invoke(rdp)) {
486e2593 2438 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, 0);
4968c300
PM
2439 trace_rcu_batch_end(rsp->name, 0, !!ACCESS_ONCE(rdp->nxtlist),
2440 need_resched(), is_idle_task(current),
2441 rcu_is_callbacks_kthread());
64db4cff 2442 return;
29c00b4a 2443 }
64db4cff
PM
2444
2445 /*
2446 * Extract the list of ready callbacks, disabling to prevent
2447 * races with call_rcu() from interrupt handlers.
2448 */
2449 local_irq_save(flags);
8146c4e2 2450 WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
29c00b4a 2451 bl = rdp->blimit;
486e2593 2452 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, bl);
64db4cff
PM
2453 list = rdp->nxtlist;
2454 rdp->nxtlist = *rdp->nxttail[RCU_DONE_TAIL];
2455 *rdp->nxttail[RCU_DONE_TAIL] = NULL;
2456 tail = rdp->nxttail[RCU_DONE_TAIL];
b41772ab
PM
2457 for (i = RCU_NEXT_SIZE - 1; i >= 0; i--)
2458 if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
2459 rdp->nxttail[i] = &rdp->nxtlist;
64db4cff
PM
2460 local_irq_restore(flags);
2461
2462 /* Invoke callbacks. */
486e2593 2463 count = count_lazy = 0;
64db4cff
PM
2464 while (list) {
2465 next = list->next;
2466 prefetch(next);
551d55a9 2467 debug_rcu_head_unqueue(list);
486e2593
PM
2468 if (__rcu_reclaim(rsp->name, list))
2469 count_lazy++;
64db4cff 2470 list = next;
dff1672d
PM
2471 /* Stop only if limit reached and CPU has something to do. */
2472 if (++count >= bl &&
2473 (need_resched() ||
2474 (!is_idle_task(current) && !rcu_is_callbacks_kthread())))
64db4cff
PM
2475 break;
2476 }
2477
2478 local_irq_save(flags);
4968c300
PM
2479 trace_rcu_batch_end(rsp->name, count, !!list, need_resched(),
2480 is_idle_task(current),
2481 rcu_is_callbacks_kthread());
64db4cff
PM
2482
2483 /* Update count, and requeue any remaining callbacks. */
64db4cff
PM
2484 if (list != NULL) {
2485 *tail = rdp->nxtlist;
2486 rdp->nxtlist = list;
b41772ab
PM
2487 for (i = 0; i < RCU_NEXT_SIZE; i++)
2488 if (&rdp->nxtlist == rdp->nxttail[i])
2489 rdp->nxttail[i] = tail;
64db4cff
PM
2490 else
2491 break;
2492 }
b1420f1c
PM
2493 smp_mb(); /* List handling before counting for rcu_barrier(). */
2494 rdp->qlen_lazy -= count_lazy;
a792563b 2495 ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
b1420f1c 2496 rdp->n_cbs_invoked += count;
64db4cff
PM
2497
2498 /* Reinstate batch limit if we have worked down the excess. */
2499 if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark)
2500 rdp->blimit = blimit;
2501
37c72e56
PM
2502 /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */
2503 if (rdp->qlen == 0 && rdp->qlen_last_fqs_check != 0) {
2504 rdp->qlen_last_fqs_check = 0;
2505 rdp->n_force_qs_snap = rsp->n_force_qs;
2506 } else if (rdp->qlen < rdp->qlen_last_fqs_check - qhimark)
2507 rdp->qlen_last_fqs_check = rdp->qlen;
cfca9279 2508 WARN_ON_ONCE((rdp->nxtlist == NULL) != (rdp->qlen == 0));
37c72e56 2509
64db4cff
PM
2510 local_irq_restore(flags);
2511
e0f23060 2512 /* Re-invoke RCU core processing if there are callbacks remaining. */
64db4cff 2513 if (cpu_has_callbacks_ready_to_invoke(rdp))
a46e0899 2514 invoke_rcu_core();
64db4cff
PM
2515}
2516
2517/*
2518 * Check to see if this CPU is in a non-context-switch quiescent state
2519 * (user mode or idle loop for rcu, non-softirq execution for rcu_bh).
e0f23060 2520 * Also schedule RCU core processing.
64db4cff 2521 *
9b2e4f18 2522 * This function must be called from hardirq context. It is normally
64db4cff
PM
2523 * invoked from the scheduling-clock interrupt. If rcu_pending returns
2524 * false, there is no point in invoking rcu_check_callbacks().
2525 */
c3377c2d 2526void rcu_check_callbacks(int user)
64db4cff 2527{
f7f7bac9 2528 trace_rcu_utilization(TPS("Start scheduler-tick"));
a858af28 2529 increment_cpu_stall_ticks();
9b2e4f18 2530 if (user || rcu_is_cpu_rrupt_from_idle()) {
64db4cff
PM
2531
2532 /*
2533 * Get here if this CPU took its interrupt from user
2534 * mode or from the idle loop, and if this is not a
2535 * nested interrupt. In this case, the CPU is in
d6714c22 2536 * a quiescent state, so note it.
64db4cff
PM
2537 *
2538 * No memory barrier is required here because both
d6714c22
PM
2539 * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local
2540 * variables that other CPUs neither access nor modify,
2541 * at least not while the corresponding CPU is online.
64db4cff
PM
2542 */
2543
284a8c93
PM
2544 rcu_sched_qs();
2545 rcu_bh_qs();
64db4cff
PM
2546
2547 } else if (!in_softirq()) {
2548
2549 /*
2550 * Get here if this CPU did not take its interrupt from
2551 * softirq, in other words, if it is not interrupting
2552 * a rcu_bh read-side critical section. This is an _bh
d6714c22 2553 * critical section, so note it.
64db4cff
PM
2554 */
2555
284a8c93 2556 rcu_bh_qs();
64db4cff 2557 }
86aea0e6 2558 rcu_preempt_check_callbacks();
e3950ecd 2559 if (rcu_pending())
a46e0899 2560 invoke_rcu_core();
8315f422
PM
2561 if (user)
2562 rcu_note_voluntary_context_switch(current);
f7f7bac9 2563 trace_rcu_utilization(TPS("End scheduler-tick"));
64db4cff
PM
2564}
2565
64db4cff
PM
2566/*
2567 * Scan the leaf rcu_node structures, processing dyntick state for any that
2568 * have not yet encountered a quiescent state, using the function specified.
27f4d280
PM
2569 * Also initiate boosting for any threads blocked on the root rcu_node.
2570 *
ee47eb9f 2571 * The caller must have suppressed start of new grace periods.
64db4cff 2572 */
217af2a2
PM
2573static void force_qs_rnp(struct rcu_state *rsp,
2574 int (*f)(struct rcu_data *rsp, bool *isidle,
2575 unsigned long *maxj),
2576 bool *isidle, unsigned long *maxj)
64db4cff
PM
2577{
2578 unsigned long bit;
2579 int cpu;
2580 unsigned long flags;
2581 unsigned long mask;
a0b6c9a7 2582 struct rcu_node *rnp;
64db4cff 2583
a0b6c9a7 2584 rcu_for_each_leaf_node(rsp, rnp) {
bde6c3aa 2585 cond_resched_rcu_qs();
64db4cff 2586 mask = 0;
1304afb2 2587 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 2588 smp_mb__after_unlock_lock();
ee47eb9f 2589 if (!rcu_gp_in_progress(rsp)) {
1304afb2 2590 raw_spin_unlock_irqrestore(&rnp->lock, flags);
0f10dc82 2591 return;
64db4cff 2592 }
a0b6c9a7 2593 if (rnp->qsmask == 0) {
1217ed1b 2594 rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
64db4cff
PM
2595 continue;
2596 }
a0b6c9a7 2597 cpu = rnp->grplo;
64db4cff 2598 bit = 1;
a0b6c9a7 2599 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
0edd1b17
PM
2600 if ((rnp->qsmask & bit) != 0) {
2601 if ((rnp->qsmaskinit & bit) != 0)
e02b2edf 2602 *isidle = false;
0edd1b17
PM
2603 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj))
2604 mask |= bit;
2605 }
64db4cff 2606 }
45f014c5 2607 if (mask != 0) {
64db4cff 2608
d3f6bad3
PM
2609 /* rcu_report_qs_rnp() releases rnp->lock. */
2610 rcu_report_qs_rnp(mask, rsp, rnp, flags);
64db4cff
PM
2611 continue;
2612 }
1304afb2 2613 raw_spin_unlock_irqrestore(&rnp->lock, flags);
64db4cff 2614 }
64db4cff
PM
2615}
2616
2617/*
2618 * Force quiescent states on reluctant CPUs, and also detect which
2619 * CPUs are in dyntick-idle mode.
2620 */
4cdfc175 2621static void force_quiescent_state(struct rcu_state *rsp)
64db4cff
PM
2622{
2623 unsigned long flags;
394f2769
PM
2624 bool ret;
2625 struct rcu_node *rnp;
2626 struct rcu_node *rnp_old = NULL;
2627
2628 /* Funnel through hierarchy to reduce memory contention. */
d860d403 2629 rnp = __this_cpu_read(rsp->rda->mynode);
394f2769
PM
2630 for (; rnp != NULL; rnp = rnp->parent) {
2631 ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
2632 !raw_spin_trylock(&rnp->fqslock);
2633 if (rnp_old != NULL)
2634 raw_spin_unlock(&rnp_old->fqslock);
2635 if (ret) {
a792563b 2636 rsp->n_force_qs_lh++;
394f2769
PM
2637 return;
2638 }
2639 rnp_old = rnp;
2640 }
2641 /* rnp_old == rcu_get_root(rsp), rnp == NULL. */
64db4cff 2642
394f2769
PM
2643 /* Reached the root of the rcu_node tree, acquire lock. */
2644 raw_spin_lock_irqsave(&rnp_old->lock, flags);
6303b9c8 2645 smp_mb__after_unlock_lock();
394f2769
PM
2646 raw_spin_unlock(&rnp_old->fqslock);
2647 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
a792563b 2648 rsp->n_force_qs_lh++;
394f2769 2649 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
4cdfc175 2650 return; /* Someone beat us to it. */
46a1e34e 2651 }
4de376a1
PK
2652 ACCESS_ONCE(rsp->gp_flags) =
2653 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
394f2769 2654 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2aa792e6 2655 rcu_gp_kthread_wake(rsp);
64db4cff
PM
2656}
2657
64db4cff 2658/*
e0f23060
PM
2659 * This does the RCU core processing work for the specified rcu_state
2660 * and rcu_data structures. This may be called only from the CPU to
2661 * whom the rdp belongs.
64db4cff
PM
2662 */
2663static void
1bca8cf1 2664__rcu_process_callbacks(struct rcu_state *rsp)
64db4cff
PM
2665{
2666 unsigned long flags;
48a7639c 2667 bool needwake;
fa07a58f 2668 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
64db4cff 2669
2e597558
PM
2670 WARN_ON_ONCE(rdp->beenonline == 0);
2671
64db4cff
PM
2672 /* Update RCU state based on any recent quiescent states. */
2673 rcu_check_quiescent_state(rsp, rdp);
2674
2675 /* Does this CPU require a not-yet-started grace period? */
dc35c893 2676 local_irq_save(flags);
64db4cff 2677 if (cpu_needs_another_gp(rsp, rdp)) {
dc35c893 2678 raw_spin_lock(&rcu_get_root(rsp)->lock); /* irqs disabled. */
48a7639c 2679 needwake = rcu_start_gp(rsp);
b8462084 2680 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
48a7639c
PM
2681 if (needwake)
2682 rcu_gp_kthread_wake(rsp);
dc35c893
PM
2683 } else {
2684 local_irq_restore(flags);
64db4cff
PM
2685 }
2686
2687 /* If there are callbacks ready, invoke them. */
09223371 2688 if (cpu_has_callbacks_ready_to_invoke(rdp))
a46e0899 2689 invoke_rcu_callbacks(rsp, rdp);
96d3fd0d
PM
2690
2691 /* Do any needed deferred wakeups of rcuo kthreads. */
2692 do_nocb_deferred_wakeup(rdp);
09223371
SL
2693}
2694
64db4cff 2695/*
e0f23060 2696 * Do RCU core processing for the current CPU.
64db4cff 2697 */
09223371 2698static void rcu_process_callbacks(struct softirq_action *unused)
64db4cff 2699{
6ce75a23
PM
2700 struct rcu_state *rsp;
2701
bfa00b4c
PM
2702 if (cpu_is_offline(smp_processor_id()))
2703 return;
f7f7bac9 2704 trace_rcu_utilization(TPS("Start RCU core"));
6ce75a23
PM
2705 for_each_rcu_flavor(rsp)
2706 __rcu_process_callbacks(rsp);
f7f7bac9 2707 trace_rcu_utilization(TPS("End RCU core"));
64db4cff
PM
2708}
2709
a26ac245 2710/*
e0f23060
PM
2711 * Schedule RCU callback invocation. If the specified type of RCU
2712 * does not support RCU priority boosting, just do a direct call,
2713 * otherwise wake up the per-CPU kernel kthread. Note that because we
924df8a0 2714 * are running on the current CPU with softirqs disabled, the
e0f23060 2715 * rcu_cpu_kthread_task cannot disappear out from under us.
a26ac245 2716 */
a46e0899 2717static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
a26ac245 2718{
b0d30417
PM
2719 if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active)))
2720 return;
a46e0899
PM
2721 if (likely(!rsp->boost)) {
2722 rcu_do_batch(rsp, rdp);
a26ac245
PM
2723 return;
2724 }
a46e0899 2725 invoke_rcu_callbacks_kthread();
a26ac245
PM
2726}
2727
a46e0899 2728static void invoke_rcu_core(void)
09223371 2729{
b0f74036
PM
2730 if (cpu_online(smp_processor_id()))
2731 raise_softirq(RCU_SOFTIRQ);
09223371
SL
2732}
2733
29154c57
PM
2734/*
2735 * Handle any core-RCU processing required by a call_rcu() invocation.
2736 */
2737static void __call_rcu_core(struct rcu_state *rsp, struct rcu_data *rdp,
2738 struct rcu_head *head, unsigned long flags)
64db4cff 2739{
48a7639c
PM
2740 bool needwake;
2741
62fde6ed
PM
2742 /*
2743 * If called from an extended quiescent state, invoke the RCU
2744 * core in order to force a re-evaluation of RCU's idleness.
2745 */
5c173eb8 2746 if (!rcu_is_watching() && cpu_online(smp_processor_id()))
62fde6ed
PM
2747 invoke_rcu_core();
2748
a16b7a69 2749 /* If interrupts were disabled or CPU offline, don't invoke RCU core. */
29154c57 2750 if (irqs_disabled_flags(flags) || cpu_is_offline(smp_processor_id()))
2655d57e 2751 return;
64db4cff 2752
37c72e56
PM
2753 /*
2754 * Force the grace period if too many callbacks or too long waiting.
2755 * Enforce hysteresis, and don't invoke force_quiescent_state()
2756 * if some other CPU has recently done so. Also, don't bother
2757 * invoking force_quiescent_state() if the newly enqueued callback
2758 * is the only one waiting for a grace period to complete.
2759 */
2655d57e 2760 if (unlikely(rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) {
b52573d2
PM
2761
2762 /* Are we ignoring a completed grace period? */
470716fc 2763 note_gp_changes(rsp, rdp);
b52573d2
PM
2764
2765 /* Start a new grace period if one not already started. */
2766 if (!rcu_gp_in_progress(rsp)) {
b52573d2
PM
2767 struct rcu_node *rnp_root = rcu_get_root(rsp);
2768
b8462084 2769 raw_spin_lock(&rnp_root->lock);
6303b9c8 2770 smp_mb__after_unlock_lock();
48a7639c 2771 needwake = rcu_start_gp(rsp);
b8462084 2772 raw_spin_unlock(&rnp_root->lock);
48a7639c
PM
2773 if (needwake)
2774 rcu_gp_kthread_wake(rsp);
b52573d2
PM
2775 } else {
2776 /* Give the grace period a kick. */
2777 rdp->blimit = LONG_MAX;
2778 if (rsp->n_force_qs == rdp->n_force_qs_snap &&
2779 *rdp->nxttail[RCU_DONE_TAIL] != head)
4cdfc175 2780 force_quiescent_state(rsp);
b52573d2
PM
2781 rdp->n_force_qs_snap = rsp->n_force_qs;
2782 rdp->qlen_last_fqs_check = rdp->qlen;
2783 }
4cdfc175 2784 }
29154c57
PM
2785}
2786
ae150184
PM
2787/*
2788 * RCU callback function to leak a callback.
2789 */
2790static void rcu_leak_callback(struct rcu_head *rhp)
2791{
2792}
2793
3fbfbf7a
PM
2794/*
2795 * Helper function for call_rcu() and friends. The cpu argument will
2796 * normally be -1, indicating "currently running CPU". It may specify
2797 * a CPU only if that CPU is a no-CBs CPU. Currently, only _rcu_barrier()
2798 * is expected to specify a CPU.
2799 */
64db4cff
PM
2800static void
2801__call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
3fbfbf7a 2802 struct rcu_state *rsp, int cpu, bool lazy)
64db4cff
PM
2803{
2804 unsigned long flags;
2805 struct rcu_data *rdp;
2806
1146edcb 2807 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
ae150184
PM
2808 if (debug_rcu_head_queue(head)) {
2809 /* Probable double call_rcu(), so leak the callback. */
2810 ACCESS_ONCE(head->func) = rcu_leak_callback;
2811 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
2812 return;
2813 }
64db4cff
PM
2814 head->func = func;
2815 head->next = NULL;
2816
64db4cff
PM
2817 /*
2818 * Opportunistically note grace-period endings and beginnings.
2819 * Note that we might see a beginning right after we see an
2820 * end, but never vice versa, since this CPU has to pass through
2821 * a quiescent state betweentimes.
2822 */
2823 local_irq_save(flags);
394f99a9 2824 rdp = this_cpu_ptr(rsp->rda);
64db4cff
PM
2825
2826 /* Add the callback to our list. */
3fbfbf7a
PM
2827 if (unlikely(rdp->nxttail[RCU_NEXT_TAIL] == NULL) || cpu != -1) {
2828 int offline;
2829
2830 if (cpu != -1)
2831 rdp = per_cpu_ptr(rsp->rda, cpu);
96d3fd0d 2832 offline = !__call_rcu_nocb(rdp, head, lazy, flags);
3fbfbf7a 2833 WARN_ON_ONCE(offline);
0d8ee37e 2834 /* _call_rcu() is illegal on offline CPU; leak the callback. */
0d8ee37e
PM
2835 local_irq_restore(flags);
2836 return;
2837 }
a792563b 2838 ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
486e2593
PM
2839 if (lazy)
2840 rdp->qlen_lazy++;
c57afe80
PM
2841 else
2842 rcu_idle_count_callbacks_posted();
b1420f1c
PM
2843 smp_mb(); /* Count before adding callback for rcu_barrier(). */
2844 *rdp->nxttail[RCU_NEXT_TAIL] = head;
2845 rdp->nxttail[RCU_NEXT_TAIL] = &head->next;
2655d57e 2846
d4c08f2a
PM
2847 if (__is_kfree_rcu_offset((unsigned long)func))
2848 trace_rcu_kfree_callback(rsp->name, head, (unsigned long)func,
486e2593 2849 rdp->qlen_lazy, rdp->qlen);
d4c08f2a 2850 else
486e2593 2851 trace_rcu_callback(rsp->name, head, rdp->qlen_lazy, rdp->qlen);
d4c08f2a 2852
29154c57
PM
2853 /* Go handle any RCU core processing required. */
2854 __call_rcu_core(rsp, rdp, head, flags);
64db4cff
PM
2855 local_irq_restore(flags);
2856}
2857
2858/*
d6714c22 2859 * Queue an RCU-sched callback for invocation after a grace period.
64db4cff 2860 */
d6714c22 2861void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
64db4cff 2862{
3fbfbf7a 2863 __call_rcu(head, func, &rcu_sched_state, -1, 0);
64db4cff 2864}
d6714c22 2865EXPORT_SYMBOL_GPL(call_rcu_sched);
64db4cff
PM
2866
2867/*
486e2593 2868 * Queue an RCU callback for invocation after a quicker grace period.
64db4cff
PM
2869 */
2870void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
2871{
3fbfbf7a 2872 __call_rcu(head, func, &rcu_bh_state, -1, 0);
64db4cff
PM
2873}
2874EXPORT_SYMBOL_GPL(call_rcu_bh);
2875
495aa969
ACB
2876/*
2877 * Queue an RCU callback for lazy invocation after a grace period.
2878 * This will likely be later named something like "call_rcu_lazy()",
2879 * but this change will require some way of tagging the lazy RCU
2880 * callbacks in the list of pending callbacks. Until then, this
2881 * function may only be called from __kfree_rcu().
2882 */
2883void kfree_call_rcu(struct rcu_head *head,
2884 void (*func)(struct rcu_head *rcu))
2885{
e534165b 2886 __call_rcu(head, func, rcu_state_p, -1, 1);
495aa969
ACB
2887}
2888EXPORT_SYMBOL_GPL(kfree_call_rcu);
2889
6d813391
PM
2890/*
2891 * Because a context switch is a grace period for RCU-sched and RCU-bh,
2892 * any blocking grace-period wait automatically implies a grace period
2893 * if there is only one CPU online at any point time during execution
2894 * of either synchronize_sched() or synchronize_rcu_bh(). It is OK to
2895 * occasionally incorrectly indicate that there are multiple CPUs online
2896 * when there was in fact only one the whole time, as this just adds
2897 * some overhead: RCU still operates correctly.
6d813391
PM
2898 */
2899static inline int rcu_blocking_is_gp(void)
2900{
95f0c1de
PM
2901 int ret;
2902
6d813391 2903 might_sleep(); /* Check for RCU read-side critical section. */
95f0c1de
PM
2904 preempt_disable();
2905 ret = num_online_cpus() <= 1;
2906 preempt_enable();
2907 return ret;
6d813391
PM
2908}
2909
6ebb237b
PM
2910/**
2911 * synchronize_sched - wait until an rcu-sched grace period has elapsed.
2912 *
2913 * Control will return to the caller some time after a full rcu-sched
2914 * grace period has elapsed, in other words after all currently executing
2915 * rcu-sched read-side critical sections have completed. These read-side
2916 * critical sections are delimited by rcu_read_lock_sched() and
2917 * rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(),
2918 * local_irq_disable(), and so on may be used in place of
2919 * rcu_read_lock_sched().
2920 *
2921 * This means that all preempt_disable code sequences, including NMI and
f0a0e6f2
PM
2922 * non-threaded hardware-interrupt handlers, in progress on entry will
2923 * have completed before this primitive returns. However, this does not
2924 * guarantee that softirq handlers will have completed, since in some
2925 * kernels, these handlers can run in process context, and can block.
2926 *
2927 * Note that this guarantee implies further memory-ordering guarantees.
2928 * On systems with more than one CPU, when synchronize_sched() returns,
2929 * each CPU is guaranteed to have executed a full memory barrier since the
2930 * end of its last RCU-sched read-side critical section whose beginning
2931 * preceded the call to synchronize_sched(). In addition, each CPU having
2932 * an RCU read-side critical section that extends beyond the return from
2933 * synchronize_sched() is guaranteed to have executed a full memory barrier
2934 * after the beginning of synchronize_sched() and before the beginning of
2935 * that RCU read-side critical section. Note that these guarantees include
2936 * CPUs that are offline, idle, or executing in user mode, as well as CPUs
2937 * that are executing in the kernel.
2938 *
2939 * Furthermore, if CPU A invoked synchronize_sched(), which returned
2940 * to its caller on CPU B, then both CPU A and CPU B are guaranteed
2941 * to have executed a full memory barrier during the execution of
2942 * synchronize_sched() -- even if CPU A and CPU B are the same CPU (but
2943 * again only if the system has more than one CPU).
6ebb237b
PM
2944 *
2945 * This primitive provides the guarantees made by the (now removed)
2946 * synchronize_kernel() API. In contrast, synchronize_rcu() only
2947 * guarantees that rcu_read_lock() sections will have completed.
2948 * In "classic RCU", these two guarantees happen to be one and
2949 * the same, but can differ in realtime RCU implementations.
2950 */
2951void synchronize_sched(void)
2952{
fe15d706
PM
2953 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
2954 !lock_is_held(&rcu_lock_map) &&
2955 !lock_is_held(&rcu_sched_lock_map),
2956 "Illegal synchronize_sched() in RCU-sched read-side critical section");
6ebb237b
PM
2957 if (rcu_blocking_is_gp())
2958 return;
3705b88d
AM
2959 if (rcu_expedited)
2960 synchronize_sched_expedited();
2961 else
2962 wait_rcu_gp(call_rcu_sched);
6ebb237b
PM
2963}
2964EXPORT_SYMBOL_GPL(synchronize_sched);
2965
2966/**
2967 * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
2968 *
2969 * Control will return to the caller some time after a full rcu_bh grace
2970 * period has elapsed, in other words after all currently executing rcu_bh
2971 * read-side critical sections have completed. RCU read-side critical
2972 * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(),
2973 * and may be nested.
f0a0e6f2
PM
2974 *
2975 * See the description of synchronize_sched() for more detailed information
2976 * on memory ordering guarantees.
6ebb237b
PM
2977 */
2978void synchronize_rcu_bh(void)
2979{
fe15d706
PM
2980 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
2981 !lock_is_held(&rcu_lock_map) &&
2982 !lock_is_held(&rcu_sched_lock_map),
2983 "Illegal synchronize_rcu_bh() in RCU-bh read-side critical section");
6ebb237b
PM
2984 if (rcu_blocking_is_gp())
2985 return;
3705b88d
AM
2986 if (rcu_expedited)
2987 synchronize_rcu_bh_expedited();
2988 else
2989 wait_rcu_gp(call_rcu_bh);
6ebb237b
PM
2990}
2991EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
2992
765a3f4f
PM
2993/**
2994 * get_state_synchronize_rcu - Snapshot current RCU state
2995 *
2996 * Returns a cookie that is used by a later call to cond_synchronize_rcu()
2997 * to determine whether or not a full grace period has elapsed in the
2998 * meantime.
2999 */
3000unsigned long get_state_synchronize_rcu(void)
3001{
3002 /*
3003 * Any prior manipulation of RCU-protected data must happen
3004 * before the load from ->gpnum.
3005 */
3006 smp_mb(); /* ^^^ */
3007
3008 /*
3009 * Make sure this load happens before the purportedly
3010 * time-consuming work between get_state_synchronize_rcu()
3011 * and cond_synchronize_rcu().
3012 */
e534165b 3013 return smp_load_acquire(&rcu_state_p->gpnum);
765a3f4f
PM
3014}
3015EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
3016
3017/**
3018 * cond_synchronize_rcu - Conditionally wait for an RCU grace period
3019 *
3020 * @oldstate: return value from earlier call to get_state_synchronize_rcu()
3021 *
3022 * If a full RCU grace period has elapsed since the earlier call to
3023 * get_state_synchronize_rcu(), just return. Otherwise, invoke
3024 * synchronize_rcu() to wait for a full grace period.
3025 *
3026 * Yes, this function does not take counter wrap into account. But
3027 * counter wrap is harmless. If the counter wraps, we have waited for
3028 * more than 2 billion grace periods (and way more on a 64-bit system!),
3029 * so waiting for one additional grace period should be just fine.
3030 */
3031void cond_synchronize_rcu(unsigned long oldstate)
3032{
3033 unsigned long newstate;
3034
3035 /*
3036 * Ensure that this load happens before any RCU-destructive
3037 * actions the caller might carry out after we return.
3038 */
e534165b 3039 newstate = smp_load_acquire(&rcu_state_p->completed);
765a3f4f
PM
3040 if (ULONG_CMP_GE(oldstate, newstate))
3041 synchronize_rcu();
3042}
3043EXPORT_SYMBOL_GPL(cond_synchronize_rcu);
3044
3d3b7db0
PM
3045static int synchronize_sched_expedited_cpu_stop(void *data)
3046{
3047 /*
3048 * There must be a full memory barrier on each affected CPU
3049 * between the time that try_stop_cpus() is called and the
3050 * time that it returns.
3051 *
3052 * In the current initial implementation of cpu_stop, the
3053 * above condition is already met when the control reaches
3054 * this point and the following smp_mb() is not strictly
3055 * necessary. Do smp_mb() anyway for documentation and
3056 * robustness against future implementation changes.
3057 */
3058 smp_mb(); /* See above comment block. */
3059 return 0;
3060}
3061
236fefaf
PM
3062/**
3063 * synchronize_sched_expedited - Brute-force RCU-sched grace period
3064 *
3065 * Wait for an RCU-sched grace period to elapse, but use a "big hammer"
3066 * approach to force the grace period to end quickly. This consumes
3067 * significant time on all CPUs and is unfriendly to real-time workloads,
3068 * so is thus not recommended for any sort of common-case code. In fact,
3069 * if you are using synchronize_sched_expedited() in a loop, please
3070 * restructure your code to batch your updates, and then use a single
3071 * synchronize_sched() instead.
3d3b7db0 3072 *
3d3b7db0
PM
3073 * This implementation can be thought of as an application of ticket
3074 * locking to RCU, with sync_sched_expedited_started and
3075 * sync_sched_expedited_done taking on the roles of the halves
3076 * of the ticket-lock word. Each task atomically increments
3077 * sync_sched_expedited_started upon entry, snapshotting the old value,
3078 * then attempts to stop all the CPUs. If this succeeds, then each
3079 * CPU will have executed a context switch, resulting in an RCU-sched
3080 * grace period. We are then done, so we use atomic_cmpxchg() to
3081 * update sync_sched_expedited_done to match our snapshot -- but
3082 * only if someone else has not already advanced past our snapshot.
3083 *
3084 * On the other hand, if try_stop_cpus() fails, we check the value
3085 * of sync_sched_expedited_done. If it has advanced past our
3086 * initial snapshot, then someone else must have forced a grace period
3087 * some time after we took our snapshot. In this case, our work is
3088 * done for us, and we can simply return. Otherwise, we try again,
3089 * but keep our initial snapshot for purposes of checking for someone
3090 * doing our work for us.
3091 *
3092 * If we fail too many times in a row, we fall back to synchronize_sched().
3093 */
3094void synchronize_sched_expedited(void)
3095{
e0775cef
PM
3096 cpumask_var_t cm;
3097 bool cma = false;
3098 int cpu;
1924bcb0
PM
3099 long firstsnap, s, snap;
3100 int trycount = 0;
40694d66 3101 struct rcu_state *rsp = &rcu_sched_state;
3d3b7db0 3102
1924bcb0
PM
3103 /*
3104 * If we are in danger of counter wrap, just do synchronize_sched().
3105 * By allowing sync_sched_expedited_started to advance no more than
3106 * ULONG_MAX/8 ahead of sync_sched_expedited_done, we are ensuring
3107 * that more than 3.5 billion CPUs would be required to force a
3108 * counter wrap on a 32-bit system. Quite a few more CPUs would of
3109 * course be required on a 64-bit system.
3110 */
40694d66
PM
3111 if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
3112 (ulong)atomic_long_read(&rsp->expedited_done) +
1924bcb0
PM
3113 ULONG_MAX / 8)) {
3114 synchronize_sched();
a30489c5 3115 atomic_long_inc(&rsp->expedited_wrap);
1924bcb0
PM
3116 return;
3117 }
3d3b7db0 3118
1924bcb0
PM
3119 /*
3120 * Take a ticket. Note that atomic_inc_return() implies a
3121 * full memory barrier.
3122 */
40694d66 3123 snap = atomic_long_inc_return(&rsp->expedited_start);
1924bcb0 3124 firstsnap = snap;
dd56af42
PM
3125 if (!try_get_online_cpus()) {
3126 /* CPU hotplug operation in flight, fall back to normal GP. */
3127 wait_rcu_gp(call_rcu_sched);
3128 atomic_long_inc(&rsp->expedited_normal);
3129 return;
3130 }
1cc85961 3131 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
3d3b7db0 3132
e0775cef
PM
3133 /* Offline CPUs, idle CPUs, and any CPU we run on are quiescent. */
3134 cma = zalloc_cpumask_var(&cm, GFP_KERNEL);
3135 if (cma) {
3136 cpumask_copy(cm, cpu_online_mask);
3137 cpumask_clear_cpu(raw_smp_processor_id(), cm);
3138 for_each_cpu(cpu, cm) {
3139 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
3140
3141 if (!(atomic_add_return(0, &rdtp->dynticks) & 0x1))
3142 cpumask_clear_cpu(cpu, cm);
3143 }
3144 if (cpumask_weight(cm) == 0)
3145 goto all_cpus_idle;
3146 }
3147
3d3b7db0
PM
3148 /*
3149 * Each pass through the following loop attempts to force a
3150 * context switch on each CPU.
3151 */
e0775cef 3152 while (try_stop_cpus(cma ? cm : cpu_online_mask,
3d3b7db0
PM
3153 synchronize_sched_expedited_cpu_stop,
3154 NULL) == -EAGAIN) {
3155 put_online_cpus();
a30489c5 3156 atomic_long_inc(&rsp->expedited_tryfail);
3d3b7db0 3157
1924bcb0 3158 /* Check to see if someone else did our work for us. */
40694d66 3159 s = atomic_long_read(&rsp->expedited_done);
1924bcb0 3160 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
a30489c5 3161 /* ensure test happens before caller kfree */
4e857c58 3162 smp_mb__before_atomic(); /* ^^^ */
a30489c5 3163 atomic_long_inc(&rsp->expedited_workdone1);
e0775cef 3164 free_cpumask_var(cm);
1924bcb0
PM
3165 return;
3166 }
3d3b7db0
PM
3167
3168 /* No joy, try again later. Or just synchronize_sched(). */
c701d5d9 3169 if (trycount++ < 10) {
3d3b7db0 3170 udelay(trycount * num_online_cpus());
c701d5d9 3171 } else {
3705b88d 3172 wait_rcu_gp(call_rcu_sched);
a30489c5 3173 atomic_long_inc(&rsp->expedited_normal);
e0775cef 3174 free_cpumask_var(cm);
3d3b7db0
PM
3175 return;
3176 }
3177
1924bcb0 3178 /* Recheck to see if someone else did our work for us. */
40694d66 3179 s = atomic_long_read(&rsp->expedited_done);
1924bcb0 3180 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
a30489c5 3181 /* ensure test happens before caller kfree */
4e857c58 3182 smp_mb__before_atomic(); /* ^^^ */
a30489c5 3183 atomic_long_inc(&rsp->expedited_workdone2);
e0775cef 3184 free_cpumask_var(cm);
3d3b7db0
PM
3185 return;
3186 }
3187
3188 /*
3189 * Refetching sync_sched_expedited_started allows later
1924bcb0
PM
3190 * callers to piggyback on our grace period. We retry
3191 * after they started, so our grace period works for them,
3192 * and they started after our first try, so their grace
3193 * period works for us.
3d3b7db0 3194 */
dd56af42
PM
3195 if (!try_get_online_cpus()) {
3196 /* CPU hotplug operation in flight, use normal GP. */
3197 wait_rcu_gp(call_rcu_sched);
3198 atomic_long_inc(&rsp->expedited_normal);
e0775cef 3199 free_cpumask_var(cm);
dd56af42
PM
3200 return;
3201 }
40694d66 3202 snap = atomic_long_read(&rsp->expedited_start);
3d3b7db0
PM
3203 smp_mb(); /* ensure read is before try_stop_cpus(). */
3204 }
a30489c5 3205 atomic_long_inc(&rsp->expedited_stoppedcpus);
3d3b7db0 3206
e0775cef
PM
3207all_cpus_idle:
3208 free_cpumask_var(cm);
3209
3d3b7db0
PM
3210 /*
3211 * Everyone up to our most recent fetch is covered by our grace
3212 * period. Update the counter, but only if our work is still
3213 * relevant -- which it won't be if someone who started later
1924bcb0 3214 * than we did already did their update.
3d3b7db0
PM
3215 */
3216 do {
a30489c5 3217 atomic_long_inc(&rsp->expedited_done_tries);
40694d66 3218 s = atomic_long_read(&rsp->expedited_done);
1924bcb0 3219 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
a30489c5 3220 /* ensure test happens before caller kfree */
4e857c58 3221 smp_mb__before_atomic(); /* ^^^ */
a30489c5 3222 atomic_long_inc(&rsp->expedited_done_lost);
3d3b7db0
PM
3223 break;
3224 }
40694d66 3225 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
a30489c5 3226 atomic_long_inc(&rsp->expedited_done_exit);
3d3b7db0
PM
3227
3228 put_online_cpus();
3229}
3230EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
3231
64db4cff
PM
3232/*
3233 * Check to see if there is any immediate RCU-related work to be done
3234 * by the current CPU, for the specified type of RCU, returning 1 if so.
3235 * The checks are in order of increasing expense: checks that can be
3236 * carried out against CPU-local state are performed first. However,
3237 * we must check for CPU stalls first, else we might not get a chance.
3238 */
3239static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
3240{
2f51f988
PM
3241 struct rcu_node *rnp = rdp->mynode;
3242
64db4cff
PM
3243 rdp->n_rcu_pending++;
3244
3245 /* Check for CPU stalls, if enabled. */
3246 check_cpu_stall(rsp, rdp);
3247
a096932f
PM
3248 /* Is this CPU a NO_HZ_FULL CPU that should ignore RCU? */
3249 if (rcu_nohz_full_cpu(rsp))
3250 return 0;
3251
64db4cff 3252 /* Is the RCU core waiting for a quiescent state from this CPU? */
5c51dd73 3253 if (rcu_scheduler_fully_active &&
5cd37193
PM
3254 rdp->qs_pending && !rdp->passed_quiesce &&
3255 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr)) {
d21670ac 3256 rdp->n_rp_qs_pending++;
5cd37193
PM
3257 } else if (rdp->qs_pending &&
3258 (rdp->passed_quiesce ||
3259 rdp->rcu_qs_ctr_snap != __this_cpu_read(rcu_qs_ctr))) {
d21670ac 3260 rdp->n_rp_report_qs++;
64db4cff 3261 return 1;
7ba5c840 3262 }
64db4cff
PM
3263
3264 /* Does this CPU have callbacks ready to invoke? */
7ba5c840
PM
3265 if (cpu_has_callbacks_ready_to_invoke(rdp)) {
3266 rdp->n_rp_cb_ready++;
64db4cff 3267 return 1;
7ba5c840 3268 }
64db4cff
PM
3269
3270 /* Has RCU gone idle with this CPU needing another grace period? */
7ba5c840
PM
3271 if (cpu_needs_another_gp(rsp, rdp)) {
3272 rdp->n_rp_cpu_needs_gp++;
64db4cff 3273 return 1;
7ba5c840 3274 }
64db4cff
PM
3275
3276 /* Has another RCU grace period completed? */
2f51f988 3277 if (ACCESS_ONCE(rnp->completed) != rdp->completed) { /* outside lock */
7ba5c840 3278 rdp->n_rp_gp_completed++;
64db4cff 3279 return 1;
7ba5c840 3280 }
64db4cff
PM
3281
3282 /* Has a new RCU grace period started? */
e3663b10
PM
3283 if (ACCESS_ONCE(rnp->gpnum) != rdp->gpnum ||
3284 unlikely(ACCESS_ONCE(rdp->gpwrap))) { /* outside lock */
7ba5c840 3285 rdp->n_rp_gp_started++;
64db4cff 3286 return 1;
7ba5c840 3287 }
64db4cff 3288
96d3fd0d
PM
3289 /* Does this CPU need a deferred NOCB wakeup? */
3290 if (rcu_nocb_need_deferred_wakeup(rdp)) {
3291 rdp->n_rp_nocb_defer_wakeup++;
3292 return 1;
3293 }
3294
64db4cff 3295 /* nothing to do */
7ba5c840 3296 rdp->n_rp_need_nothing++;
64db4cff
PM
3297 return 0;
3298}
3299
3300/*
3301 * Check to see if there is any immediate RCU-related work to be done
3302 * by the current CPU, returning 1 if so. This function is part of the
3303 * RCU implementation; it is -not- an exported member of the RCU API.
3304 */
e3950ecd 3305static int rcu_pending(void)
64db4cff 3306{
6ce75a23
PM
3307 struct rcu_state *rsp;
3308
3309 for_each_rcu_flavor(rsp)
e3950ecd 3310 if (__rcu_pending(rsp, this_cpu_ptr(rsp->rda)))
6ce75a23
PM
3311 return 1;
3312 return 0;
64db4cff
PM
3313}
3314
3315/*
c0f4dfd4
PM
3316 * Return true if the specified CPU has any callback. If all_lazy is
3317 * non-NULL, store an indication of whether all callbacks are lazy.
3318 * (If there are no callbacks, all of them are deemed to be lazy.)
64db4cff 3319 */
aa6da514 3320static int __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
64db4cff 3321{
c0f4dfd4
PM
3322 bool al = true;
3323 bool hc = false;
3324 struct rcu_data *rdp;
6ce75a23
PM
3325 struct rcu_state *rsp;
3326
c0f4dfd4 3327 for_each_rcu_flavor(rsp) {
aa6da514 3328 rdp = this_cpu_ptr(rsp->rda);
69c8d28c
PM
3329 if (!rdp->nxtlist)
3330 continue;
3331 hc = true;
3332 if (rdp->qlen != rdp->qlen_lazy || !all_lazy) {
c0f4dfd4 3333 al = false;
69c8d28c
PM
3334 break;
3335 }
c0f4dfd4
PM
3336 }
3337 if (all_lazy)
3338 *all_lazy = al;
3339 return hc;
64db4cff
PM
3340}
3341
a83eff0a
PM
3342/*
3343 * Helper function for _rcu_barrier() tracing. If tracing is disabled,
3344 * the compiler is expected to optimize this away.
3345 */
e66c33d5 3346static void _rcu_barrier_trace(struct rcu_state *rsp, const char *s,
a83eff0a
PM
3347 int cpu, unsigned long done)
3348{
3349 trace_rcu_barrier(rsp->name, s, cpu,
3350 atomic_read(&rsp->barrier_cpu_count), done);
3351}
3352
b1420f1c
PM
3353/*
3354 * RCU callback function for _rcu_barrier(). If we are last, wake
3355 * up the task executing _rcu_barrier().
3356 */
24ebbca8 3357static void rcu_barrier_callback(struct rcu_head *rhp)
d0ec774c 3358{
24ebbca8
PM
3359 struct rcu_data *rdp = container_of(rhp, struct rcu_data, barrier_head);
3360 struct rcu_state *rsp = rdp->rsp;
3361
a83eff0a
PM
3362 if (atomic_dec_and_test(&rsp->barrier_cpu_count)) {
3363 _rcu_barrier_trace(rsp, "LastCB", -1, rsp->n_barrier_done);
7db74df8 3364 complete(&rsp->barrier_completion);
a83eff0a
PM
3365 } else {
3366 _rcu_barrier_trace(rsp, "CB", -1, rsp->n_barrier_done);
3367 }
d0ec774c
PM
3368}
3369
3370/*
3371 * Called with preemption disabled, and from cross-cpu IRQ context.
3372 */
3373static void rcu_barrier_func(void *type)
3374{
037b64ed 3375 struct rcu_state *rsp = type;
fa07a58f 3376 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
d0ec774c 3377
a83eff0a 3378 _rcu_barrier_trace(rsp, "IRQ", -1, rsp->n_barrier_done);
24ebbca8 3379 atomic_inc(&rsp->barrier_cpu_count);
06668efa 3380 rsp->call(&rdp->barrier_head, rcu_barrier_callback);
d0ec774c
PM
3381}
3382
d0ec774c
PM
3383/*
3384 * Orchestrate the specified type of RCU barrier, waiting for all
3385 * RCU callbacks of the specified type to complete.
3386 */
037b64ed 3387static void _rcu_barrier(struct rcu_state *rsp)
d0ec774c 3388{
b1420f1c 3389 int cpu;
b1420f1c 3390 struct rcu_data *rdp;
cf3a9c48
PM
3391 unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done);
3392 unsigned long snap_done;
b1420f1c 3393
a83eff0a 3394 _rcu_barrier_trace(rsp, "Begin", -1, snap);
b1420f1c 3395
e74f4c45 3396 /* Take mutex to serialize concurrent rcu_barrier() requests. */
7be7f0be 3397 mutex_lock(&rsp->barrier_mutex);
b1420f1c 3398
cf3a9c48
PM
3399 /*
3400 * Ensure that all prior references, including to ->n_barrier_done,
3401 * are ordered before the _rcu_barrier() machinery.
3402 */
3403 smp_mb(); /* See above block comment. */
3404
3405 /*
3406 * Recheck ->n_barrier_done to see if others did our work for us.
3407 * This means checking ->n_barrier_done for an even-to-odd-to-even
3408 * transition. The "if" expression below therefore rounds the old
3409 * value up to the next even number and adds two before comparing.
3410 */
458fb381 3411 snap_done = rsp->n_barrier_done;
a83eff0a 3412 _rcu_barrier_trace(rsp, "Check", -1, snap_done);
458fb381
PM
3413
3414 /*
3415 * If the value in snap is odd, we needed to wait for the current
3416 * rcu_barrier() to complete, then wait for the next one, in other
3417 * words, we need the value of snap_done to be three larger than
3418 * the value of snap. On the other hand, if the value in snap is
3419 * even, we only had to wait for the next rcu_barrier() to complete,
3420 * in other words, we need the value of snap_done to be only two
3421 * greater than the value of snap. The "(snap + 3) & ~0x1" computes
3422 * this for us (thank you, Linus!).
3423 */
3424 if (ULONG_CMP_GE(snap_done, (snap + 3) & ~0x1)) {
a83eff0a 3425 _rcu_barrier_trace(rsp, "EarlyExit", -1, snap_done);
cf3a9c48
PM
3426 smp_mb(); /* caller's subsequent code after above check. */
3427 mutex_unlock(&rsp->barrier_mutex);
3428 return;
3429 }
3430
3431 /*
3432 * Increment ->n_barrier_done to avoid duplicate work. Use
3433 * ACCESS_ONCE() to prevent the compiler from speculating
3434 * the increment to precede the early-exit check.
3435 */
a792563b 3436 ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
cf3a9c48 3437 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
a83eff0a 3438 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
cf3a9c48 3439 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
b1420f1c 3440
d0ec774c 3441 /*
b1420f1c
PM
3442 * Initialize the count to one rather than to zero in order to
3443 * avoid a too-soon return to zero in case of a short grace period
1331e7a1
PM
3444 * (or preemption of this task). Exclude CPU-hotplug operations
3445 * to ensure that no offline CPU has callbacks queued.
d0ec774c 3446 */
7db74df8 3447 init_completion(&rsp->barrier_completion);
24ebbca8 3448 atomic_set(&rsp->barrier_cpu_count, 1);
1331e7a1 3449 get_online_cpus();
b1420f1c
PM
3450
3451 /*
1331e7a1
PM
3452 * Force each CPU with callbacks to register a new callback.
3453 * When that callback is invoked, we will know that all of the
3454 * corresponding CPU's preceding callbacks have been invoked.
b1420f1c 3455 */
3fbfbf7a 3456 for_each_possible_cpu(cpu) {
d1e43fa5 3457 if (!cpu_online(cpu) && !rcu_is_nocb_cpu(cpu))
3fbfbf7a 3458 continue;
b1420f1c 3459 rdp = per_cpu_ptr(rsp->rda, cpu);
d1e43fa5 3460 if (rcu_is_nocb_cpu(cpu)) {
d7e29933
PM
3461 if (!rcu_nocb_cpu_needs_barrier(rsp, cpu)) {
3462 _rcu_barrier_trace(rsp, "OfflineNoCB", cpu,
3463 rsp->n_barrier_done);
3464 } else {
3465 _rcu_barrier_trace(rsp, "OnlineNoCB", cpu,
3466 rsp->n_barrier_done);
41050a00 3467 smp_mb__before_atomic();
d7e29933
PM
3468 atomic_inc(&rsp->barrier_cpu_count);
3469 __call_rcu(&rdp->barrier_head,
3470 rcu_barrier_callback, rsp, cpu, 0);
3471 }
3fbfbf7a 3472 } else if (ACCESS_ONCE(rdp->qlen)) {
a83eff0a
PM
3473 _rcu_barrier_trace(rsp, "OnlineQ", cpu,
3474 rsp->n_barrier_done);
037b64ed 3475 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
b1420f1c 3476 } else {
a83eff0a
PM
3477 _rcu_barrier_trace(rsp, "OnlineNQ", cpu,
3478 rsp->n_barrier_done);
b1420f1c
PM
3479 }
3480 }
1331e7a1 3481 put_online_cpus();
b1420f1c
PM
3482
3483 /*
3484 * Now that we have an rcu_barrier_callback() callback on each
3485 * CPU, and thus each counted, remove the initial count.
3486 */
24ebbca8 3487 if (atomic_dec_and_test(&rsp->barrier_cpu_count))
7db74df8 3488 complete(&rsp->barrier_completion);
b1420f1c 3489
cf3a9c48
PM
3490 /* Increment ->n_barrier_done to prevent duplicate work. */
3491 smp_mb(); /* Keep increment after above mechanism. */
a792563b 3492 ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
cf3a9c48 3493 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
a83eff0a 3494 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
cf3a9c48
PM
3495 smp_mb(); /* Keep increment before caller's subsequent code. */
3496
b1420f1c 3497 /* Wait for all rcu_barrier_callback() callbacks to be invoked. */
7db74df8 3498 wait_for_completion(&rsp->barrier_completion);
b1420f1c
PM
3499
3500 /* Other rcu_barrier() invocations can now safely proceed. */
7be7f0be 3501 mutex_unlock(&rsp->barrier_mutex);
d0ec774c 3502}
d0ec774c
PM
3503
3504/**
3505 * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
3506 */
3507void rcu_barrier_bh(void)
3508{
037b64ed 3509 _rcu_barrier(&rcu_bh_state);
d0ec774c
PM
3510}
3511EXPORT_SYMBOL_GPL(rcu_barrier_bh);
3512
3513/**
3514 * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
3515 */
3516void rcu_barrier_sched(void)
3517{
037b64ed 3518 _rcu_barrier(&rcu_sched_state);
d0ec774c
PM
3519}
3520EXPORT_SYMBOL_GPL(rcu_barrier_sched);
3521
64db4cff 3522/*
27569620 3523 * Do boot-time initialization of a CPU's per-CPU RCU data.
64db4cff 3524 */
27569620
PM
3525static void __init
3526rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
64db4cff
PM
3527{
3528 unsigned long flags;
394f99a9 3529 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
27569620
PM
3530 struct rcu_node *rnp = rcu_get_root(rsp);
3531
3532 /* Set up local state, ensuring consistent view of global state. */
1304afb2 3533 raw_spin_lock_irqsave(&rnp->lock, flags);
27569620 3534 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
27569620 3535 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
29e37d81 3536 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
9b2e4f18 3537 WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
27569620 3538 rdp->cpu = cpu;
d4c08f2a 3539 rdp->rsp = rsp;
3fbfbf7a 3540 rcu_boot_init_nocb_percpu_data(rdp);
1304afb2 3541 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27569620
PM
3542}
3543
3544/*
3545 * Initialize a CPU's per-CPU RCU data. Note that only one online or
3546 * offline event can be happening at a given time. Note also that we
3547 * can accept some slop in the rsp->completed access due to the fact
3548 * that this CPU cannot possibly have any RCU callbacks in flight yet.
64db4cff 3549 */
49fb4c62 3550static void
9b67122a 3551rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
64db4cff
PM
3552{
3553 unsigned long flags;
64db4cff 3554 unsigned long mask;
394f99a9 3555 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
64db4cff
PM
3556 struct rcu_node *rnp = rcu_get_root(rsp);
3557
a4fbe35a
PM
3558 /* Exclude new grace periods. */
3559 mutex_lock(&rsp->onoff_mutex);
3560
64db4cff 3561 /* Set up local state, ensuring consistent view of global state. */
1304afb2 3562 raw_spin_lock_irqsave(&rnp->lock, flags);
64db4cff 3563 rdp->beenonline = 1; /* We have now been online. */
37c72e56
PM
3564 rdp->qlen_last_fqs_check = 0;
3565 rdp->n_force_qs_snap = rsp->n_force_qs;
64db4cff 3566 rdp->blimit = blimit;
0d8ee37e 3567 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
29e37d81 3568 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
2333210b 3569 rcu_sysidle_init_percpu_data(rdp->dynticks);
c92b131b
PM
3570 atomic_set(&rdp->dynticks->dynticks,
3571 (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
1304afb2 3572 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
64db4cff 3573
64db4cff
PM
3574 /* Add CPU to rcu_node bitmasks. */
3575 rnp = rdp->mynode;
3576 mask = rdp->grpmask;
3577 do {
3578 /* Exclude any attempts to start a new GP on small systems. */
1304afb2 3579 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
64db4cff
PM
3580 rnp->qsmaskinit |= mask;
3581 mask = rnp->grpmask;
d09b62df 3582 if (rnp == rdp->mynode) {
06ae115a
PM
3583 /*
3584 * If there is a grace period in progress, we will
3585 * set up to wait for it next time we run the
3586 * RCU core code.
3587 */
3588 rdp->gpnum = rnp->completed;
d09b62df 3589 rdp->completed = rnp->completed;
06ae115a 3590 rdp->passed_quiesce = 0;
5cd37193 3591 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
06ae115a 3592 rdp->qs_pending = 0;
f7f7bac9 3593 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl"));
d09b62df 3594 }
1304afb2 3595 raw_spin_unlock(&rnp->lock); /* irqs already disabled. */
64db4cff
PM
3596 rnp = rnp->parent;
3597 } while (rnp != NULL && !(rnp->qsmaskinit & mask));
a4fbe35a 3598 local_irq_restore(flags);
64db4cff 3599
a4fbe35a 3600 mutex_unlock(&rsp->onoff_mutex);
64db4cff
PM
3601}
3602
49fb4c62 3603static void rcu_prepare_cpu(int cpu)
64db4cff 3604{
6ce75a23
PM
3605 struct rcu_state *rsp;
3606
3607 for_each_rcu_flavor(rsp)
9b67122a 3608 rcu_init_percpu_data(cpu, rsp);
64db4cff
PM
3609}
3610
3611/*
f41d911f 3612 * Handle CPU online/offline notification events.
64db4cff 3613 */
49fb4c62 3614static int rcu_cpu_notify(struct notifier_block *self,
9f680ab4 3615 unsigned long action, void *hcpu)
64db4cff
PM
3616{
3617 long cpu = (long)hcpu;
e534165b 3618 struct rcu_data *rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
a26ac245 3619 struct rcu_node *rnp = rdp->mynode;
6ce75a23 3620 struct rcu_state *rsp;
64db4cff 3621
f7f7bac9 3622 trace_rcu_utilization(TPS("Start CPU hotplug"));
64db4cff
PM
3623 switch (action) {
3624 case CPU_UP_PREPARE:
3625 case CPU_UP_PREPARE_FROZEN:
d72bce0e
PZ
3626 rcu_prepare_cpu(cpu);
3627 rcu_prepare_kthreads(cpu);
35ce7f29 3628 rcu_spawn_all_nocb_kthreads(cpu);
a26ac245
PM
3629 break;
3630 case CPU_ONLINE:
0f962a5e 3631 case CPU_DOWN_FAILED:
5d01bbd1 3632 rcu_boost_kthread_setaffinity(rnp, -1);
0f962a5e
PM
3633 break;
3634 case CPU_DOWN_PREPARE:
34ed6246 3635 rcu_boost_kthread_setaffinity(rnp, cpu);
64db4cff 3636 break;
d0ec774c
PM
3637 case CPU_DYING:
3638 case CPU_DYING_FROZEN:
6ce75a23
PM
3639 for_each_rcu_flavor(rsp)
3640 rcu_cleanup_dying_cpu(rsp);
d0ec774c 3641 break;
64db4cff
PM
3642 case CPU_DEAD:
3643 case CPU_DEAD_FROZEN:
3644 case CPU_UP_CANCELED:
3645 case CPU_UP_CANCELED_FROZEN:
776d6807 3646 for_each_rcu_flavor(rsp) {
6ce75a23 3647 rcu_cleanup_dead_cpu(cpu, rsp);
776d6807
PM
3648 do_nocb_deferred_wakeup(per_cpu_ptr(rsp->rda, cpu));
3649 }
64db4cff
PM
3650 break;
3651 default:
3652 break;
3653 }
f7f7bac9 3654 trace_rcu_utilization(TPS("End CPU hotplug"));
34ed6246 3655 return NOTIFY_OK;
64db4cff
PM
3656}
3657
d1d74d14
BP
3658static int rcu_pm_notify(struct notifier_block *self,
3659 unsigned long action, void *hcpu)
3660{
3661 switch (action) {
3662 case PM_HIBERNATION_PREPARE:
3663 case PM_SUSPEND_PREPARE:
3664 if (nr_cpu_ids <= 256) /* Expediting bad for large systems. */
3665 rcu_expedited = 1;
3666 break;
3667 case PM_POST_HIBERNATION:
3668 case PM_POST_SUSPEND:
3669 rcu_expedited = 0;
3670 break;
3671 default:
3672 break;
3673 }
3674 return NOTIFY_OK;
3675}
3676
b3dbec76 3677/*
9386c0b7 3678 * Spawn the kthreads that handle each RCU flavor's grace periods.
b3dbec76
PM
3679 */
3680static int __init rcu_spawn_gp_kthread(void)
3681{
3682 unsigned long flags;
a94844b2 3683 int kthread_prio_in = kthread_prio;
b3dbec76
PM
3684 struct rcu_node *rnp;
3685 struct rcu_state *rsp;
a94844b2 3686 struct sched_param sp;
b3dbec76
PM
3687 struct task_struct *t;
3688
a94844b2
PM
3689 /* Force priority into range. */
3690 if (IS_ENABLED(CONFIG_RCU_BOOST) && kthread_prio < 1)
3691 kthread_prio = 1;
3692 else if (kthread_prio < 0)
3693 kthread_prio = 0;
3694 else if (kthread_prio > 99)
3695 kthread_prio = 99;
3696 if (kthread_prio != kthread_prio_in)
3697 pr_alert("rcu_spawn_gp_kthread(): Limited prio to %d from %d\n",
3698 kthread_prio, kthread_prio_in);
3699
9386c0b7 3700 rcu_scheduler_fully_active = 1;
b3dbec76 3701 for_each_rcu_flavor(rsp) {
a94844b2 3702 t = kthread_create(rcu_gp_kthread, rsp, "%s", rsp->name);
b3dbec76
PM
3703 BUG_ON(IS_ERR(t));
3704 rnp = rcu_get_root(rsp);
3705 raw_spin_lock_irqsave(&rnp->lock, flags);
3706 rsp->gp_kthread = t;
a94844b2
PM
3707 if (kthread_prio) {
3708 sp.sched_priority = kthread_prio;
3709 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
3710 }
3711 wake_up_process(t);
b3dbec76
PM
3712 raw_spin_unlock_irqrestore(&rnp->lock, flags);
3713 }
35ce7f29 3714 rcu_spawn_nocb_kthreads();
9386c0b7 3715 rcu_spawn_boost_kthreads();
b3dbec76
PM
3716 return 0;
3717}
3718early_initcall(rcu_spawn_gp_kthread);
3719
bbad9379
PM
3720/*
3721 * This function is invoked towards the end of the scheduler's initialization
3722 * process. Before this is called, the idle task might contain
3723 * RCU read-side critical sections (during which time, this idle
3724 * task is booting the system). After this function is called, the
3725 * idle tasks are prohibited from containing RCU read-side critical
3726 * sections. This function also enables RCU lockdep checking.
3727 */
3728void rcu_scheduler_starting(void)
3729{
3730 WARN_ON(num_online_cpus() != 1);
3731 WARN_ON(nr_context_switches() > 0);
3732 rcu_scheduler_active = 1;
3733}
3734
64db4cff
PM
3735/*
3736 * Compute the per-level fanout, either using the exact fanout specified
3737 * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT.
3738 */
3739#ifdef CONFIG_RCU_FANOUT_EXACT
3740static void __init rcu_init_levelspread(struct rcu_state *rsp)
3741{
3742 int i;
3743
04f34650
PM
3744 rsp->levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
3745 for (i = rcu_num_lvls - 2; i >= 0; i--)
64db4cff
PM
3746 rsp->levelspread[i] = CONFIG_RCU_FANOUT;
3747}
3748#else /* #ifdef CONFIG_RCU_FANOUT_EXACT */
3749static void __init rcu_init_levelspread(struct rcu_state *rsp)
3750{
3751 int ccur;
3752 int cprv;
3753 int i;
3754
4dbd6bb3 3755 cprv = nr_cpu_ids;
f885b7f2 3756 for (i = rcu_num_lvls - 1; i >= 0; i--) {
64db4cff
PM
3757 ccur = rsp->levelcnt[i];
3758 rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
3759 cprv = ccur;
3760 }
3761}
3762#endif /* #else #ifdef CONFIG_RCU_FANOUT_EXACT */
3763
3764/*
3765 * Helper function for rcu_init() that initializes one rcu_state structure.
3766 */
394f99a9
LJ
3767static void __init rcu_init_one(struct rcu_state *rsp,
3768 struct rcu_data __percpu *rda)
64db4cff 3769{
b4426b49
FF
3770 static const char * const buf[] = {
3771 "rcu_node_0",
3772 "rcu_node_1",
3773 "rcu_node_2",
3774 "rcu_node_3" }; /* Match MAX_RCU_LVLS */
3775 static const char * const fqs[] = {
3776 "rcu_node_fqs_0",
3777 "rcu_node_fqs_1",
3778 "rcu_node_fqs_2",
3779 "rcu_node_fqs_3" }; /* Match MAX_RCU_LVLS */
4a81e832 3780 static u8 fl_mask = 0x1;
64db4cff
PM
3781 int cpustride = 1;
3782 int i;
3783 int j;
3784 struct rcu_node *rnp;
3785
b6407e86
PM
3786 BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */
3787
4930521a
PM
3788 /* Silence gcc 4.8 warning about array index out of range. */
3789 if (rcu_num_lvls > RCU_NUM_LVLS)
3790 panic("rcu_init_one: rcu_num_lvls overflow");
3791
64db4cff
PM
3792 /* Initialize the level-tracking arrays. */
3793
f885b7f2
PM
3794 for (i = 0; i < rcu_num_lvls; i++)
3795 rsp->levelcnt[i] = num_rcu_lvl[i];
3796 for (i = 1; i < rcu_num_lvls; i++)
64db4cff
PM
3797 rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
3798 rcu_init_levelspread(rsp);
4a81e832
PM
3799 rsp->flavor_mask = fl_mask;
3800 fl_mask <<= 1;
64db4cff
PM
3801
3802 /* Initialize the elements themselves, starting from the leaves. */
3803
f885b7f2 3804 for (i = rcu_num_lvls - 1; i >= 0; i--) {
64db4cff
PM
3805 cpustride *= rsp->levelspread[i];
3806 rnp = rsp->level[i];
3807 for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
1304afb2 3808 raw_spin_lock_init(&rnp->lock);
b6407e86
PM
3809 lockdep_set_class_and_name(&rnp->lock,
3810 &rcu_node_class[i], buf[i]);
394f2769
PM
3811 raw_spin_lock_init(&rnp->fqslock);
3812 lockdep_set_class_and_name(&rnp->fqslock,
3813 &rcu_fqs_class[i], fqs[i]);
25d30cf4
PM
3814 rnp->gpnum = rsp->gpnum;
3815 rnp->completed = rsp->completed;
64db4cff
PM
3816 rnp->qsmask = 0;
3817 rnp->qsmaskinit = 0;
3818 rnp->grplo = j * cpustride;
3819 rnp->grphi = (j + 1) * cpustride - 1;
595f3900
HS
3820 if (rnp->grphi >= nr_cpu_ids)
3821 rnp->grphi = nr_cpu_ids - 1;
64db4cff
PM
3822 if (i == 0) {
3823 rnp->grpnum = 0;
3824 rnp->grpmask = 0;
3825 rnp->parent = NULL;
3826 } else {
3827 rnp->grpnum = j % rsp->levelspread[i - 1];
3828 rnp->grpmask = 1UL << rnp->grpnum;
3829 rnp->parent = rsp->level[i - 1] +
3830 j / rsp->levelspread[i - 1];
3831 }
3832 rnp->level = i;
12f5f524 3833 INIT_LIST_HEAD(&rnp->blkd_tasks);
dae6e64d 3834 rcu_init_one_nocb(rnp);
64db4cff
PM
3835 }
3836 }
0c34029a 3837
394f99a9 3838 rsp->rda = rda;
b3dbec76 3839 init_waitqueue_head(&rsp->gp_wq);
f885b7f2 3840 rnp = rsp->level[rcu_num_lvls - 1];
0c34029a 3841 for_each_possible_cpu(i) {
4a90a068 3842 while (i > rnp->grphi)
0c34029a 3843 rnp++;
394f99a9 3844 per_cpu_ptr(rsp->rda, i)->mynode = rnp;
0c34029a
LJ
3845 rcu_boot_init_percpu_data(i, rsp);
3846 }
6ce75a23 3847 list_add(&rsp->flavors, &rcu_struct_flavors);
64db4cff
PM
3848}
3849
f885b7f2
PM
3850/*
3851 * Compute the rcu_node tree geometry from kernel parameters. This cannot
4102adab 3852 * replace the definitions in tree.h because those are needed to size
f885b7f2
PM
3853 * the ->node array in the rcu_state structure.
3854 */
3855static void __init rcu_init_geometry(void)
3856{
026ad283 3857 ulong d;
f885b7f2
PM
3858 int i;
3859 int j;
cca6f393 3860 int n = nr_cpu_ids;
f885b7f2
PM
3861 int rcu_capacity[MAX_RCU_LVLS + 1];
3862
026ad283
PM
3863 /*
3864 * Initialize any unspecified boot parameters.
3865 * The default values of jiffies_till_first_fqs and
3866 * jiffies_till_next_fqs are set to the RCU_JIFFIES_TILL_FORCE_QS
3867 * value, which is a function of HZ, then adding one for each
3868 * RCU_JIFFIES_FQS_DIV CPUs that might be on the system.
3869 */
3870 d = RCU_JIFFIES_TILL_FORCE_QS + nr_cpu_ids / RCU_JIFFIES_FQS_DIV;
3871 if (jiffies_till_first_fqs == ULONG_MAX)
3872 jiffies_till_first_fqs = d;
3873 if (jiffies_till_next_fqs == ULONG_MAX)
3874 jiffies_till_next_fqs = d;
3875
f885b7f2 3876 /* If the compile-time values are accurate, just leave. */
b17c7035
PM
3877 if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF &&
3878 nr_cpu_ids == NR_CPUS)
f885b7f2 3879 return;
39479098
PM
3880 pr_info("RCU: Adjusting geometry for rcu_fanout_leaf=%d, nr_cpu_ids=%d\n",
3881 rcu_fanout_leaf, nr_cpu_ids);
f885b7f2
PM
3882
3883 /*
3884 * Compute number of nodes that can be handled an rcu_node tree
3885 * with the given number of levels. Setting rcu_capacity[0] makes
3886 * some of the arithmetic easier.
3887 */
3888 rcu_capacity[0] = 1;
3889 rcu_capacity[1] = rcu_fanout_leaf;
3890 for (i = 2; i <= MAX_RCU_LVLS; i++)
3891 rcu_capacity[i] = rcu_capacity[i - 1] * CONFIG_RCU_FANOUT;
3892
3893 /*
3894 * The boot-time rcu_fanout_leaf parameter is only permitted
3895 * to increase the leaf-level fanout, not decrease it. Of course,
3896 * the leaf-level fanout cannot exceed the number of bits in
3897 * the rcu_node masks. Finally, the tree must be able to accommodate
3898 * the configured number of CPUs. Complain and fall back to the
3899 * compile-time values if these limits are exceeded.
3900 */
3901 if (rcu_fanout_leaf < CONFIG_RCU_FANOUT_LEAF ||
3902 rcu_fanout_leaf > sizeof(unsigned long) * 8 ||
3903 n > rcu_capacity[MAX_RCU_LVLS]) {
3904 WARN_ON(1);
3905 return;
3906 }
3907
3908 /* Calculate the number of rcu_nodes at each level of the tree. */
3909 for (i = 1; i <= MAX_RCU_LVLS; i++)
3910 if (n <= rcu_capacity[i]) {
3911 for (j = 0; j <= i; j++)
3912 num_rcu_lvl[j] =
3913 DIV_ROUND_UP(n, rcu_capacity[i - j]);
3914 rcu_num_lvls = i;
3915 for (j = i + 1; j <= MAX_RCU_LVLS; j++)
3916 num_rcu_lvl[j] = 0;
3917 break;
3918 }
3919
3920 /* Calculate the total number of rcu_node structures. */
3921 rcu_num_nodes = 0;
3922 for (i = 0; i <= MAX_RCU_LVLS; i++)
3923 rcu_num_nodes += num_rcu_lvl[i];
3924 rcu_num_nodes -= n;
3925}
3926
9f680ab4 3927void __init rcu_init(void)
64db4cff 3928{
017c4261 3929 int cpu;
9f680ab4 3930
f41d911f 3931 rcu_bootup_announce();
f885b7f2 3932 rcu_init_geometry();
394f99a9 3933 rcu_init_one(&rcu_bh_state, &rcu_bh_data);
69c8d28c 3934 rcu_init_one(&rcu_sched_state, &rcu_sched_data);
f41d911f 3935 __rcu_init_preempt();
b5b39360 3936 open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
9f680ab4
PM
3937
3938 /*
3939 * We don't need protection against CPU-hotplug here because
3940 * this is called early in boot, before either interrupts
3941 * or the scheduler are operational.
3942 */
3943 cpu_notifier(rcu_cpu_notify, 0);
d1d74d14 3944 pm_notifier(rcu_pm_notify, 0);
017c4261
PM
3945 for_each_online_cpu(cpu)
3946 rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
aa23c6fb
PK
3947
3948 rcu_early_boot_tests();
64db4cff
PM
3949}
3950
4102adab 3951#include "tree_plugin.h"
This page took 0.642201 seconds and 5 git commands to generate.