blob: c624415f838605f5706b31822b8913ff79fa0a98 [file] [log] [blame]
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001/*
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
Paul E. McKenney87de1cf2013-12-03 10:02:52 -080015 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010017 *
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 -
Paul E. McKenneya71fca52009-09-18 10:28:19 -070028 * Documentation/RCU
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010029 */
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>
Ingo Molnarc1dc0b92009-08-02 11:28:21 +020038#include <linux/nmi.h>
Paul E. McKenney8826f3b2011-05-11 05:41:41 -070039#include <linux/atomic.h>
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010040#include <linux/bitops.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -040041#include <linux/export.h>
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010042#include <linux/completion.h>
43#include <linux/moduleparam.h>
Paul E. McKenney4102ada2013-10-08 20:23:47 -070044#include <linux/module.h>
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010045#include <linux/percpu.h>
46#include <linux/notifier.h>
47#include <linux/cpu.h>
48#include <linux/mutex.h>
49#include <linux/time.h>
Paul E. McKenneybbad9372010-04-02 16:17:17 -070050#include <linux/kernel_stat.h>
Paul E. McKenneya26ac242011-01-12 14:10:23 -080051#include <linux/wait.h>
52#include <linux/kthread.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070053#include <linux/prefetch.h>
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -080054#include <linux/delay.h>
55#include <linux/stop_machine.h>
Paul E. McKenney661a85d2012-07-07 05:57:03 -070056#include <linux/random.h>
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -040057#include <linux/ftrace_event.h>
Borislav Petkovd1d74d12013-04-22 00:12:42 +020058#include <linux/suspend.h>
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010059
Paul E. McKenney4102ada2013-10-08 20:23:47 -070060#include "tree.h"
Paul E. McKenney29c00b42011-06-17 15:53:19 -070061#include "rcu.h"
Paul E. McKenney9f77da92009-08-22 13:56:45 -070062
Paul E. McKenney4102ada2013-10-08 20:23:47 -070063MODULE_ALIAS("rcutree");
64#ifdef MODULE_PARAM_PREFIX
65#undef MODULE_PARAM_PREFIX
66#endif
67#define MODULE_PARAM_PREFIX "rcutree."
68
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010069/* Data structures. */
70
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -070071static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
Paul E. McKenney394f2762012-06-26 17:00:35 -070072static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS];
Peter Zijlstra88b91c72009-10-26 10:24:31 -070073
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -040074/*
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 */
Steven Rostedt (Red Hat)a41bfeb2013-07-12 17:00:28 -040082#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -040083static char sname##_varname[] = #sname; \
84static const char *tp_##sname##_varname __used __tracepoint_string = sname##_varname; \
Steven Rostedt (Red Hat)a41bfeb2013-07-12 17:00:28 -040085struct rcu_state sname##_state = { \
Paul E. McKenney6c90cc72012-05-28 19:41:41 -070086 .level = { &sname##_state.node[0] }, \
Paul E. McKenney037b64e2012-05-28 23:26:01 -070087 .call = cr, \
Paul E. McKenneyaf446b72011-09-10 21:54:08 -070088 .fqs_state = RCU_GP_IDLE, \
Paul E. McKenney42c35332012-09-28 10:49:58 -070089 .gpnum = 0UL - 300UL, \
90 .completed = 0UL - 300UL, \
Paul E. McKenney7b2e6012012-10-08 10:54:03 -070091 .orphan_lock = __RAW_SPIN_LOCK_UNLOCKED(&sname##_state.orphan_lock), \
Paul E. McKenney6c90cc72012-05-28 19:41:41 -070092 .orphan_nxttail = &sname##_state.orphan_nxtlist, \
93 .orphan_donetail = &sname##_state.orphan_donelist, \
Paul E. McKenney7be7f0b2012-05-29 05:18:53 -070094 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \
Paul E. McKenneya4fbe352012-10-07 08:36:12 -070095 .onoff_mutex = __MUTEX_INITIALIZER(sname##_state.onoff_mutex), \
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -040096 .name = sname##_varname, \
Paul E. McKenneya4889852012-12-03 08:16:28 -080097 .abbr = sabbr, \
Steven Rostedt (Red Hat)a41bfeb2013-07-12 17:00:28 -040098}; \
99DEFINE_PER_CPU(struct rcu_data, sname##_data)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100100
Steven Rostedt (Red Hat)a41bfeb2013-07-12 17:00:28 -0400101RCU_STATE_INITIALIZER(rcu_sched, 's', call_rcu_sched);
102RCU_STATE_INITIALIZER(rcu_bh, 'b', call_rcu_bh);
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100103
Paul E. McKenney27f4d282011-02-07 12:47:15 -0800104static struct rcu_state *rcu_state;
Paul E. McKenney6ce75a22012-06-12 11:01:13 -0700105LIST_HEAD(rcu_struct_flavors);
Paul E. McKenney27f4d282011-02-07 12:47:15 -0800106
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -0700107/* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */
108static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF;
Paul E. McKenney7e5c2df2012-07-01 15:42:33 -0700109module_param(rcu_fanout_leaf, int, 0444);
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -0700110int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
111static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */
112 NUM_RCU_LVL_0,
113 NUM_RCU_LVL_1,
114 NUM_RCU_LVL_2,
115 NUM_RCU_LVL_3,
116 NUM_RCU_LVL_4,
117};
118int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
119
Paul E. McKenneyb0d30412011-07-10 15:57:35 -0700120/*
121 * The rcu_scheduler_active variable transitions from zero to one just
122 * before the first task is spawned. So when this variable is zero, RCU
123 * can assume that there is but one task, allowing RCU to (for example)
Cody P Schaferb44f6652013-01-04 12:59:40 -0500124 * optimize synchronize_sched() to a simple barrier(). When this variable
Paul E. McKenneyb0d30412011-07-10 15:57:35 -0700125 * is one, RCU must actually do all the hard work required to detect real
126 * grace periods. This variable is also used to suppress boot-time false
127 * positives from lockdep-RCU error checking.
128 */
Paul E. McKenneybbad9372010-04-02 16:17:17 -0700129int rcu_scheduler_active __read_mostly;
130EXPORT_SYMBOL_GPL(rcu_scheduler_active);
131
Paul E. McKenneyb0d30412011-07-10 15:57:35 -0700132/*
133 * The rcu_scheduler_fully_active variable transitions from zero to one
134 * during the early_initcall() processing, which is after the scheduler
135 * is capable of creating new tasks. So RCU processing (for example,
136 * creating tasks for RCU priority boosting) must be delayed until after
137 * rcu_scheduler_fully_active transitions from zero to one. We also
138 * currently delay invocation of any RCU callbacks until after this point.
139 *
140 * It might later prove better for people registering RCU callbacks during
141 * early boot to take responsibility for these callbacks, but one step at
142 * a time.
143 */
144static int rcu_scheduler_fully_active __read_mostly;
145
Paul E. McKenneya46e0892011-06-15 15:47:09 -0700146#ifdef CONFIG_RCU_BOOST
147
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100148/*
Paul E. McKenneya26ac242011-01-12 14:10:23 -0800149 * Control variables for per-CPU and per-rcu_node kthreads. These
150 * handle all flavors of RCU.
151 */
152static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
Paul E. McKenneyd71df902011-03-29 17:48:28 -0700153DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
Paul E. McKenney5ece5ba2011-04-22 18:08:51 -0700154DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
Paul E. McKenneyd71df902011-03-29 17:48:28 -0700155DEFINE_PER_CPU(char, rcu_cpu_has_work);
Paul E. McKenneya26ac242011-01-12 14:10:23 -0800156
Paul E. McKenneya46e0892011-06-15 15:47:09 -0700157#endif /* #ifdef CONFIG_RCU_BOOST */
158
Thomas Gleixner5d01bbd2012-07-16 10:42:35 +0000159static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
Paul E. McKenneya46e0892011-06-15 15:47:09 -0700160static void invoke_rcu_core(void);
161static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
Paul E. McKenneya26ac242011-01-12 14:10:23 -0800162
Paul E. McKenneya26ac242011-01-12 14:10:23 -0800163/*
Paul E. McKenney4a298652011-04-03 21:33:51 -0700164 * 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
175/*
Paul E. McKenneyfc2219d42009-09-23 09:50:41 -0700176 * 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
185/*
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700186 * Note a quiescent state. Because we do not need to know
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100187 * how many quiescent states passed, just if there was at least
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700188 * one since the start of the grace period, this just sets a flag.
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700189 * The caller must have disabled preemption.
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100190 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700191void rcu_sched_qs(int cpu)
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100192{
Paul E. McKenney25502a62010-04-01 17:37:01 -0700193 struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700194
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700195 if (rdp->passed_quiesce == 0)
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400196 trace_rcu_grace_period(TPS("rcu_sched"), rdp->gpnum, TPS("cpuqs"));
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700197 rdp->passed_quiesce = 1;
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100198}
199
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700200void rcu_bh_qs(int cpu)
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100201{
Paul E. McKenney25502a62010-04-01 17:37:01 -0700202 struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700203
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700204 if (rdp->passed_quiesce == 0)
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400205 trace_rcu_grace_period(TPS("rcu_bh"), rdp->gpnum, TPS("cpuqs"));
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700206 rdp->passed_quiesce = 1;
Ingo Molnarb1f77b02009-03-13 03:20:49 +0100207}
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100208
Paul E. McKenney25502a62010-04-01 17:37:01 -0700209/*
210 * Note a context switch. This is a quiescent state for RCU-sched,
211 * and requires special handling for preemptible RCU.
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -0700212 * The caller must have disabled preemption.
Paul E. McKenney25502a62010-04-01 17:37:01 -0700213 */
214void rcu_note_context_switch(int cpu)
215{
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400216 trace_rcu_utilization(TPS("Start context switch"));
Paul E. McKenney25502a62010-04-01 17:37:01 -0700217 rcu_sched_qs(cpu);
Paul E. McKenneycba6d0d2012-07-02 07:08:42 -0700218 rcu_preempt_note_context_switch(cpu);
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400219 trace_rcu_utilization(TPS("End context switch"));
Paul E. McKenney25502a62010-04-01 17:37:01 -0700220}
Gleb Natapov29ce8312011-05-04 16:31:03 +0300221EXPORT_SYMBOL_GPL(rcu_note_context_switch);
Paul E. McKenney25502a62010-04-01 17:37:01 -0700222
Paul E. McKenney01896f72013-08-18 12:14:32 -0700223static DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
Paul E. McKenney29e37d82011-11-17 16:55:56 -0800224 .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE,
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700225 .dynticks = ATOMIC_INIT(1),
Paul E. McKenney23332102013-06-21 12:34:33 -0700226#ifdef CONFIG_NO_HZ_FULL_SYSIDLE
227 .dynticks_idle_nesting = DYNTICK_TASK_NEST_VALUE,
228 .dynticks_idle = ATOMIC_INIT(1),
229#endif /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
Paul E. McKenney90a4d2c2009-01-04 11:41:11 -0800230};
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100231
Eric Dumazet878d7432012-10-18 04:55:36 -0700232static long blimit = 10; /* Maximum callbacks per rcu_do_batch. */
233static long qhimark = 10000; /* If this many pending, ignore blimit. */
234static long qlowmark = 100; /* Once only this many pending, use blimit. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100235
Eric Dumazet878d7432012-10-18 04:55:36 -0700236module_param(blimit, long, 0444);
237module_param(qhimark, long, 0444);
238module_param(qlowmark, long, 0444);
Paul E. McKenney3d76c082009-09-28 07:46:32 -0700239
Paul E. McKenney026ad282013-04-03 22:14:11 -0700240static ulong jiffies_till_first_fqs = ULONG_MAX;
241static ulong jiffies_till_next_fqs = ULONG_MAX;
Paul E. McKenneyd40011f2012-06-26 20:45:57 -0700242
243module_param(jiffies_till_first_fqs, ulong, 0644);
244module_param(jiffies_till_next_fqs, ulong, 0644);
245
Paul E. McKenney910ee452012-12-31 02:24:21 -0800246static void rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
247 struct rcu_data *rdp);
Paul E. McKenney217af2a2013-06-21 15:39:06 -0700248static void force_qs_rnp(struct rcu_state *rsp,
249 int (*f)(struct rcu_data *rsp, bool *isidle,
250 unsigned long *maxj),
251 bool *isidle, unsigned long *maxj);
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700252static void force_quiescent_state(struct rcu_state *rsp);
Paul E. McKenneya1572292009-08-22 13:56:51 -0700253static int rcu_pending(int cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100254
255/*
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700256 * Return the number of RCU-sched batches processed thus far for debug & stats.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100257 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700258long rcu_batches_completed_sched(void)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100259{
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700260 return rcu_sched_state.completed;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100261}
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700262EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100263
264/*
265 * Return the number of RCU BH batches processed thus far for debug & stats.
266 */
267long rcu_batches_completed_bh(void)
268{
269 return rcu_bh_state.completed;
270}
271EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
272
273/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800274 * Force a quiescent state for RCU BH.
275 */
276void rcu_bh_force_quiescent_state(void)
277{
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700278 force_quiescent_state(&rcu_bh_state);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800279}
280EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
281
282/*
Paul E. McKenney4a298652011-04-03 21:33:51 -0700283 * Record the number of times rcutorture tests have been initiated and
284 * terminated. This information allows the debugfs tracing stats to be
285 * correlated to the rcutorture messages, even when the rcutorture module
286 * is being repeatedly loaded and unloaded. In other words, we cannot
287 * store this state in rcutorture itself.
288 */
289void rcutorture_record_test_transition(void)
290{
291 rcutorture_testseq++;
292 rcutorture_vernum = 0;
293}
294EXPORT_SYMBOL_GPL(rcutorture_record_test_transition);
295
296/*
297 * Record the number of writer passes through the current rcutorture test.
298 * This is also used to correlate debugfs tracing stats with the rcutorture
299 * messages.
300 */
301void rcutorture_record_progress(unsigned long vernum)
302{
303 rcutorture_vernum++;
304}
305EXPORT_SYMBOL_GPL(rcutorture_record_progress);
306
307/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800308 * Force a quiescent state for RCU-sched.
309 */
310void rcu_sched_force_quiescent_state(void)
311{
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700312 force_quiescent_state(&rcu_sched_state);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800313}
314EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state);
315
316/*
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100317 * Does the CPU have callbacks ready to be invoked?
318 */
319static int
320cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp)
321{
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -0700322 return &rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL] &&
323 rdp->nxttail[RCU_DONE_TAIL] != NULL;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100324}
325
326/*
Paul E. McKenney365187f2014-03-10 10:55:52 -0700327 * Return the root node of the specified rcu_state structure.
328 */
329static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
330{
331 return &rsp->node[0];
332}
333
334/*
335 * Is there any need for future grace periods?
336 * Interrupts must be disabled. If the caller does not hold the root
337 * rnp_node structure's ->lock, the results are advisory only.
338 */
339static int rcu_future_needs_gp(struct rcu_state *rsp)
340{
341 struct rcu_node *rnp = rcu_get_root(rsp);
342 int idx = (ACCESS_ONCE(rnp->completed) + 1) & 0x1;
343 int *fp = &rnp->need_future_gp[idx];
344
345 return ACCESS_ONCE(*fp);
346}
347
348/*
Paul E. McKenneydc35c892012-12-03 13:52:00 -0800349 * Does the current CPU require a not-yet-started grace period?
350 * The caller must have disabled interrupts to prevent races with
351 * normal callback registry.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100352 */
353static int
354cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
355{
Paul E. McKenneydc35c892012-12-03 13:52:00 -0800356 int i;
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -0700357
Paul E. McKenneydc35c892012-12-03 13:52:00 -0800358 if (rcu_gp_in_progress(rsp))
359 return 0; /* No, a grace period is already in progress. */
Paul E. McKenney365187f2014-03-10 10:55:52 -0700360 if (rcu_future_needs_gp(rsp))
Paul E. McKenney34ed62462013-01-07 13:37:42 -0800361 return 1; /* Yes, a no-CBs CPU needs one. */
Paul E. McKenneydc35c892012-12-03 13:52:00 -0800362 if (!rdp->nxttail[RCU_NEXT_TAIL])
363 return 0; /* No, this is a no-CBs (or offline) CPU. */
364 if (*rdp->nxttail[RCU_NEXT_READY_TAIL])
365 return 1; /* Yes, this CPU has newly registered callbacks. */
366 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++)
367 if (rdp->nxttail[i - 1] != rdp->nxttail[i] &&
368 ULONG_CMP_LT(ACCESS_ONCE(rsp->completed),
369 rdp->nxtcompleted[i]))
370 return 1; /* Yes, CBs for future grace period. */
371 return 0; /* No grace period needed. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100372}
373
374/*
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700375 * rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100376 *
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700377 * If the new value of the ->dynticks_nesting counter now is zero,
378 * we really have entered idle, and must do the appropriate accounting.
379 * The caller must have disabled interrupts.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100380 */
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700381static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
382 bool user)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100383{
Paul E. McKenney96d3fd02013-10-04 14:33:34 -0700384 struct rcu_state *rsp;
385 struct rcu_data *rdp;
386
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400387 trace_rcu_dyntick(TPS("Start"), oldval, rdtp->dynticks_nesting);
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700388 if (!user && !is_idle_task(current)) {
Paul E. McKenney289828e2013-08-31 19:23:29 -0700389 struct task_struct *idle __maybe_unused =
390 idle_task(smp_processor_id());
Paul E. McKenney0989cb42011-11-01 08:57:21 -0700391
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400392 trace_rcu_dyntick(TPS("Error on entry: not idle task"), oldval, 0);
Paul E. McKenneybf1304e2012-05-09 15:55:39 -0700393 ftrace_dump(DUMP_ORIG);
Paul E. McKenney0989cb42011-11-01 08:57:21 -0700394 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
395 current->pid, current->comm,
396 idle->pid, idle->comm); /* must be idle task! */
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700397 }
Paul E. McKenney96d3fd02013-10-04 14:33:34 -0700398 for_each_rcu_flavor(rsp) {
399 rdp = this_cpu_ptr(rsp->rda);
400 do_nocb_deferred_wakeup(rdp);
401 }
Paul E. McKenneyaea1b352011-11-02 06:54:54 -0700402 rcu_prepare_for_idle(smp_processor_id());
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700403 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
404 smp_mb__before_atomic_inc(); /* See above. */
405 atomic_inc(&rdtp->dynticks);
406 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
407 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
Paul E. McKenneyc44e2cd2012-01-12 13:08:18 -0800408
409 /*
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700410 * It is illegal to enter an extended quiescent state while
Paul E. McKenneyc44e2cd2012-01-12 13:08:18 -0800411 * in an RCU read-side critical section.
412 */
413 rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
414 "Illegal idle entry in RCU read-side critical section.");
415 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map),
416 "Illegal idle entry in RCU-bh read-side critical section.");
417 rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map),
418 "Illegal idle entry in RCU-sched read-side critical section.");
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100419}
420
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700421/*
422 * Enter an RCU extended quiescent state, which can be either the
423 * idle loop or adaptive-tickless usermode execution.
424 */
425static void rcu_eqs_enter(bool user)
426{
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700427 long long oldval;
428 struct rcu_dynticks *rdtp;
429
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700430 rdtp = this_cpu_ptr(&rcu_dynticks);
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700431 oldval = rdtp->dynticks_nesting;
432 WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700433 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) {
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700434 rdtp->dynticks_nesting = 0;
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700435 rcu_eqs_enter_common(rdtp, oldval, user);
436 } else {
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700437 rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700438 }
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700439}
440
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700441/**
442 * rcu_idle_enter - inform RCU that current CPU is entering idle
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100443 *
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700444 * Enter idle mode, in other words, -leave- the mode in which RCU
445 * read-side critical sections can occur. (Though RCU read-side
446 * critical sections can occur in irq handlers in idle, a possibility
447 * handled by irq_enter() and irq_exit().)
448 *
449 * We crowbar the ->dynticks_nesting field to zero to allow for
450 * the possibility of usermode upcalls having messed up our count
451 * of interrupt nesting level during the prior busy period.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100452 */
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700453void rcu_idle_enter(void)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100454{
Frederic Weisbeckerc5d900b2012-07-11 20:26:31 +0200455 unsigned long flags;
456
457 local_irq_save(flags);
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700458 rcu_eqs_enter(false);
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700459 rcu_sysidle_enter(this_cpu_ptr(&rcu_dynticks), 0);
Frederic Weisbeckerc5d900b2012-07-11 20:26:31 +0200460 local_irq_restore(flags);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700461}
Paul E. McKenney8a2ecf42012-02-02 15:42:04 -0800462EXPORT_SYMBOL_GPL(rcu_idle_enter);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700463
Frederic Weisbecker2b1d5022012-07-11 20:26:30 +0200464#ifdef CONFIG_RCU_USER_QS
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700465/**
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700466 * rcu_user_enter - inform RCU that we are resuming userspace.
467 *
468 * Enter RCU idle mode right before resuming userspace. No use of RCU
469 * is permitted between this call and rcu_user_exit(). This way the
470 * CPU doesn't need to maintain the tick for RCU maintenance purposes
471 * when the CPU runs in userspace.
472 */
473void rcu_user_enter(void)
474{
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100475 rcu_eqs_enter(1);
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700476}
Frederic Weisbecker2b1d5022012-07-11 20:26:30 +0200477#endif /* CONFIG_RCU_USER_QS */
Frederic Weisbecker19dd15912012-06-04 16:42:35 -0700478
479/**
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700480 * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
481 *
482 * Exit from an interrupt handler, which might possibly result in entering
483 * idle mode, in other words, leaving the mode in which read-side critical
484 * sections can occur.
485 *
486 * This code assumes that the idle loop never does anything that might
487 * result in unbalanced calls to irq_enter() and irq_exit(). If your
488 * architecture violates this assumption, RCU will give you what you
489 * deserve, good and hard. But very infrequently and irreproducibly.
490 *
491 * Use things like work queues to work around this limitation.
492 *
493 * You have been warned.
494 */
495void rcu_irq_exit(void)
496{
497 unsigned long flags;
Paul E. McKenney4145fa72011-10-31 15:01:54 -0700498 long long oldval;
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700499 struct rcu_dynticks *rdtp;
500
501 local_irq_save(flags);
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700502 rdtp = this_cpu_ptr(&rcu_dynticks);
Paul E. McKenney4145fa72011-10-31 15:01:54 -0700503 oldval = rdtp->dynticks_nesting;
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700504 rdtp->dynticks_nesting--;
505 WARN_ON_ONCE(rdtp->dynticks_nesting < 0);
Frederic Weisbeckerb6fc6022011-11-28 16:18:56 -0800506 if (rdtp->dynticks_nesting)
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400507 trace_rcu_dyntick(TPS("--="), oldval, rdtp->dynticks_nesting);
Frederic Weisbeckerb6fc6022011-11-28 16:18:56 -0800508 else
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700509 rcu_eqs_enter_common(rdtp, oldval, true);
Paul E. McKenneyeb348b82013-06-21 13:00:57 -0700510 rcu_sysidle_enter(rdtp, 1);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700511 local_irq_restore(flags);
512}
513
514/*
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700515 * rcu_eqs_exit_common - current CPU moving away from extended quiescent state
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700516 *
517 * If the new value of the ->dynticks_nesting counter was previously zero,
518 * we really have exited idle, and must do the appropriate accounting.
519 * The caller must have disabled interrupts.
520 */
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700521static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
522 int user)
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700523{
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700524 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
525 atomic_inc(&rdtp->dynticks);
526 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
527 smp_mb__after_atomic_inc(); /* See above. */
528 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
Paul E. McKenney7cb92492011-11-28 12:28:34 -0800529 rcu_cleanup_after_idle(smp_processor_id());
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400530 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700531 if (!user && !is_idle_task(current)) {
Paul E. McKenney289828e2013-08-31 19:23:29 -0700532 struct task_struct *idle __maybe_unused =
533 idle_task(smp_processor_id());
Paul E. McKenney0989cb42011-11-01 08:57:21 -0700534
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400535 trace_rcu_dyntick(TPS("Error on exit: not idle task"),
Paul E. McKenney4145fa72011-10-31 15:01:54 -0700536 oldval, rdtp->dynticks_nesting);
Paul E. McKenneybf1304e2012-05-09 15:55:39 -0700537 ftrace_dump(DUMP_ORIG);
Paul E. McKenney0989cb42011-11-01 08:57:21 -0700538 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
539 current->pid, current->comm,
540 idle->pid, idle->comm); /* must be idle task! */
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700541 }
542}
543
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700544/*
545 * Exit an RCU extended quiescent state, which can be either the
546 * idle loop or adaptive-tickless usermode execution.
547 */
548static void rcu_eqs_exit(bool user)
549{
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700550 struct rcu_dynticks *rdtp;
551 long long oldval;
552
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700553 rdtp = this_cpu_ptr(&rcu_dynticks);
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700554 oldval = rdtp->dynticks_nesting;
555 WARN_ON_ONCE(oldval < 0);
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700556 if (oldval & DYNTICK_TASK_NEST_MASK) {
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700557 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700558 } else {
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700559 rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
Paul E. McKenney3a5924052013-10-04 18:48:55 -0700560 rcu_eqs_exit_common(rdtp, oldval, user);
561 }
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700562}
563
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700564/**
565 * rcu_idle_exit - inform RCU that current CPU is leaving idle
566 *
567 * Exit idle mode, in other words, -enter- the mode in which RCU
568 * read-side critical sections can occur.
569 *
Paul E. McKenney29e37d82011-11-17 16:55:56 -0800570 * We crowbar the ->dynticks_nesting field to DYNTICK_TASK_NEST to
Paul E. McKenney4145fa72011-10-31 15:01:54 -0700571 * allow for the possibility of usermode upcalls messing up our count
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700572 * of interrupt nesting level during the busy period that is just
573 * now starting.
574 */
575void rcu_idle_exit(void)
576{
Frederic Weisbeckerc5d900b2012-07-11 20:26:31 +0200577 unsigned long flags;
578
579 local_irq_save(flags);
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700580 rcu_eqs_exit(false);
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700581 rcu_sysidle_exit(this_cpu_ptr(&rcu_dynticks), 0);
Frederic Weisbeckerc5d900b2012-07-11 20:26:31 +0200582 local_irq_restore(flags);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700583}
Paul E. McKenney8a2ecf42012-02-02 15:42:04 -0800584EXPORT_SYMBOL_GPL(rcu_idle_exit);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700585
Frederic Weisbecker2b1d5022012-07-11 20:26:30 +0200586#ifdef CONFIG_RCU_USER_QS
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700587/**
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700588 * rcu_user_exit - inform RCU that we are exiting userspace.
589 *
590 * Exit RCU idle mode while entering the kernel because it can
591 * run a RCU read side critical section anytime.
592 */
593void rcu_user_exit(void)
594{
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100595 rcu_eqs_exit(1);
Frederic Weisbeckeradf50912012-06-28 11:20:21 -0700596}
Frederic Weisbecker2b1d5022012-07-11 20:26:30 +0200597#endif /* CONFIG_RCU_USER_QS */
Frederic Weisbecker19dd15912012-06-04 16:42:35 -0700598
599/**
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700600 * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle
601 *
602 * Enter an interrupt handler, which might possibly result in exiting
603 * idle mode, in other words, entering the mode in which read-side critical
604 * sections can occur.
605 *
606 * Note that the Linux kernel is fully capable of entering an interrupt
607 * handler that it never exits, for example when doing upcalls to
608 * user mode! This code assumes that the idle loop never does upcalls to
609 * user mode. If your architecture does do upcalls from the idle loop (or
610 * does anything else that results in unbalanced calls to the irq_enter()
611 * and irq_exit() functions), RCU will give you what you deserve, good
612 * and hard. But very infrequently and irreproducibly.
613 *
614 * Use things like work queues to work around this limitation.
615 *
616 * You have been warned.
617 */
618void rcu_irq_enter(void)
619{
620 unsigned long flags;
621 struct rcu_dynticks *rdtp;
622 long long oldval;
623
624 local_irq_save(flags);
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700625 rdtp = this_cpu_ptr(&rcu_dynticks);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700626 oldval = rdtp->dynticks_nesting;
627 rdtp->dynticks_nesting++;
628 WARN_ON_ONCE(rdtp->dynticks_nesting == 0);
Frederic Weisbeckerb6fc6022011-11-28 16:18:56 -0800629 if (oldval)
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400630 trace_rcu_dyntick(TPS("++="), oldval, rdtp->dynticks_nesting);
Frederic Weisbeckerb6fc6022011-11-28 16:18:56 -0800631 else
Paul E. McKenneycb349ca2012-09-04 17:35:31 -0700632 rcu_eqs_exit_common(rdtp, oldval, true);
Paul E. McKenneyeb348b82013-06-21 13:00:57 -0700633 rcu_sysidle_exit(rdtp, 1);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100634 local_irq_restore(flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100635}
636
637/**
638 * rcu_nmi_enter - inform RCU of entry to NMI context
639 *
640 * If the CPU was idle with dynamic ticks active, and there is no
641 * irq handler running, this updates rdtp->dynticks_nmi to let the
642 * RCU grace-period handling know that the CPU is active.
643 */
644void rcu_nmi_enter(void)
645{
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700646 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100647
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700648 if (rdtp->dynticks_nmi_nesting == 0 &&
649 (atomic_read(&rdtp->dynticks) & 0x1))
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100650 return;
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700651 rdtp->dynticks_nmi_nesting++;
652 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
653 atomic_inc(&rdtp->dynticks);
654 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
655 smp_mb__after_atomic_inc(); /* See above. */
656 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100657}
658
659/**
660 * rcu_nmi_exit - inform RCU of exit from NMI context
661 *
662 * If the CPU was idle with dynamic ticks active, and there is no
663 * irq handler running, this updates rdtp->dynticks_nmi to let the
664 * RCU grace-period handling know that the CPU is no longer active.
665 */
666void rcu_nmi_exit(void)
667{
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700668 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100669
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700670 if (rdtp->dynticks_nmi_nesting == 0 ||
671 --rdtp->dynticks_nmi_nesting != 0)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100672 return;
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700673 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
674 smp_mb__before_atomic_inc(); /* See above. */
675 atomic_inc(&rdtp->dynticks);
676 smp_mb__after_atomic_inc(); /* Force delay to next write. */
677 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100678}
679
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100680/**
Paul E. McKenneycc6783f2013-09-06 17:39:49 -0700681 * __rcu_is_watching - are RCU read-side critical sections safe?
682 *
683 * Return true if RCU is watching the running CPU, which means that
684 * this CPU can safely enter RCU read-side critical sections. Unlike
Paul E. McKenney5c173eb2013-09-13 17:20:11 -0700685 * rcu_is_watching(), the caller of __rcu_is_watching() must have at
Paul E. McKenneycc6783f2013-09-06 17:39:49 -0700686 * least disabled preemption.
687 */
Linus Torvaldsb29c8302013-11-16 12:23:18 -0800688bool notrace __rcu_is_watching(void)
Paul E. McKenneycc6783f2013-09-06 17:39:49 -0700689{
Paul E. McKenney5c173eb2013-09-13 17:20:11 -0700690 return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
Paul E. McKenneycc6783f2013-09-06 17:39:49 -0700691}
692
Paul E. McKenney5c173eb2013-09-13 17:20:11 -0700693/**
694 * rcu_is_watching - see if RCU thinks that the current CPU is idle
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100695 *
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700696 * If the current CPU is in its idle loop and is neither in an interrupt
Paul E. McKenney34240692011-10-03 11:38:52 -0700697 * or NMI handler, return true.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100698 */
Linus Torvaldsb29c8302013-11-16 12:23:18 -0800699bool notrace rcu_is_watching(void)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100700{
Paul E. McKenney34240692011-10-03 11:38:52 -0700701 int ret;
702
703 preempt_disable();
Paul E. McKenney5c173eb2013-09-13 17:20:11 -0700704 ret = __rcu_is_watching();
Paul E. McKenney34240692011-10-03 11:38:52 -0700705 preempt_enable();
706 return ret;
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700707}
Paul E. McKenney5c173eb2013-09-13 17:20:11 -0700708EXPORT_SYMBOL_GPL(rcu_is_watching);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700709
Paul E. McKenney62fde6e2012-05-22 22:10:24 -0700710#if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenneyc0d6d012012-01-23 12:41:26 -0800711
712/*
713 * Is the current CPU online? Disable preemption to avoid false positives
714 * that could otherwise happen due to the current CPU number being sampled,
715 * this task being preempted, its old CPU being taken offline, resuming
716 * on some other CPU, then determining that its old CPU is now offline.
717 * It is OK to use RCU on an offline processor during initial boot, hence
Paul E. McKenney2036d942012-01-30 17:02:47 -0800718 * the check for rcu_scheduler_fully_active. Note also that it is OK
719 * for a CPU coming online to use RCU for one jiffy prior to marking itself
720 * online in the cpu_online_mask. Similarly, it is OK for a CPU going
721 * offline to continue to use RCU for one jiffy after marking itself
722 * offline in the cpu_online_mask. This leniency is necessary given the
723 * non-atomic nature of the online and offline processing, for example,
724 * the fact that a CPU enters the scheduler after completing the CPU_DYING
725 * notifiers.
726 *
727 * This is also why RCU internally marks CPUs online during the
728 * CPU_UP_PREPARE phase and offline during the CPU_DEAD phase.
Paul E. McKenneyc0d6d012012-01-23 12:41:26 -0800729 *
730 * Disable checking if in an NMI handler because we cannot safely report
731 * errors from NMI handlers anyway.
732 */
733bool rcu_lockdep_current_cpu_online(void)
734{
Paul E. McKenney2036d942012-01-30 17:02:47 -0800735 struct rcu_data *rdp;
736 struct rcu_node *rnp;
Paul E. McKenneyc0d6d012012-01-23 12:41:26 -0800737 bool ret;
738
739 if (in_nmi())
Fengguang Wuf6f7ee92013-10-10 11:08:33 -0700740 return true;
Paul E. McKenneyc0d6d012012-01-23 12:41:26 -0800741 preempt_disable();
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700742 rdp = this_cpu_ptr(&rcu_sched_data);
Paul E. McKenney2036d942012-01-30 17:02:47 -0800743 rnp = rdp->mynode;
744 ret = (rdp->grpmask & rnp->qsmaskinit) ||
Paul E. McKenneyc0d6d012012-01-23 12:41:26 -0800745 !rcu_scheduler_fully_active;
746 preempt_enable();
747 return ret;
748}
749EXPORT_SYMBOL_GPL(rcu_lockdep_current_cpu_online);
750
Paul E. McKenney62fde6e2012-05-22 22:10:24 -0700751#endif /* #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700752
753/**
754 * rcu_is_cpu_rrupt_from_idle - see if idle or immediately interrupted from idle
755 *
756 * If the current CPU is idle or running at a first-level (not nested)
757 * interrupt from idle, return true. The caller must have at least
758 * disabled preemption.
759 */
Josh Triplett62e3cb12012-11-20 09:55:26 -0800760static int rcu_is_cpu_rrupt_from_idle(void)
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -0700761{
Christoph Lameterc9d4b0a2013-08-31 13:34:10 -0700762 return __this_cpu_read(rcu_dynticks.dynticks_nesting) <= 1;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100763}
764
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100765/*
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100766 * Snapshot the specified CPU's dynticks counter so that we can later
767 * credit them with an implicit quiescent state. Return 1 if this CPU
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700768 * is in dynticks idle mode, which is an extended quiescent state.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100769 */
Paul E. McKenney217af2a2013-06-21 15:39:06 -0700770static int dyntick_save_progress_counter(struct rcu_data *rdp,
771 bool *isidle, unsigned long *maxj)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100772{
Paul E. McKenney23b5c8f2010-09-07 10:38:22 -0700773 rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
Paul E. McKenney0edd1b12013-06-21 16:37:22 -0700774 rcu_sysidle_check_cpu(rdp, isidle, maxj);
Paul E. McKenneyf0e7c192011-11-23 15:02:05 -0800775 return (rdp->dynticks_snap & 0x1) == 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100776}
777
778/*
Paul E. McKenney6193c762013-09-23 13:57:18 -0700779 * This function really isn't for public consumption, but RCU is special in
780 * that context switches can allow the state machine to make progress.
781 */
782extern void resched_cpu(int cpu);
783
784/*
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100785 * Return true if the specified CPU has passed through a quiescent
786 * state by virtue of being in or having passed through an dynticks
787 * idle state since the last call to dyntick_save_progress_counter()
Paul E. McKenneya82dcc72012-08-01 14:29:20 -0700788 * for this same CPU, or by virtue of having been offline.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100789 */
Paul E. McKenney217af2a2013-06-21 15:39:06 -0700790static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
791 bool *isidle, unsigned long *maxj)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100792{
Paul E. McKenney7eb4f452011-07-30 07:32:48 -0700793 unsigned int curr;
794 unsigned int snap;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100795
Paul E. McKenney7eb4f452011-07-30 07:32:48 -0700796 curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
797 snap = (unsigned int)rdp->dynticks_snap;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100798
799 /*
800 * If the CPU passed through or entered a dynticks idle phase with
801 * no active irq/NMI handlers, then we can safely pretend that the CPU
802 * already acknowledged the request to pass through a quiescent
803 * state. Either way, that CPU cannot possibly be in an RCU
804 * read-side critical section that started before the beginning
805 * of the current RCU grace period.
806 */
Paul E. McKenney7eb4f452011-07-30 07:32:48 -0700807 if ((curr & 0x1) == 0 || UINT_CMP_GE(curr, snap + 2)) {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400808 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100809 rdp->dynticks_fqs++;
810 return 1;
811 }
812
Paul E. McKenneya82dcc72012-08-01 14:29:20 -0700813 /*
814 * Check for the CPU being offline, but only if the grace period
815 * is old enough. We don't need to worry about the CPU changing
816 * state: If we see it offline even once, it has been through a
817 * quiescent state.
818 *
819 * The reason for insisting that the grace period be at least
820 * one jiffy old is that CPUs that are not quite online and that
821 * have just gone offline can still execute RCU read-side critical
822 * sections.
823 */
824 if (ULONG_CMP_GE(rdp->rsp->gp_start + 2, jiffies))
825 return 0; /* Grace period is not old enough. */
826 barrier();
827 if (cpu_is_offline(rdp->cpu)) {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -0400828 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("ofl"));
Paul E. McKenneya82dcc72012-08-01 14:29:20 -0700829 rdp->offline_fqs++;
830 return 1;
831 }
Paul E. McKenney65d798f2013-04-12 16:19:10 -0700832
833 /*
834 * There is a possibility that a CPU in adaptive-ticks state
835 * might run in the kernel with the scheduling-clock tick disabled
836 * for an extended time period. Invoke rcu_kick_nohz_cpu() to
837 * force the CPU to restart the scheduling-clock tick in this
838 * CPU is in this state.
839 */
840 rcu_kick_nohz_cpu(rdp->cpu);
841
Paul E. McKenney6193c762013-09-23 13:57:18 -0700842 /*
843 * Alternatively, the CPU might be running in the kernel
844 * for an extended period of time without a quiescent state.
845 * Attempt to force the CPU through the scheduler to gain the
846 * needed quiescent state, but only if the grace period has gone
847 * on for an uncommonly long time. If there are many stuck CPUs,
848 * we will beat on the first one until it gets unstuck, then move
849 * to the next. Only do this for the primary flavor of RCU.
850 */
851 if (rdp->rsp == rcu_state &&
Paul E. McKenneycb1e78c2013-12-04 18:42:03 -0800852 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
Paul E. McKenney6193c762013-09-23 13:57:18 -0700853 rdp->rsp->jiffies_resched += 5;
854 resched_cpu(rdp->cpu);
855 }
856
Paul E. McKenneya82dcc72012-08-01 14:29:20 -0700857 return 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100858}
859
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100860static void record_gp_stall_check_time(struct rcu_state *rsp)
861{
Paul E. McKenneycb1e78c2013-12-04 18:42:03 -0800862 unsigned long j = jiffies;
Paul E. McKenney6193c762013-09-23 13:57:18 -0700863 unsigned long j1;
Paul E. McKenney26cdfed2013-09-04 10:51:13 -0700864
865 rsp->gp_start = j;
866 smp_wmb(); /* Record start time before stall time. */
Paul E. McKenney6193c762013-09-23 13:57:18 -0700867 j1 = rcu_jiffies_till_stall_check();
Iulia Manda4fc5b752014-03-11 15:22:28 +0200868 ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
Paul E. McKenney6193c762013-09-23 13:57:18 -0700869 rsp->jiffies_resched = j + j1 / 2;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100870}
871
Paul E. McKenneyb637a322012-09-19 16:58:38 -0700872/*
873 * Dump stacks of all tasks running on stalled CPUs. This is a fallback
874 * for architectures that do not implement trigger_all_cpu_backtrace().
875 * The NMI-triggered stack traces are more accurate because they are
876 * printed by the target CPU.
877 */
878static void rcu_dump_cpu_stacks(struct rcu_state *rsp)
879{
880 int cpu;
881 unsigned long flags;
882 struct rcu_node *rnp;
883
884 rcu_for_each_leaf_node(rsp, rnp) {
885 raw_spin_lock_irqsave(&rnp->lock, flags);
886 if (rnp->qsmask != 0) {
887 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
888 if (rnp->qsmask & (1UL << cpu))
889 dump_cpu_task(rnp->grplo + cpu);
890 }
891 raw_spin_unlock_irqrestore(&rnp->lock, flags);
892 }
893}
894
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100895static void print_other_cpu_stall(struct rcu_state *rsp)
896{
897 int cpu;
898 long delta;
899 unsigned long flags;
Paul E. McKenney285fe292012-05-09 08:45:12 -0700900 int ndetected = 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100901 struct rcu_node *rnp = rcu_get_root(rsp);
Paul E. McKenney53bb8572012-09-21 16:35:25 -0700902 long totqlen = 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100903
904 /* Only let one CPU complain about others per time interval. */
905
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800906 raw_spin_lock_irqsave(&rnp->lock, flags);
Iulia Manda4fc5b752014-03-11 15:22:28 +0200907 delta = jiffies - ACCESS_ONCE(rsp->jiffies_stall);
Paul E. McKenneyfc2219d42009-09-23 09:50:41 -0700908 if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800909 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100910 return;
911 }
Iulia Manda4fc5b752014-03-11 15:22:28 +0200912 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800913 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100914
Paul E. McKenney8cdd32a2010-08-09 14:23:03 -0700915 /*
916 * OK, time to rat on our buddy...
917 * See Documentation/RCU/stallwarn.txt for info on how to debug
918 * RCU CPU stall warnings.
919 */
Paul E. McKenneyd7f3e202013-03-18 16:19:52 -0700920 pr_err("INFO: %s detected stalls on CPUs/tasks:",
Paul E. McKenney4300aa62010-04-13 16:18:22 -0700921 rsp->name);
Paul E. McKenneya858af22012-01-16 13:29:10 -0800922 print_cpu_stall_info_begin();
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -0700923 rcu_for_each_leaf_node(rsp, rnp) {
Paul E. McKenney3acd9eb2010-02-22 17:05:03 -0800924 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney9bc8b552011-08-13 13:31:47 -0700925 ndetected += rcu_print_task_stall(rnp);
Paul E. McKenneyc8020a62012-08-10 16:55:59 -0700926 if (rnp->qsmask != 0) {
927 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
928 if (rnp->qsmask & (1UL << cpu)) {
929 print_cpu_stall_info(rsp,
930 rnp->grplo + cpu);
931 ndetected++;
932 }
933 }
Paul E. McKenney3acd9eb2010-02-22 17:05:03 -0800934 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100935 }
Paul E. McKenneya858af22012-01-16 13:29:10 -0800936
937 /*
938 * Now rat on any tasks that got kicked up to the root rcu_node
939 * due to CPU offlining.
940 */
941 rnp = rcu_get_root(rsp);
942 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney285fe292012-05-09 08:45:12 -0700943 ndetected += rcu_print_task_stall(rnp);
Paul E. McKenneya858af22012-01-16 13:29:10 -0800944 raw_spin_unlock_irqrestore(&rnp->lock, flags);
945
946 print_cpu_stall_info_end();
Paul E. McKenney53bb8572012-09-21 16:35:25 -0700947 for_each_possible_cpu(cpu)
948 totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
Paul E. McKenney83ebe632014-03-06 11:09:10 -0800949 pr_cont("(detected by %d, t=%ld jiffies, g=%ld, c=%ld, q=%lu)\n",
Paul E. McKenneyeee05882012-09-21 14:15:05 -0700950 smp_processor_id(), (long)(jiffies - rsp->gp_start),
Paul E. McKenney83ebe632014-03-06 11:09:10 -0800951 (long)rsp->gpnum, (long)rsp->completed, totqlen);
Paul E. McKenney9bc8b552011-08-13 13:31:47 -0700952 if (ndetected == 0)
Paul E. McKenneyd7f3e202013-03-18 16:19:52 -0700953 pr_err("INFO: Stall ended before state dump start\n");
Paul E. McKenney9bc8b552011-08-13 13:31:47 -0700954 else if (!trigger_all_cpu_backtrace())
Paul E. McKenneyb637a322012-09-19 16:58:38 -0700955 rcu_dump_cpu_stacks(rsp);
Ingo Molnarc1dc0b92009-08-02 11:28:21 +0200956
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700957 /* Complain about tasks blocking the grace period. */
Paul E. McKenney1ed509a2010-02-22 17:05:05 -0800958
959 rcu_print_detail_task_stall(rsp);
960
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700961 force_quiescent_state(rsp); /* Kick them all. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100962}
963
Peter Zijlstrab021fe32013-09-17 09:30:55 +0200964/*
965 * This function really isn't for public consumption, but RCU is special in
966 * that context switches can allow the state machine to make progress.
967 */
968extern void resched_cpu(int cpu);
969
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100970static void print_cpu_stall(struct rcu_state *rsp)
971{
Paul E. McKenney53bb8572012-09-21 16:35:25 -0700972 int cpu;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100973 unsigned long flags;
974 struct rcu_node *rnp = rcu_get_root(rsp);
Paul E. McKenney53bb8572012-09-21 16:35:25 -0700975 long totqlen = 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100976
Paul E. McKenney8cdd32a2010-08-09 14:23:03 -0700977 /*
978 * OK, time to rat on ourselves...
979 * See Documentation/RCU/stallwarn.txt for info on how to debug
980 * RCU CPU stall warnings.
981 */
Paul E. McKenneyd7f3e202013-03-18 16:19:52 -0700982 pr_err("INFO: %s self-detected stall on CPU", rsp->name);
Paul E. McKenneya858af22012-01-16 13:29:10 -0800983 print_cpu_stall_info_begin();
984 print_cpu_stall_info(rsp, smp_processor_id());
985 print_cpu_stall_info_end();
Paul E. McKenney53bb8572012-09-21 16:35:25 -0700986 for_each_possible_cpu(cpu)
987 totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
Paul E. McKenney83ebe632014-03-06 11:09:10 -0800988 pr_cont(" (t=%lu jiffies g=%ld c=%ld q=%lu)\n",
989 jiffies - rsp->gp_start,
990 (long)rsp->gpnum, (long)rsp->completed, totqlen);
Paul E. McKenney4627e242011-08-03 03:34:24 -0700991 if (!trigger_all_cpu_backtrace())
992 dump_stack();
Ingo Molnarc1dc0b92009-08-02 11:28:21 +0200993
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800994 raw_spin_lock_irqsave(&rnp->lock, flags);
Iulia Manda4fc5b752014-03-11 15:22:28 +0200995 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
996 ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
Paul E. McKenney6bfc09e2012-10-19 12:49:17 -0700997 3 * rcu_jiffies_till_stall_check() + 3;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800998 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Ingo Molnarc1dc0b92009-08-02 11:28:21 +0200999
Peter Zijlstrab021fe32013-09-17 09:30:55 +02001000 /*
1001 * Attempt to revive the RCU machinery by forcing a context switch.
1002 *
1003 * A context switch would normally allow the RCU state machine to make
1004 * progress and it could be we're stuck in kernel space without context
1005 * switches for an entirely unreasonable amount of time.
1006 */
1007 resched_cpu(smp_processor_id());
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001008}
1009
1010static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
1011{
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001012 unsigned long completed;
1013 unsigned long gpnum;
1014 unsigned long gps;
Paul E. McKenneybad6e132011-05-02 23:40:04 -07001015 unsigned long j;
1016 unsigned long js;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001017 struct rcu_node *rnp;
1018
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001019 if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp))
Paul E. McKenneyc68de202010-04-15 10:12:40 -07001020 return;
Paul E. McKenneycb1e78c2013-12-04 18:42:03 -08001021 j = jiffies;
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001022
1023 /*
1024 * Lots of memory barriers to reject false positives.
1025 *
1026 * The idea is to pick up rsp->gpnum, then rsp->jiffies_stall,
1027 * then rsp->gp_start, and finally rsp->completed. These values
1028 * are updated in the opposite order with memory barriers (or
1029 * equivalent) during grace-period initialization and cleanup.
1030 * Now, a false positive can occur if we get an new value of
1031 * rsp->gp_start and a old value of rsp->jiffies_stall. But given
1032 * the memory barriers, the only way that this can happen is if one
1033 * grace period ends and another starts between these two fetches.
1034 * Detect this by comparing rsp->completed with the previous fetch
1035 * from rsp->gpnum.
1036 *
1037 * Given this check, comparisons of jiffies, rsp->jiffies_stall,
1038 * and rsp->gp_start suffice to forestall false positives.
1039 */
1040 gpnum = ACCESS_ONCE(rsp->gpnum);
1041 smp_rmb(); /* Pick up ->gpnum first... */
Paul E. McKenneybad6e132011-05-02 23:40:04 -07001042 js = ACCESS_ONCE(rsp->jiffies_stall);
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001043 smp_rmb(); /* ...then ->jiffies_stall before the rest... */
1044 gps = ACCESS_ONCE(rsp->gp_start);
1045 smp_rmb(); /* ...and finally ->gp_start before ->completed. */
1046 completed = ACCESS_ONCE(rsp->completed);
1047 if (ULONG_CMP_GE(completed, gpnum) ||
1048 ULONG_CMP_LT(j, js) ||
1049 ULONG_CMP_GE(gps, js))
1050 return; /* No stall or GP completed since entering function. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001051 rnp = rdp->mynode;
Paul E. McKenneyc96ea7c2012-08-13 11:17:06 -07001052 if (rcu_gp_in_progress(rsp) &&
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001053 (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask)) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001054
1055 /* We haven't checked in, so go dump stack. */
1056 print_cpu_stall(rsp);
1057
Paul E. McKenneybad6e132011-05-02 23:40:04 -07001058 } else if (rcu_gp_in_progress(rsp) &&
1059 ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001060
Paul E. McKenneybad6e132011-05-02 23:40:04 -07001061 /* They had a few time units to dump stack, so complain. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001062 print_other_cpu_stall(rsp);
1063 }
1064}
1065
Paul E. McKenney53d84e02010-08-10 14:28:53 -07001066/**
1067 * rcu_cpu_stall_reset - prevent further stall warnings in current grace period
1068 *
1069 * Set the stall-warning timeout way off into the future, thus preventing
1070 * any RCU CPU stall-warning messages from appearing in the current set of
1071 * RCU grace periods.
1072 *
1073 * The caller must disable hard irqs.
1074 */
1075void rcu_cpu_stall_reset(void)
1076{
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07001077 struct rcu_state *rsp;
1078
1079 for_each_rcu_flavor(rsp)
Iulia Manda4fc5b752014-03-11 15:22:28 +02001080 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
Paul E. McKenney53d84e02010-08-10 14:28:53 -07001081}
1082
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001083/*
Paul E. McKenney3f5d3ea2012-05-09 15:39:56 -07001084 * Initialize the specified rcu_data structure's callback list to empty.
1085 */
1086static void init_callback_list(struct rcu_data *rdp)
1087{
1088 int i;
1089
Paul E. McKenney34ed62462013-01-07 13:37:42 -08001090 if (init_nocb_callback_list(rdp))
1091 return;
Paul E. McKenney3f5d3ea2012-05-09 15:39:56 -07001092 rdp->nxtlist = NULL;
1093 for (i = 0; i < RCU_NEXT_SIZE; i++)
1094 rdp->nxttail[i] = &rdp->nxtlist;
1095}
1096
1097/*
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001098 * Determine the value that ->completed will have at the end of the
1099 * next subsequent grace period. This is used to tag callbacks so that
1100 * a CPU can invoke callbacks in a timely fashion even if that CPU has
1101 * been dyntick-idle for an extended period with callbacks under the
1102 * influence of RCU_FAST_NO_HZ.
1103 *
1104 * The caller must hold rnp->lock with interrupts disabled.
1105 */
1106static unsigned long rcu_cbs_completed(struct rcu_state *rsp,
1107 struct rcu_node *rnp)
1108{
1109 /*
1110 * If RCU is idle, we just wait for the next grace period.
1111 * But we can only be sure that RCU is idle if we are looking
1112 * at the root rcu_node structure -- otherwise, a new grace
1113 * period might have started, but just not yet gotten around
1114 * to initializing the current non-root rcu_node structure.
1115 */
1116 if (rcu_get_root(rsp) == rnp && rnp->gpnum == rnp->completed)
1117 return rnp->completed + 1;
1118
1119 /*
1120 * Otherwise, wait for a possible partial grace period and
1121 * then the subsequent full grace period.
1122 */
1123 return rnp->completed + 2;
1124}
1125
1126/*
Paul E. McKenney0446be42012-12-30 15:21:01 -08001127 * Trace-event helper function for rcu_start_future_gp() and
1128 * rcu_nocb_wait_gp().
1129 */
1130static void trace_rcu_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001131 unsigned long c, const char *s)
Paul E. McKenney0446be42012-12-30 15:21:01 -08001132{
1133 trace_rcu_future_grace_period(rdp->rsp->name, rnp->gpnum,
1134 rnp->completed, c, rnp->level,
1135 rnp->grplo, rnp->grphi, s);
1136}
1137
1138/*
1139 * Start some future grace period, as needed to handle newly arrived
1140 * callbacks. The required future grace periods are recorded in each
1141 * rcu_node structure's ->need_future_gp field.
1142 *
1143 * The caller must hold the specified rcu_node structure's ->lock.
1144 */
1145static unsigned long __maybe_unused
1146rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp)
1147{
1148 unsigned long c;
1149 int i;
1150 struct rcu_node *rnp_root = rcu_get_root(rdp->rsp);
1151
1152 /*
1153 * Pick up grace-period number for new callbacks. If this
1154 * grace period is already marked as needed, return to the caller.
1155 */
1156 c = rcu_cbs_completed(rdp->rsp, rnp);
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001157 trace_rcu_future_gp(rnp, rdp, c, TPS("Startleaf"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001158 if (rnp->need_future_gp[c & 0x1]) {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001159 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartleaf"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001160 return c;
1161 }
1162
1163 /*
1164 * If either this rcu_node structure or the root rcu_node structure
1165 * believe that a grace period is in progress, then we must wait
1166 * for the one following, which is in "c". Because our request
1167 * will be noticed at the end of the current grace period, we don't
1168 * need to explicitly start one.
1169 */
1170 if (rnp->gpnum != rnp->completed ||
1171 ACCESS_ONCE(rnp->gpnum) != ACCESS_ONCE(rnp->completed)) {
1172 rnp->need_future_gp[c & 0x1]++;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001173 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001174 return c;
1175 }
1176
1177 /*
1178 * There might be no grace period in progress. If we don't already
1179 * hold it, acquire the root rcu_node structure's lock in order to
1180 * start one (if needed).
1181 */
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001182 if (rnp != rnp_root) {
Paul E. McKenney0446be42012-12-30 15:21:01 -08001183 raw_spin_lock(&rnp_root->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001184 smp_mb__after_unlock_lock();
1185 }
Paul E. McKenney0446be42012-12-30 15:21:01 -08001186
1187 /*
1188 * Get a new grace-period number. If there really is no grace
1189 * period in progress, it will be smaller than the one we obtained
1190 * earlier. Adjust callbacks as needed. Note that even no-CBs
1191 * CPUs have a ->nxtcompleted[] array, so no no-CBs checks needed.
1192 */
1193 c = rcu_cbs_completed(rdp->rsp, rnp_root);
1194 for (i = RCU_DONE_TAIL; i < RCU_NEXT_TAIL; i++)
1195 if (ULONG_CMP_LT(c, rdp->nxtcompleted[i]))
1196 rdp->nxtcompleted[i] = c;
1197
1198 /*
1199 * If the needed for the required grace period is already
1200 * recorded, trace and leave.
1201 */
1202 if (rnp_root->need_future_gp[c & 0x1]) {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001203 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartedroot"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001204 goto unlock_out;
1205 }
1206
1207 /* Record the need for the future grace period. */
1208 rnp_root->need_future_gp[c & 0x1]++;
1209
1210 /* If a grace period is not already in progress, start one. */
1211 if (rnp_root->gpnum != rnp_root->completed) {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001212 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleafroot"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001213 } else {
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001214 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedroot"));
Paul E. McKenney910ee452012-12-31 02:24:21 -08001215 rcu_start_gp_advanced(rdp->rsp, rnp_root, rdp);
Paul E. McKenney0446be42012-12-30 15:21:01 -08001216 }
1217unlock_out:
1218 if (rnp != rnp_root)
1219 raw_spin_unlock(&rnp_root->lock);
1220 return c;
1221}
1222
1223/*
1224 * Clean up any old requests for the just-ended grace period. Also return
1225 * whether any additional grace periods have been requested. Also invoke
1226 * rcu_nocb_gp_cleanup() in order to wake up any no-callbacks kthreads
1227 * waiting for this grace period to complete.
1228 */
1229static int rcu_future_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
1230{
1231 int c = rnp->completed;
1232 int needmore;
1233 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
1234
1235 rcu_nocb_gp_cleanup(rsp, rnp);
1236 rnp->need_future_gp[c & 0x1] = 0;
1237 needmore = rnp->need_future_gp[(c + 1) & 0x1];
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001238 trace_rcu_future_gp(rnp, rdp, c,
1239 needmore ? TPS("CleanupMore") : TPS("Cleanup"));
Paul E. McKenney0446be42012-12-30 15:21:01 -08001240 return needmore;
1241}
1242
1243/*
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001244 * If there is room, assign a ->completed number to any callbacks on
1245 * this CPU that have not already been assigned. Also accelerate any
1246 * callbacks that were previously assigned a ->completed number that has
1247 * since proven to be too conservative, which can happen if callbacks get
1248 * assigned a ->completed number while RCU is idle, but with reference to
1249 * a non-root rcu_node structure. This function is idempotent, so it does
1250 * not hurt to call it repeatedly.
1251 *
1252 * The caller must hold rnp->lock with interrupts disabled.
1253 */
1254static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1255 struct rcu_data *rdp)
1256{
1257 unsigned long c;
1258 int i;
1259
1260 /* If the CPU has no callbacks, nothing to do. */
1261 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
1262 return;
1263
1264 /*
1265 * Starting from the sublist containing the callbacks most
1266 * recently assigned a ->completed number and working down, find the
1267 * first sublist that is not assignable to an upcoming grace period.
1268 * Such a sublist has something in it (first two tests) and has
1269 * a ->completed number assigned that will complete sooner than
1270 * the ->completed number for newly arrived callbacks (last test).
1271 *
1272 * The key point is that any later sublist can be assigned the
1273 * same ->completed number as the newly arrived callbacks, which
1274 * means that the callbacks in any of these later sublist can be
1275 * grouped into a single sublist, whether or not they have already
1276 * been assigned a ->completed number.
1277 */
1278 c = rcu_cbs_completed(rsp, rnp);
1279 for (i = RCU_NEXT_TAIL - 1; i > RCU_DONE_TAIL; i--)
1280 if (rdp->nxttail[i] != rdp->nxttail[i - 1] &&
1281 !ULONG_CMP_GE(rdp->nxtcompleted[i], c))
1282 break;
1283
1284 /*
1285 * If there are no sublist for unassigned callbacks, leave.
1286 * At the same time, advance "i" one sublist, so that "i" will
1287 * index into the sublist where all the remaining callbacks should
1288 * be grouped into.
1289 */
1290 if (++i >= RCU_NEXT_TAIL)
1291 return;
1292
1293 /*
1294 * Assign all subsequent callbacks' ->completed number to the next
1295 * full grace period and group them all in the sublist initially
1296 * indexed by "i".
1297 */
1298 for (; i <= RCU_NEXT_TAIL; i++) {
1299 rdp->nxttail[i] = rdp->nxttail[RCU_NEXT_TAIL];
1300 rdp->nxtcompleted[i] = c;
1301 }
Paul E. McKenney910ee452012-12-31 02:24:21 -08001302 /* Record any needed additional grace periods. */
1303 rcu_start_future_gp(rnp, rdp);
Paul E. McKenney6d4b4182012-11-27 16:55:44 -08001304
1305 /* Trace depending on how much we were able to accelerate. */
1306 if (!*rdp->nxttail[RCU_WAIT_TAIL])
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001307 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccWaitCB"));
Paul E. McKenney6d4b4182012-11-27 16:55:44 -08001308 else
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001309 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccReadyCB"));
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001310}
1311
1312/*
1313 * Move any callbacks whose grace period has completed to the
1314 * RCU_DONE_TAIL sublist, then compact the remaining sublists and
1315 * assign ->completed numbers to any callbacks in the RCU_NEXT_TAIL
1316 * sublist. This function is idempotent, so it does not hurt to
1317 * invoke it repeatedly. As long as it is not invoked -too- often...
1318 *
1319 * The caller must hold rnp->lock with interrupts disabled.
1320 */
1321static void rcu_advance_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1322 struct rcu_data *rdp)
1323{
1324 int i, j;
1325
1326 /* If the CPU has no callbacks, nothing to do. */
1327 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
1328 return;
1329
1330 /*
1331 * Find all callbacks whose ->completed numbers indicate that they
1332 * are ready to invoke, and put them into the RCU_DONE_TAIL sublist.
1333 */
1334 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++) {
1335 if (ULONG_CMP_LT(rnp->completed, rdp->nxtcompleted[i]))
1336 break;
1337 rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[i];
1338 }
1339 /* Clean up any sublist tail pointers that were misordered above. */
1340 for (j = RCU_WAIT_TAIL; j < i; j++)
1341 rdp->nxttail[j] = rdp->nxttail[RCU_DONE_TAIL];
1342
1343 /* Copy down callbacks to fill in empty sublists. */
1344 for (j = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++, j++) {
1345 if (rdp->nxttail[j] == rdp->nxttail[RCU_NEXT_TAIL])
1346 break;
1347 rdp->nxttail[j] = rdp->nxttail[i];
1348 rdp->nxtcompleted[j] = rdp->nxtcompleted[i];
1349 }
1350
1351 /* Classify any remaining callbacks. */
1352 rcu_accelerate_cbs(rsp, rnp, rdp);
1353}
1354
1355/*
Paul E. McKenneyba9fbe92013-03-19 11:53:31 -07001356 * Update CPU-local rcu_data state to record the beginnings and ends of
1357 * grace periods. The caller must hold the ->lock of the leaf rcu_node
1358 * structure corresponding to the current CPU, and must have irqs disabled.
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08001359 */
Paul E. McKenneyba9fbe92013-03-19 11:53:31 -07001360static void __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp)
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08001361{
Paul E. McKenneyba9fbe92013-03-19 11:53:31 -07001362 /* Handle the ends of any preceding grace periods first. */
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001363 if (rdp->completed == rnp->completed) {
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08001364
Paul E. McKenneyba9fbe92013-03-19 11:53:31 -07001365 /* No grace period end, so just accelerate recent callbacks. */
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001366 rcu_accelerate_cbs(rsp, rnp, rdp);
1367
1368 } else {
1369
1370 /* Advance callbacks. */
1371 rcu_advance_cbs(rsp, rnp, rdp);
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08001372
1373 /* Remember that we saw this grace-period completion. */
1374 rdp->completed = rnp->completed;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001375 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuend"));
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08001376 }
Paul E. McKenney398ebe62013-03-19 10:53:14 -07001377
Paul E. McKenney6eaef632013-03-19 10:08:37 -07001378 if (rdp->gpnum != rnp->gpnum) {
1379 /*
1380 * If the current grace period is waiting for this CPU,
1381 * set up to detect a quiescent state, otherwise don't
1382 * go looking for one.
1383 */
1384 rdp->gpnum = rnp->gpnum;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001385 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpustart"));
Paul E. McKenney6eaef632013-03-19 10:08:37 -07001386 rdp->passed_quiesce = 0;
1387 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
1388 zero_cpu_stall_ticks(rdp);
1389 }
1390}
1391
Paul E. McKenneyd34ea322013-03-19 11:10:43 -07001392static void note_gp_changes(struct rcu_state *rsp, struct rcu_data *rdp)
Paul E. McKenney6eaef632013-03-19 10:08:37 -07001393{
1394 unsigned long flags;
1395 struct rcu_node *rnp;
1396
1397 local_irq_save(flags);
1398 rnp = rdp->mynode;
Paul E. McKenneyd34ea322013-03-19 11:10:43 -07001399 if ((rdp->gpnum == ACCESS_ONCE(rnp->gpnum) &&
1400 rdp->completed == ACCESS_ONCE(rnp->completed)) || /* w/out lock. */
Paul E. McKenney6eaef632013-03-19 10:08:37 -07001401 !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
1402 local_irq_restore(flags);
1403 return;
1404 }
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001405 smp_mb__after_unlock_lock();
Paul E. McKenneyd34ea322013-03-19 11:10:43 -07001406 __note_gp_changes(rsp, rnp, rdp);
Paul E. McKenney6eaef632013-03-19 10:08:37 -07001407 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1408}
1409
1410/*
Paul E. McKenneyf7be8202013-08-08 18:27:52 -07001411 * Initialize a new grace period. Return 0 if no grace period required.
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001412 */
1413static int rcu_gp_init(struct rcu_state *rsp)
1414{
1415 struct rcu_data *rdp;
1416 struct rcu_node *rnp = rcu_get_root(rsp);
1417
Paul E. McKenneyeb757672013-06-21 17:10:40 -07001418 rcu_bind_gp_kthread();
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001419 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001420 smp_mb__after_unlock_lock();
Paul E. McKenney91dc9542014-02-18 09:47:13 -08001421 if (!ACCESS_ONCE(rsp->gp_flags)) {
Paul E. McKenneyf7be8202013-08-08 18:27:52 -07001422 /* Spurious wakeup, tell caller to go back to sleep. */
1423 raw_spin_unlock_irq(&rnp->lock);
1424 return 0;
1425 }
Paul E. McKenney91dc9542014-02-18 09:47:13 -08001426 ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001427
Paul E. McKenneyf7be8202013-08-08 18:27:52 -07001428 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
1429 /*
1430 * Grace period already in progress, don't start another.
1431 * Not supposed to be able to happen.
1432 */
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001433 raw_spin_unlock_irq(&rnp->lock);
1434 return 0;
1435 }
1436
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001437 /* Advance to a new grace period and initialize state. */
Paul E. McKenney26cdfed2013-09-04 10:51:13 -07001438 record_gp_stall_check_time(rsp);
Paul E. McKenney765a3f42014-03-14 16:37:08 -07001439 /* Record GP times before starting GP, hence smp_store_release(). */
1440 smp_store_release(&rsp->gpnum, rsp->gpnum + 1);
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001441 trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start"));
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001442 raw_spin_unlock_irq(&rnp->lock);
1443
1444 /* Exclude any concurrent CPU-hotplug operations. */
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07001445 mutex_lock(&rsp->onoff_mutex);
Paul E. McKenney765a3f42014-03-14 16:37:08 -07001446 smp_mb__after_unlock_lock(); /* ->gpnum increment before GP! */
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001447
1448 /*
1449 * Set the quiescent-state-needed bits in all the rcu_node
1450 * structures for all currently online CPUs in breadth-first order,
1451 * starting from the root rcu_node structure, relying on the layout
1452 * of the tree within the rsp->node[] array. Note that other CPUs
1453 * will access only the leaves of the hierarchy, thus seeing that no
1454 * grace period is in progress, at least until the corresponding
1455 * leaf node has been initialized. In addition, we have excluded
1456 * CPU-hotplug operations.
1457 *
1458 * The grace period cannot complete until the initialization
1459 * process finishes, because this kthread handles both.
1460 */
1461 rcu_for_each_node_breadth_first(rsp, rnp) {
1462 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001463 smp_mb__after_unlock_lock();
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001464 rdp = this_cpu_ptr(rsp->rda);
1465 rcu_preempt_check_blocked_tasks(rnp);
1466 rnp->qsmask = rnp->qsmaskinit;
Paul E. McKenney0446be42012-12-30 15:21:01 -08001467 ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
Paul E. McKenney25d30cf2012-07-11 05:23:18 -07001468 WARN_ON_ONCE(rnp->completed != rsp->completed);
Paul E. McKenney0446be42012-12-30 15:21:01 -08001469 ACCESS_ONCE(rnp->completed) = rsp->completed;
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001470 if (rnp == rdp->mynode)
Paul E. McKenneyce3d9c02013-03-19 12:27:50 -07001471 __note_gp_changes(rsp, rnp, rdp);
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001472 rcu_preempt_boost_start_gp(rnp);
1473 trace_rcu_grace_period_init(rsp->name, rnp->gpnum,
1474 rnp->level, rnp->grplo,
1475 rnp->grphi, rnp->qsmask);
1476 raw_spin_unlock_irq(&rnp->lock);
Paul E. McKenney661a85d2012-07-07 05:57:03 -07001477#ifdef CONFIG_PROVE_RCU_DELAY
Paul E. McKenney971394f2013-06-02 07:13:57 -07001478 if ((prandom_u32() % (rcu_num_nodes + 1)) == 0 &&
Paul E. McKenney81e59492013-03-10 15:44:52 -07001479 system_state == SYSTEM_RUNNING)
Paul E. McKenney971394f2013-06-02 07:13:57 -07001480 udelay(200);
Paul E. McKenney661a85d2012-07-07 05:57:03 -07001481#endif /* #ifdef CONFIG_PROVE_RCU_DELAY */
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001482 cond_resched();
1483 }
1484
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07001485 mutex_unlock(&rsp->onoff_mutex);
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001486 return 1;
1487}
1488
1489/*
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001490 * Do one round of quiescent-state forcing.
1491 */
Paul E. McKenney01896f72013-08-18 12:14:32 -07001492static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001493{
1494 int fqs_state = fqs_state_in;
Paul E. McKenney217af2a2013-06-21 15:39:06 -07001495 bool isidle = false;
1496 unsigned long maxj;
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001497 struct rcu_node *rnp = rcu_get_root(rsp);
1498
1499 rsp->n_force_qs++;
1500 if (fqs_state == RCU_SAVE_DYNTICK) {
1501 /* Collect dyntick-idle snapshots. */
Paul E. McKenney0edd1b12013-06-21 16:37:22 -07001502 if (is_sysidle_rcu_state(rsp)) {
1503 isidle = 1;
1504 maxj = jiffies - ULONG_MAX / 4;
1505 }
Paul E. McKenney217af2a2013-06-21 15:39:06 -07001506 force_qs_rnp(rsp, dyntick_save_progress_counter,
1507 &isidle, &maxj);
Paul E. McKenney0edd1b12013-06-21 16:37:22 -07001508 rcu_sysidle_report_gp(rsp, isidle, maxj);
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001509 fqs_state = RCU_FORCE_QS;
1510 } else {
1511 /* Handle dyntick-idle and offline CPUs. */
Paul E. McKenney0edd1b12013-06-21 16:37:22 -07001512 isidle = 0;
Paul E. McKenney217af2a2013-06-21 15:39:06 -07001513 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj);
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001514 }
1515 /* Clear flag to prevent immediate re-entry. */
1516 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1517 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001518 smp_mb__after_unlock_lock();
Paul E. McKenney91dc9542014-02-18 09:47:13 -08001519 ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001520 raw_spin_unlock_irq(&rnp->lock);
1521 }
1522 return fqs_state;
1523}
1524
1525/*
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001526 * Clean up after the old grace period.
1527 */
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001528static void rcu_gp_cleanup(struct rcu_state *rsp)
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001529{
1530 unsigned long gp_duration;
Paul E. McKenneydae6e642013-02-10 20:48:58 -08001531 int nocb = 0;
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001532 struct rcu_data *rdp;
1533 struct rcu_node *rnp = rcu_get_root(rsp);
1534
1535 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001536 smp_mb__after_unlock_lock();
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001537 gp_duration = jiffies - rsp->gp_start;
1538 if (gp_duration > rsp->gp_max)
1539 rsp->gp_max = gp_duration;
1540
1541 /*
1542 * We know the grace period is complete, but to everyone else
1543 * it appears to still be ongoing. But it is also the case
1544 * that to everyone else it looks like there is nothing that
1545 * they can do to advance the grace period. It is therefore
1546 * safe for us to drop the lock in order to mark the grace
1547 * period as completed in all of the rcu_node structures.
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001548 */
Paul E. McKenney5d4b8652012-07-07 07:56:57 -07001549 raw_spin_unlock_irq(&rnp->lock);
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001550
Paul E. McKenney5d4b8652012-07-07 07:56:57 -07001551 /*
1552 * Propagate new ->completed value to rcu_node structures so
1553 * that other CPUs don't have to wait until the start of the next
1554 * grace period to process their callbacks. This also avoids
1555 * some nasty RCU grace-period initialization races by forcing
1556 * the end of the current grace period to be completely recorded in
1557 * all of the rcu_node structures before the beginning of the next
1558 * grace period is recorded in any of the rcu_node structures.
1559 */
1560 rcu_for_each_node_breadth_first(rsp, rnp) {
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001561 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001562 smp_mb__after_unlock_lock();
Paul E. McKenney0446be42012-12-30 15:21:01 -08001563 ACCESS_ONCE(rnp->completed) = rsp->gpnum;
Paul E. McKenneyb11cc572012-12-17 14:21:14 -08001564 rdp = this_cpu_ptr(rsp->rda);
1565 if (rnp == rdp->mynode)
Paul E. McKenney470716f2013-03-19 11:32:11 -07001566 __note_gp_changes(rsp, rnp, rdp);
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001567 /* smp_mb() provided by prior unlock-lock pair. */
Paul E. McKenney0446be42012-12-30 15:21:01 -08001568 nocb += rcu_future_gp_cleanup(rsp, rnp);
Paul E. McKenney5d4b8652012-07-07 07:56:57 -07001569 raw_spin_unlock_irq(&rnp->lock);
1570 cond_resched();
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001571 }
Paul E. McKenney5d4b8652012-07-07 07:56:57 -07001572 rnp = rcu_get_root(rsp);
1573 raw_spin_lock_irq(&rnp->lock);
Paul E. McKenney765a3f42014-03-14 16:37:08 -07001574 smp_mb__after_unlock_lock(); /* Order GP before ->completed update. */
Paul E. McKenneydae6e642013-02-10 20:48:58 -08001575 rcu_nocb_gp_set(rnp, nocb);
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001576
Paul E. McKenney765a3f42014-03-14 16:37:08 -07001577 /* Declare grace period done. */
1578 ACCESS_ONCE(rsp->completed) = rsp->gpnum;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04001579 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001580 rsp->fqs_state = RCU_GP_IDLE;
Paul E. McKenney5d4b8652012-07-07 07:56:57 -07001581 rdp = this_cpu_ptr(rsp->rda);
Paul E. McKenneyb11cc572012-12-17 14:21:14 -08001582 rcu_advance_cbs(rsp, rnp, rdp); /* Reduce false positives below. */
Paul E. McKenneybb311ec2013-08-09 16:02:09 -07001583 if (cpu_needs_another_gp(rsp, rdp)) {
Paul E. McKenney91dc9542014-02-18 09:47:13 -08001584 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
Paul E. McKenneybb311ec2013-08-09 16:02:09 -07001585 trace_rcu_grace_period(rsp->name,
1586 ACCESS_ONCE(rsp->gpnum),
1587 TPS("newreq"));
1588 }
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001589 raw_spin_unlock_irq(&rnp->lock);
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001590}
1591
1592/*
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001593 * Body of kthread that handles grace periods.
1594 */
Paul E. McKenney755609a2012-06-19 17:18:20 -07001595static int __noreturn rcu_gp_kthread(void *arg)
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001596{
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001597 int fqs_state;
Paul E. McKenney88d6df62013-08-08 21:44:31 -07001598 int gf;
Paul E. McKenneyd40011f2012-06-26 20:45:57 -07001599 unsigned long j;
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001600 int ret;
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001601 struct rcu_state *rsp = arg;
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001602 struct rcu_node *rnp = rcu_get_root(rsp);
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001603
1604 for (;;) {
1605
1606 /* Handle grace-period start. */
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001607 for (;;) {
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001608 trace_rcu_grace_period(rsp->name,
1609 ACCESS_ONCE(rsp->gpnum),
1610 TPS("reqwait"));
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001611 wait_event_interruptible(rsp->gp_wq,
Paul E. McKenney591c6d12013-08-08 22:26:23 -07001612 ACCESS_ONCE(rsp->gp_flags) &
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001613 RCU_GP_FLAG_INIT);
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001614 /* Locking provides needed memory barrier. */
Paul E. McKenneyf7be8202013-08-08 18:27:52 -07001615 if (rcu_gp_init(rsp))
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001616 break;
Paul E. McKenney7fdefc12012-06-22 11:08:41 -07001617 cond_resched();
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001618 flush_signals(current);
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001619 trace_rcu_grace_period(rsp->name,
1620 ACCESS_ONCE(rsp->gpnum),
1621 TPS("reqwaitsig"));
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001622 }
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001623
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001624 /* Handle quiescent-state forcing. */
1625 fqs_state = RCU_SAVE_DYNTICK;
Paul E. McKenneyd40011f2012-06-26 20:45:57 -07001626 j = jiffies_till_first_fqs;
1627 if (j > HZ) {
1628 j = HZ;
1629 jiffies_till_first_fqs = HZ;
1630 }
Paul E. McKenney88d6df62013-08-08 21:44:31 -07001631 ret = 0;
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001632 for (;;) {
Paul E. McKenney88d6df62013-08-08 21:44:31 -07001633 if (!ret)
1634 rsp->jiffies_force_qs = jiffies + j;
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001635 trace_rcu_grace_period(rsp->name,
1636 ACCESS_ONCE(rsp->gpnum),
1637 TPS("fqswait"));
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001638 ret = wait_event_interruptible_timeout(rsp->gp_wq,
Paul E. McKenney88d6df62013-08-08 21:44:31 -07001639 ((gf = ACCESS_ONCE(rsp->gp_flags)) &
1640 RCU_GP_FLAG_FQS) ||
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001641 (!ACCESS_ONCE(rnp->qsmask) &&
1642 !rcu_preempt_blocked_readers_cgp(rnp)),
Paul E. McKenneyd40011f2012-06-26 20:45:57 -07001643 j);
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001644 /* Locking provides needed memory barriers. */
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001645 /* If grace period done, leave loop. */
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001646 if (!ACCESS_ONCE(rnp->qsmask) &&
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001647 !rcu_preempt_blocked_readers_cgp(rnp))
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001648 break;
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001649 /* If time for quiescent-state forcing, do it. */
Paul E. McKenney88d6df62013-08-08 21:44:31 -07001650 if (ULONG_CMP_GE(jiffies, rsp->jiffies_force_qs) ||
1651 (gf & RCU_GP_FLAG_FQS)) {
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001652 trace_rcu_grace_period(rsp->name,
1653 ACCESS_ONCE(rsp->gpnum),
1654 TPS("fqsstart"));
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001655 fqs_state = rcu_gp_fqs(rsp, fqs_state);
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001656 trace_rcu_grace_period(rsp->name,
1657 ACCESS_ONCE(rsp->gpnum),
1658 TPS("fqsend"));
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001659 cond_resched();
1660 } else {
1661 /* Deal with stray signal. */
1662 cond_resched();
1663 flush_signals(current);
Paul E. McKenney63c4db72013-08-09 12:19:29 -07001664 trace_rcu_grace_period(rsp->name,
1665 ACCESS_ONCE(rsp->gpnum),
1666 TPS("fqswaitsig"));
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001667 }
Paul E. McKenneyd40011f2012-06-26 20:45:57 -07001668 j = jiffies_till_next_fqs;
1669 if (j > HZ) {
1670 j = HZ;
1671 jiffies_till_next_fqs = HZ;
1672 } else if (j < 1) {
1673 j = 1;
1674 jiffies_till_next_fqs = 1;
1675 }
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001676 }
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07001677
1678 /* Handle grace-period end. */
1679 rcu_gp_cleanup(rsp);
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001680 }
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001681}
1682
Steven Rostedt016a8d52013-05-28 17:32:53 -04001683static void rsp_wakeup(struct irq_work *work)
1684{
1685 struct rcu_state *rsp = container_of(work, struct rcu_state, wakeup_work);
1686
1687 /* Wake up rcu_gp_kthread() to start the grace period. */
1688 wake_up(&rsp->gp_wq);
Paul E. McKenney365187f2014-03-10 10:55:52 -07001689 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
1690 "Workqueuewoken");
Steven Rostedt016a8d52013-05-28 17:32:53 -04001691}
1692
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001693/*
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001694 * Start a new RCU grace period if warranted, re-initializing the hierarchy
1695 * in preparation for detecting the next grace period. The caller must hold
Paul E. McKenneyb8462082012-12-29 22:04:18 -08001696 * the root node's ->lock and hard irqs must be disabled.
Paul E. McKenneye5601402012-01-07 11:03:57 -08001697 *
1698 * Note that it is legal for a dying CPU (which is marked as offline) to
1699 * invoke this function. This can happen when the dying CPU reports its
1700 * quiescent state.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001701 */
1702static void
Paul E. McKenney910ee452012-12-31 02:24:21 -08001703rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
1704 struct rcu_data *rdp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001705{
Paul E. McKenneyb8462082012-12-29 22:04:18 -08001706 if (!rsp->gp_kthread || !cpu_needs_another_gp(rsp, rdp)) {
Paul E. McKenneyb32e9eb2009-11-12 22:35:03 -08001707 /*
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001708 * Either we have not yet spawned the grace-period
Paul E. McKenney62da1922012-09-20 16:02:49 -07001709 * task, this CPU does not need another grace period,
1710 * or a grace period is already in progress.
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07001711 * Either way, don't start a new grace period.
Paul E. McKenneyb32e9eb2009-11-12 22:35:03 -08001712 */
Paul E. McKenneyafe24b12011-08-24 16:52:09 -07001713 return;
1714 }
Paul E. McKenney91dc9542014-02-18 09:47:13 -08001715 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
Paul E. McKenneybb311ec2013-08-09 16:02:09 -07001716 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
1717 TPS("newreq"));
Paul E. McKenney62da1922012-09-20 16:02:49 -07001718
Steven Rostedt016a8d52013-05-28 17:32:53 -04001719 /*
1720 * We can't do wakeups while holding the rnp->lock, as that
Paul E. McKenney1eafd312013-06-20 13:50:40 -07001721 * could cause possible deadlocks with the rq->lock. Defer
1722 * the wakeup to interrupt context. And don't bother waking
1723 * up the running kthread.
Steven Rostedt016a8d52013-05-28 17:32:53 -04001724 */
Paul E. McKenney365187f2014-03-10 10:55:52 -07001725 if (current != rsp->gp_kthread) {
1726 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
1727 "Workqueuewake");
Paul E. McKenney1eafd312013-06-20 13:50:40 -07001728 irq_work_queue(&rsp->wakeup_work);
Paul E. McKenney365187f2014-03-10 10:55:52 -07001729 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001730}
1731
1732/*
Paul E. McKenney910ee452012-12-31 02:24:21 -08001733 * Similar to rcu_start_gp_advanced(), but also advance the calling CPU's
1734 * callbacks. Note that rcu_start_gp_advanced() cannot do this because it
1735 * is invoked indirectly from rcu_advance_cbs(), which would result in
1736 * endless recursion -- or would do so if it wasn't for the self-deadlock
1737 * that is encountered beforehand.
1738 */
1739static void
1740rcu_start_gp(struct rcu_state *rsp)
1741{
1742 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
1743 struct rcu_node *rnp = rcu_get_root(rsp);
1744
1745 /*
1746 * If there is no grace period in progress right now, any
1747 * callbacks we have up to this point will be satisfied by the
1748 * next grace period. Also, advancing the callbacks reduces the
1749 * probability of false positives from cpu_needs_another_gp()
1750 * resulting in pointless grace periods. So, advance callbacks
1751 * then start the grace period!
1752 */
1753 rcu_advance_cbs(rsp, rnp, rdp);
1754 rcu_start_gp_advanced(rsp, rnp, rdp);
1755}
1756
1757/*
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001758 * Report a full set of quiescent states to the specified rcu_state
1759 * data structure. This involves cleaning up after the prior grace
1760 * period and letting rcu_start_gp() start up the next grace period
Paul E. McKenneyb8462082012-12-29 22:04:18 -08001761 * if one is needed. Note that the caller must hold rnp->lock, which
1762 * is released before return.
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001763 */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001764static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
Paul E. McKenneyfc2219d42009-09-23 09:50:41 -07001765 __releases(rcu_get_root(rsp)->lock)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001766{
Paul E. McKenneyfc2219d42009-09-23 09:50:41 -07001767 WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
Paul E. McKenneycabc49c2012-06-20 17:07:14 -07001768 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
1769 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001770}
1771
1772/*
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001773 * Similar to rcu_report_qs_rdp(), for which it is a helper function.
1774 * Allows quiescent states for a group of CPUs to be reported at one go
1775 * to the specified rcu_node structure, though all the CPUs in the group
1776 * must be represented by the same rcu_node structure (which need not be
1777 * a leaf rcu_node structure, though it often will be). That structure's
1778 * lock must be held upon entry, and it is released before return.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001779 */
1780static void
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001781rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp,
1782 struct rcu_node *rnp, unsigned long flags)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001783 __releases(rnp->lock)
1784{
Paul E. McKenney28ecd582009-09-18 09:50:17 -07001785 struct rcu_node *rnp_c;
1786
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001787 /* Walk up the rcu_node hierarchy. */
1788 for (;;) {
1789 if (!(rnp->qsmask & mask)) {
1790
1791 /* Our bit has already been cleared, so done. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001792 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001793 return;
1794 }
1795 rnp->qsmask &= ~mask;
Paul E. McKenneyd4c08f22011-06-25 06:36:56 -07001796 trace_rcu_quiescent_state_report(rsp->name, rnp->gpnum,
1797 mask, rnp->qsmask, rnp->level,
1798 rnp->grplo, rnp->grphi,
1799 !!rnp->gp_tasks);
Paul E. McKenney27f4d282011-02-07 12:47:15 -08001800 if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001801
1802 /* Other bits still set at this level, so done. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001803 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001804 return;
1805 }
1806 mask = rnp->grpmask;
1807 if (rnp->parent == NULL) {
1808
1809 /* No more levels. Exit loop holding root lock. */
1810
1811 break;
1812 }
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001813 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney28ecd582009-09-18 09:50:17 -07001814 rnp_c = rnp;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001815 rnp = rnp->parent;
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001816 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001817 smp_mb__after_unlock_lock();
Paul E. McKenney28ecd582009-09-18 09:50:17 -07001818 WARN_ON_ONCE(rnp_c->qsmask);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001819 }
1820
1821 /*
1822 * Get here if we are the last CPU to pass through a quiescent
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001823 * state for this grace period. Invoke rcu_report_qs_rsp()
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001824 * to clean up and start the next grace period if one is needed.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001825 */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001826 rcu_report_qs_rsp(rsp, flags); /* releases rnp->lock. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001827}
1828
1829/*
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001830 * Record a quiescent state for the specified CPU to that CPU's rcu_data
1831 * structure. This must be either called from the specified CPU, or
1832 * called when the specified CPU is known to be offline (and when it is
1833 * also known that no other CPU is concurrently trying to help the offline
1834 * CPU). The lastcomp argument is used to make sure we are still in the
1835 * grace period of interest. We don't want to end the current grace period
1836 * based on quiescent states detected in an earlier grace period!
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001837 */
1838static void
Paul E. McKenneyd7d6a112012-08-21 15:00:05 -07001839rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001840{
1841 unsigned long flags;
1842 unsigned long mask;
1843 struct rcu_node *rnp;
1844
1845 rnp = rdp->mynode;
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001846 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08001847 smp_mb__after_unlock_lock();
Paul E. McKenneyd7d6a112012-08-21 15:00:05 -07001848 if (rdp->passed_quiesce == 0 || rdp->gpnum != rnp->gpnum ||
1849 rnp->completed == rnp->gpnum) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001850
1851 /*
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -07001852 * The grace period in which this quiescent state was
1853 * recorded has ended, so don't report it upwards.
1854 * We will instead need a new quiescent state that lies
1855 * within the current grace period.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001856 */
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -07001857 rdp->passed_quiesce = 0; /* need qs for new gp. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001858 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001859 return;
1860 }
1861 mask = rdp->grpmask;
1862 if ((rnp->qsmask & mask) == 0) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -08001863 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001864 } else {
1865 rdp->qs_pending = 0;
1866
1867 /*
1868 * This GP can't end until cpu checks in, so all of our
1869 * callbacks can be processed during the next GP.
1870 */
Paul E. McKenneydc35c892012-12-03 13:52:00 -08001871 rcu_accelerate_cbs(rsp, rnp, rdp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001872
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001873 rcu_report_qs_rnp(mask, rsp, rnp, flags); /* rlses rnp->lock */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001874 }
1875}
1876
1877/*
1878 * Check to see if there is a new grace period of which this CPU
1879 * is not yet aware, and if so, set up local rcu_data state for it.
1880 * Otherwise, see if this CPU has just passed through its first
1881 * quiescent state for this grace period, and record that fact if so.
1882 */
1883static void
1884rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
1885{
Paul E. McKenney05eb5522013-03-19 12:38:24 -07001886 /* Check for grace-period ends and beginnings. */
1887 note_gp_changes(rsp, rdp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001888
1889 /*
1890 * Does this CPU still need to do its part for current grace period?
1891 * If no, return and let the other CPUs do their part as well.
1892 */
1893 if (!rdp->qs_pending)
1894 return;
1895
1896 /*
1897 * Was there a quiescent state since the beginning of the grace
1898 * period? If no, then exit and wait for the next call.
1899 */
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -07001900 if (!rdp->passed_quiesce)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001901 return;
1902
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08001903 /*
1904 * Tell RCU we are done (but rcu_report_qs_rdp() will be the
1905 * judge of that).
1906 */
Paul E. McKenneyd7d6a112012-08-21 15:00:05 -07001907 rcu_report_qs_rdp(rdp->cpu, rsp, rdp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001908}
1909
1910#ifdef CONFIG_HOTPLUG_CPU
1911
1912/*
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001913 * Send the specified CPU's RCU callbacks to the orphanage. The
1914 * specified CPU must be offline, and the caller must hold the
Paul E. McKenney7b2e6012012-10-08 10:54:03 -07001915 * ->orphan_lock.
Paul E. McKenneye74f4c42009-10-06 21:48:17 -07001916 */
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001917static void
1918rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
1919 struct rcu_node *rnp, struct rcu_data *rdp)
Paul E. McKenneye74f4c42009-10-06 21:48:17 -07001920{
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07001921 /* No-CBs CPUs do not have orphanable callbacks. */
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +01001922 if (rcu_is_nocb_cpu(rdp->cpu))
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07001923 return;
1924
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001925 /*
1926 * Orphan the callbacks. First adjust the counts. This is safe
Paul E. McKenneyabfd6e52012-09-20 16:59:47 -07001927 * because _rcu_barrier() excludes CPU-hotplug operations, so it
1928 * cannot be running now. Thus no memory barrier is required.
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001929 */
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001930 if (rdp->nxtlist != NULL) {
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001931 rsp->qlen_lazy += rdp->qlen_lazy;
1932 rsp->qlen += rdp->qlen;
1933 rdp->n_cbs_orphaned += rdp->qlen;
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001934 rdp->qlen_lazy = 0;
Paul E. McKenney1d1fb392012-05-09 15:44:42 -07001935 ACCESS_ONCE(rdp->qlen) = 0;
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001936 }
1937
1938 /*
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001939 * Next, move those callbacks still needing a grace period to
1940 * the orphanage, where some other CPU will pick them up.
1941 * Some of the callbacks might have gone partway through a grace
1942 * period, but that is too bad. They get to start over because we
1943 * cannot assume that grace periods are synchronized across CPUs.
1944 * We don't bother updating the ->nxttail[] array yet, instead
1945 * we just reset the whole thing later on.
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001946 */
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001947 if (*rdp->nxttail[RCU_DONE_TAIL] != NULL) {
1948 *rsp->orphan_nxttail = *rdp->nxttail[RCU_DONE_TAIL];
1949 rsp->orphan_nxttail = rdp->nxttail[RCU_NEXT_TAIL];
1950 *rdp->nxttail[RCU_DONE_TAIL] = NULL;
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001951 }
1952
1953 /*
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001954 * Then move the ready-to-invoke callbacks to the orphanage,
1955 * where some other CPU will pick them up. These will not be
1956 * required to pass though another grace period: They are done.
Paul E. McKenneya50c3af2012-01-10 17:52:31 -08001957 */
Paul E. McKenneye5601402012-01-07 11:03:57 -08001958 if (rdp->nxtlist != NULL) {
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001959 *rsp->orphan_donetail = rdp->nxtlist;
1960 rsp->orphan_donetail = rdp->nxttail[RCU_DONE_TAIL];
Paul E. McKenneye5601402012-01-07 11:03:57 -08001961 }
Lai Jiangshan29494be2010-10-20 14:13:06 +08001962
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001963 /* Finally, initialize the rcu_data structure's list to empty. */
Paul E. McKenney3f5d3ea2012-05-09 15:39:56 -07001964 init_callback_list(rdp);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001965}
1966
1967/*
1968 * Adopt the RCU callbacks from the specified rcu_state structure's
Paul E. McKenney7b2e6012012-10-08 10:54:03 -07001969 * orphanage. The caller must hold the ->orphan_lock.
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001970 */
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07001971static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001972{
1973 int i;
1974 struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
1975
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07001976 /* No-CBs CPUs are handled specially. */
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07001977 if (rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags))
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07001978 return;
1979
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001980 /* Do the accounting first. */
1981 rdp->qlen_lazy += rsp->qlen_lazy;
1982 rdp->qlen += rsp->qlen;
1983 rdp->n_cbs_adopted += rsp->qlen;
Paul E. McKenney8f5af6f2012-05-04 08:31:53 -07001984 if (rsp->qlen_lazy != rsp->qlen)
1985 rcu_idle_count_callbacks_posted();
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08001986 rsp->qlen_lazy = 0;
1987 rsp->qlen = 0;
1988
1989 /*
1990 * We do not need a memory barrier here because the only way we
1991 * can get here if there is an rcu_barrier() in flight is if
1992 * we are the task doing the rcu_barrier().
1993 */
1994
1995 /* First adopt the ready-to-invoke callbacks. */
1996 if (rsp->orphan_donelist != NULL) {
1997 *rsp->orphan_donetail = *rdp->nxttail[RCU_DONE_TAIL];
1998 *rdp->nxttail[RCU_DONE_TAIL] = rsp->orphan_donelist;
1999 for (i = RCU_NEXT_SIZE - 1; i >= RCU_DONE_TAIL; i--)
2000 if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
2001 rdp->nxttail[i] = rsp->orphan_donetail;
2002 rsp->orphan_donelist = NULL;
2003 rsp->orphan_donetail = &rsp->orphan_donelist;
2004 }
2005
2006 /* And then adopt the callbacks that still need a grace period. */
2007 if (rsp->orphan_nxtlist != NULL) {
2008 *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxtlist;
2009 rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxttail;
2010 rsp->orphan_nxtlist = NULL;
2011 rsp->orphan_nxttail = &rsp->orphan_nxtlist;
2012 }
2013}
2014
2015/*
2016 * Trace the fact that this CPU is going offline.
2017 */
2018static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
2019{
2020 RCU_TRACE(unsigned long mask);
2021 RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda));
2022 RCU_TRACE(struct rcu_node *rnp = rdp->mynode);
2023
2024 RCU_TRACE(mask = rdp->grpmask);
Paul E. McKenneye5601402012-01-07 11:03:57 -08002025 trace_rcu_grace_period(rsp->name,
2026 rnp->gpnum + 1 - !!(rnp->qsmask & mask),
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04002027 TPS("cpuofl"));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002028}
2029
2030/*
Paul E. McKenneye5601402012-01-07 11:03:57 -08002031 * The CPU has been completely removed, and some other CPU is reporting
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002032 * this fact from process context. Do the remainder of the cleanup,
2033 * including orphaning the outgoing CPU's RCU callbacks, and also
Paul E. McKenney1331e7a2012-08-02 17:43:50 -07002034 * adopting them. There can only be one CPU hotplug operation at a time,
2035 * so no other CPU can be attempting to update rcu_cpu_kthread_task.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002036 */
Paul E. McKenneye5601402012-01-07 11:03:57 -08002037static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002038{
Paul E. McKenney2036d942012-01-30 17:02:47 -08002039 unsigned long flags;
2040 unsigned long mask;
2041 int need_report = 0;
Paul E. McKenneye5601402012-01-07 11:03:57 -08002042 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002043 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
Paul E. McKenneye5601402012-01-07 11:03:57 -08002044
Paul E. McKenney2036d942012-01-30 17:02:47 -08002045 /* Adjust any no-longer-needed kthreads. */
Thomas Gleixner5d01bbd2012-07-16 10:42:35 +00002046 rcu_boost_kthread_setaffinity(rnp, -1);
Paul E. McKenney2036d942012-01-30 17:02:47 -08002047
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002048 /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
Paul E. McKenney2036d942012-01-30 17:02:47 -08002049
2050 /* Exclude any attempts to start a new grace period. */
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07002051 mutex_lock(&rsp->onoff_mutex);
Paul E. McKenney7b2e6012012-10-08 10:54:03 -07002052 raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
Paul E. McKenney2036d942012-01-30 17:02:47 -08002053
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002054 /* Orphan the dead CPU's callbacks, and adopt them if appropriate. */
2055 rcu_send_cbs_to_orphanage(cpu, rsp, rnp, rdp);
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07002056 rcu_adopt_orphan_cbs(rsp, flags);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002057
Paul E. McKenney2036d942012-01-30 17:02:47 -08002058 /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */
2059 mask = rdp->grpmask; /* rnp->grplo is constant. */
2060 do {
2061 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08002062 smp_mb__after_unlock_lock();
Paul E. McKenney2036d942012-01-30 17:02:47 -08002063 rnp->qsmaskinit &= ~mask;
2064 if (rnp->qsmaskinit != 0) {
2065 if (rnp != rdp->mynode)
2066 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
2067 break;
2068 }
2069 if (rnp == rdp->mynode)
2070 need_report = rcu_preempt_offline_tasks(rsp, rnp, rdp);
2071 else
2072 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
2073 mask = rnp->grpmask;
2074 rnp = rnp->parent;
2075 } while (rnp != NULL);
2076
2077 /*
2078 * We still hold the leaf rcu_node structure lock here, and
2079 * irqs are still disabled. The reason for this subterfuge is
Paul E. McKenney7b2e6012012-10-08 10:54:03 -07002080 * because invoking rcu_report_unblock_qs_rnp() with ->orphan_lock
Paul E. McKenney2036d942012-01-30 17:02:47 -08002081 * held leads to deadlock.
2082 */
Paul E. McKenney7b2e6012012-10-08 10:54:03 -07002083 raw_spin_unlock(&rsp->orphan_lock); /* irqs remain disabled. */
Paul E. McKenney2036d942012-01-30 17:02:47 -08002084 rnp = rdp->mynode;
2085 if (need_report & RCU_OFL_TASKS_NORM_GP)
2086 rcu_report_unblock_qs_rnp(rnp, flags);
2087 else
2088 raw_spin_unlock_irqrestore(&rnp->lock, flags);
2089 if (need_report & RCU_OFL_TASKS_EXP_GP)
2090 rcu_report_exp_rnp(rsp, rnp, true);
Paul E. McKenneycf015372012-06-21 11:26:42 -07002091 WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL,
2092 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n",
2093 cpu, rdp->qlen, rdp->nxtlist);
Paul E. McKenney0d8ee372012-08-03 13:16:15 -07002094 init_callback_list(rdp);
2095 /* Disallow further callbacks on this CPU. */
2096 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07002097 mutex_unlock(&rsp->onoff_mutex);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002098}
2099
2100#else /* #ifdef CONFIG_HOTPLUG_CPU */
2101
Paul E. McKenneye5601402012-01-07 11:03:57 -08002102static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
Paul E. McKenneye74f4c42009-10-06 21:48:17 -07002103{
2104}
2105
Paul E. McKenneye5601402012-01-07 11:03:57 -08002106static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002107{
2108}
2109
2110#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
2111
2112/*
2113 * Invoke any RCU callbacks that have made it to the end of their grace
2114 * period. Thottle as specified by rdp->blimit.
2115 */
Paul E. McKenney37c72e52009-10-14 10:15:55 -07002116static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002117{
2118 unsigned long flags;
2119 struct rcu_head *next, *list, **tail;
Eric Dumazet878d7432012-10-18 04:55:36 -07002120 long bl, count, count_lazy;
2121 int i;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002122
Paul E. McKenneydc35c892012-12-03 13:52:00 -08002123 /* If no callbacks are ready, just return. */
Paul E. McKenney29c00b42011-06-17 15:53:19 -07002124 if (!cpu_has_callbacks_ready_to_invoke(rdp)) {
Paul E. McKenney486e2592012-01-06 14:11:30 -08002125 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, 0);
Paul E. McKenney4968c302011-12-07 16:32:40 -08002126 trace_rcu_batch_end(rsp->name, 0, !!ACCESS_ONCE(rdp->nxtlist),
2127 need_resched(), is_idle_task(current),
2128 rcu_is_callbacks_kthread());
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002129 return;
Paul E. McKenney29c00b42011-06-17 15:53:19 -07002130 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002131
2132 /*
2133 * Extract the list of ready callbacks, disabling to prevent
2134 * races with call_rcu() from interrupt handlers.
2135 */
2136 local_irq_save(flags);
Paul E. McKenney8146c4e22012-01-10 14:23:29 -08002137 WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
Paul E. McKenney29c00b42011-06-17 15:53:19 -07002138 bl = rdp->blimit;
Paul E. McKenney486e2592012-01-06 14:11:30 -08002139 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, bl);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002140 list = rdp->nxtlist;
2141 rdp->nxtlist = *rdp->nxttail[RCU_DONE_TAIL];
2142 *rdp->nxttail[RCU_DONE_TAIL] = NULL;
2143 tail = rdp->nxttail[RCU_DONE_TAIL];
Paul E. McKenneyb41772a2012-06-21 20:50:42 -07002144 for (i = RCU_NEXT_SIZE - 1; i >= 0; i--)
2145 if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
2146 rdp->nxttail[i] = &rdp->nxtlist;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002147 local_irq_restore(flags);
2148
2149 /* Invoke callbacks. */
Paul E. McKenney486e2592012-01-06 14:11:30 -08002150 count = count_lazy = 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002151 while (list) {
2152 next = list->next;
2153 prefetch(next);
Mathieu Desnoyers551d55a2010-04-17 08:48:42 -04002154 debug_rcu_head_unqueue(list);
Paul E. McKenney486e2592012-01-06 14:11:30 -08002155 if (__rcu_reclaim(rsp->name, list))
2156 count_lazy++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002157 list = next;
Paul E. McKenneydff16722011-11-29 15:57:13 -08002158 /* Stop only if limit reached and CPU has something to do. */
2159 if (++count >= bl &&
2160 (need_resched() ||
2161 (!is_idle_task(current) && !rcu_is_callbacks_kthread())))
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002162 break;
2163 }
2164
2165 local_irq_save(flags);
Paul E. McKenney4968c302011-12-07 16:32:40 -08002166 trace_rcu_batch_end(rsp->name, count, !!list, need_resched(),
2167 is_idle_task(current),
2168 rcu_is_callbacks_kthread());
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002169
2170 /* Update count, and requeue any remaining callbacks. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002171 if (list != NULL) {
2172 *tail = rdp->nxtlist;
2173 rdp->nxtlist = list;
Paul E. McKenneyb41772a2012-06-21 20:50:42 -07002174 for (i = 0; i < RCU_NEXT_SIZE; i++)
2175 if (&rdp->nxtlist == rdp->nxttail[i])
2176 rdp->nxttail[i] = tail;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002177 else
2178 break;
2179 }
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002180 smp_mb(); /* List handling before counting for rcu_barrier(). */
2181 rdp->qlen_lazy -= count_lazy;
Paul E. McKenney1d1fb392012-05-09 15:44:42 -07002182 ACCESS_ONCE(rdp->qlen) -= count;
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002183 rdp->n_cbs_invoked += count;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002184
2185 /* Reinstate batch limit if we have worked down the excess. */
2186 if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark)
2187 rdp->blimit = blimit;
2188
Paul E. McKenney37c72e52009-10-14 10:15:55 -07002189 /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */
2190 if (rdp->qlen == 0 && rdp->qlen_last_fqs_check != 0) {
2191 rdp->qlen_last_fqs_check = 0;
2192 rdp->n_force_qs_snap = rsp->n_force_qs;
2193 } else if (rdp->qlen < rdp->qlen_last_fqs_check - qhimark)
2194 rdp->qlen_last_fqs_check = rdp->qlen;
Paul E. McKenneycfca9272012-06-25 12:54:17 -07002195 WARN_ON_ONCE((rdp->nxtlist == NULL) != (rdp->qlen == 0));
Paul E. McKenney37c72e52009-10-14 10:15:55 -07002196
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002197 local_irq_restore(flags);
2198
Paul E. McKenneye0f23062011-06-21 01:29:39 -07002199 /* Re-invoke RCU core processing if there are callbacks remaining. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002200 if (cpu_has_callbacks_ready_to_invoke(rdp))
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002201 invoke_rcu_core();
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002202}
2203
2204/*
2205 * Check to see if this CPU is in a non-context-switch quiescent state
2206 * (user mode or idle loop for rcu, non-softirq execution for rcu_bh).
Paul E. McKenneye0f23062011-06-21 01:29:39 -07002207 * Also schedule RCU core processing.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002208 *
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -07002209 * This function must be called from hardirq context. It is normally
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002210 * invoked from the scheduling-clock interrupt. If rcu_pending returns
2211 * false, there is no point in invoking rcu_check_callbacks().
2212 */
2213void rcu_check_callbacks(int cpu, int user)
2214{
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04002215 trace_rcu_utilization(TPS("Start scheduler-tick"));
Paul E. McKenneya858af22012-01-16 13:29:10 -08002216 increment_cpu_stall_ticks();
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -07002217 if (user || rcu_is_cpu_rrupt_from_idle()) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002218
2219 /*
2220 * Get here if this CPU took its interrupt from user
2221 * mode or from the idle loop, and if this is not a
2222 * nested interrupt. In this case, the CPU is in
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002223 * a quiescent state, so note it.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002224 *
2225 * No memory barrier is required here because both
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002226 * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local
2227 * variables that other CPUs neither access nor modify,
2228 * at least not while the corresponding CPU is online.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002229 */
2230
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002231 rcu_sched_qs(cpu);
2232 rcu_bh_qs(cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002233
2234 } else if (!in_softirq()) {
2235
2236 /*
2237 * Get here if this CPU did not take its interrupt from
2238 * softirq, in other words, if it is not interrupting
2239 * a rcu_bh read-side critical section. This is an _bh
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002240 * critical section, so note it.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002241 */
2242
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002243 rcu_bh_qs(cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002244 }
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07002245 rcu_preempt_check_callbacks(cpu);
Paul E. McKenneyd21670a2010-04-14 17:39:26 -07002246 if (rcu_pending(cpu))
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002247 invoke_rcu_core();
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04002248 trace_rcu_utilization(TPS("End scheduler-tick"));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002249}
2250
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002251/*
2252 * Scan the leaf rcu_node structures, processing dyntick state for any that
2253 * have not yet encountered a quiescent state, using the function specified.
Paul E. McKenney27f4d282011-02-07 12:47:15 -08002254 * Also initiate boosting for any threads blocked on the root rcu_node.
2255 *
Paul E. McKenneyee47eb92010-01-04 15:09:07 -08002256 * The caller must have suppressed start of new grace periods.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002257 */
Paul E. McKenney217af2a2013-06-21 15:39:06 -07002258static void force_qs_rnp(struct rcu_state *rsp,
2259 int (*f)(struct rcu_data *rsp, bool *isidle,
2260 unsigned long *maxj),
2261 bool *isidle, unsigned long *maxj)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002262{
2263 unsigned long bit;
2264 int cpu;
2265 unsigned long flags;
2266 unsigned long mask;
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -07002267 struct rcu_node *rnp;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002268
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -07002269 rcu_for_each_leaf_node(rsp, rnp) {
Paul E. McKenneyb4be093f2012-06-25 08:41:11 -07002270 cond_resched();
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002271 mask = 0;
Paul E. McKenney1304afb2010-02-22 17:05:02 -08002272 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08002273 smp_mb__after_unlock_lock();
Paul E. McKenneyee47eb92010-01-04 15:09:07 -08002274 if (!rcu_gp_in_progress(rsp)) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -08002275 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney0f10dc822010-01-04 15:09:06 -08002276 return;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002277 }
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -07002278 if (rnp->qsmask == 0) {
Paul E. McKenney1217ed12011-05-04 21:43:49 -07002279 rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002280 continue;
2281 }
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -07002282 cpu = rnp->grplo;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002283 bit = 1;
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -07002284 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
Paul E. McKenney0edd1b12013-06-21 16:37:22 -07002285 if ((rnp->qsmask & bit) != 0) {
2286 if ((rnp->qsmaskinit & bit) != 0)
2287 *isidle = 0;
2288 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj))
2289 mask |= bit;
2290 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002291 }
Paul E. McKenney45f014c52e2010-01-04 15:09:08 -08002292 if (mask != 0) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002293
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -08002294 /* rcu_report_qs_rnp() releases rnp->lock. */
2295 rcu_report_qs_rnp(mask, rsp, rnp, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002296 continue;
2297 }
Paul E. McKenney1304afb2010-02-22 17:05:02 -08002298 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002299 }
Paul E. McKenney27f4d282011-02-07 12:47:15 -08002300 rnp = rcu_get_root(rsp);
Paul E. McKenney1217ed12011-05-04 21:43:49 -07002301 if (rnp->qsmask == 0) {
2302 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08002303 smp_mb__after_unlock_lock();
Paul E. McKenney1217ed12011-05-04 21:43:49 -07002304 rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */
2305 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002306}
2307
2308/*
2309 * Force quiescent states on reluctant CPUs, and also detect which
2310 * CPUs are in dyntick-idle mode.
2311 */
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07002312static void force_quiescent_state(struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002313{
2314 unsigned long flags;
Paul E. McKenney394f2762012-06-26 17:00:35 -07002315 bool ret;
2316 struct rcu_node *rnp;
2317 struct rcu_node *rnp_old = NULL;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002318
Paul E. McKenney394f2762012-06-26 17:00:35 -07002319 /* Funnel through hierarchy to reduce memory contention. */
2320 rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
2321 for (; rnp != NULL; rnp = rnp->parent) {
2322 ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
2323 !raw_spin_trylock(&rnp->fqslock);
2324 if (rnp_old != NULL)
2325 raw_spin_unlock(&rnp_old->fqslock);
2326 if (ret) {
Paul E. McKenney3660c282013-12-03 09:24:02 -08002327 ACCESS_ONCE(rsp->n_force_qs_lh)++;
Paul E. McKenney394f2762012-06-26 17:00:35 -07002328 return;
2329 }
2330 rnp_old = rnp;
2331 }
2332 /* rnp_old == rcu_get_root(rsp), rnp == NULL. */
2333
2334 /* Reached the root of the rcu_node tree, acquire lock. */
2335 raw_spin_lock_irqsave(&rnp_old->lock, flags);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08002336 smp_mb__after_unlock_lock();
Paul E. McKenney394f2762012-06-26 17:00:35 -07002337 raw_spin_unlock(&rnp_old->fqslock);
2338 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
Paul E. McKenney3660c282013-12-03 09:24:02 -08002339 ACCESS_ONCE(rsp->n_force_qs_lh)++;
Paul E. McKenney394f2762012-06-26 17:00:35 -07002340 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07002341 return; /* Someone beat us to it. */
Paul E. McKenney46a1e342010-01-04 15:09:09 -08002342 }
Paul E. McKenney91dc9542014-02-18 09:47:13 -08002343 ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
Paul E. McKenney394f2762012-06-26 17:00:35 -07002344 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07002345 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002346}
2347
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002348/*
Paul E. McKenneye0f23062011-06-21 01:29:39 -07002349 * This does the RCU core processing work for the specified rcu_state
2350 * and rcu_data structures. This may be called only from the CPU to
2351 * whom the rdp belongs.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002352 */
2353static void
Paul E. McKenney1bca8cf2012-06-12 09:40:38 -07002354__rcu_process_callbacks(struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002355{
2356 unsigned long flags;
Paul E. McKenney1bca8cf2012-06-12 09:40:38 -07002357 struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002358
Paul E. McKenney2e597552009-08-15 09:53:48 -07002359 WARN_ON_ONCE(rdp->beenonline == 0);
2360
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002361 /* Update RCU state based on any recent quiescent states. */
2362 rcu_check_quiescent_state(rsp, rdp);
2363
2364 /* Does this CPU require a not-yet-started grace period? */
Paul E. McKenneydc35c892012-12-03 13:52:00 -08002365 local_irq_save(flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002366 if (cpu_needs_another_gp(rsp, rdp)) {
Paul E. McKenneydc35c892012-12-03 13:52:00 -08002367 raw_spin_lock(&rcu_get_root(rsp)->lock); /* irqs disabled. */
Paul E. McKenneyb8462082012-12-29 22:04:18 -08002368 rcu_start_gp(rsp);
2369 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
Paul E. McKenneydc35c892012-12-03 13:52:00 -08002370 } else {
2371 local_irq_restore(flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002372 }
2373
2374 /* If there are callbacks ready, invoke them. */
Shaohua Li09223372011-06-14 13:26:25 +08002375 if (cpu_has_callbacks_ready_to_invoke(rdp))
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002376 invoke_rcu_callbacks(rsp, rdp);
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07002377
2378 /* Do any needed deferred wakeups of rcuo kthreads. */
2379 do_nocb_deferred_wakeup(rdp);
Shaohua Li09223372011-06-14 13:26:25 +08002380}
2381
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002382/*
Paul E. McKenneye0f23062011-06-21 01:29:39 -07002383 * Do RCU core processing for the current CPU.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002384 */
Shaohua Li09223372011-06-14 13:26:25 +08002385static void rcu_process_callbacks(struct softirq_action *unused)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002386{
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07002387 struct rcu_state *rsp;
2388
Paul E. McKenneybfa00b42012-06-21 09:54:10 -07002389 if (cpu_is_offline(smp_processor_id()))
2390 return;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04002391 trace_rcu_utilization(TPS("Start RCU core"));
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07002392 for_each_rcu_flavor(rsp)
2393 __rcu_process_callbacks(rsp);
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04002394 trace_rcu_utilization(TPS("End RCU core"));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002395}
2396
Paul E. McKenneya26ac242011-01-12 14:10:23 -08002397/*
Paul E. McKenneye0f23062011-06-21 01:29:39 -07002398 * Schedule RCU callback invocation. If the specified type of RCU
2399 * does not support RCU priority boosting, just do a direct call,
2400 * otherwise wake up the per-CPU kernel kthread. Note that because we
2401 * are running on the current CPU with interrupts disabled, the
2402 * rcu_cpu_kthread_task cannot disappear out from under us.
Paul E. McKenneya26ac242011-01-12 14:10:23 -08002403 */
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002404static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
Paul E. McKenneya26ac242011-01-12 14:10:23 -08002405{
Paul E. McKenneyb0d30412011-07-10 15:57:35 -07002406 if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active)))
2407 return;
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002408 if (likely(!rsp->boost)) {
2409 rcu_do_batch(rsp, rdp);
Paul E. McKenneya26ac242011-01-12 14:10:23 -08002410 return;
2411 }
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002412 invoke_rcu_callbacks_kthread();
Paul E. McKenneya26ac242011-01-12 14:10:23 -08002413}
2414
Paul E. McKenneya46e0892011-06-15 15:47:09 -07002415static void invoke_rcu_core(void)
Shaohua Li09223372011-06-14 13:26:25 +08002416{
Paul E. McKenneyb0f74032013-02-04 12:14:24 -08002417 if (cpu_online(smp_processor_id()))
2418 raise_softirq(RCU_SOFTIRQ);
Shaohua Li09223372011-06-14 13:26:25 +08002419}
2420
Paul E. McKenney29154c52012-05-30 03:21:48 -07002421/*
2422 * Handle any core-RCU processing required by a call_rcu() invocation.
2423 */
2424static void __call_rcu_core(struct rcu_state *rsp, struct rcu_data *rdp,
2425 struct rcu_head *head, unsigned long flags)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002426{
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002427 /*
Paul E. McKenney29154c52012-05-30 03:21:48 -07002428 * If called from an extended quiescent state, invoke the RCU
2429 * core in order to force a re-evaluation of RCU's idleness.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002430 */
Paul E. McKenney5c173eb2013-09-13 17:20:11 -07002431 if (!rcu_is_watching() && cpu_online(smp_processor_id()))
Paul E. McKenney29154c52012-05-30 03:21:48 -07002432 invoke_rcu_core();
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002433
Paul E. McKenney29154c52012-05-30 03:21:48 -07002434 /* If interrupts were disabled or CPU offline, don't invoke RCU core. */
2435 if (irqs_disabled_flags(flags) || cpu_is_offline(smp_processor_id()))
Paul E. McKenney2655d572011-04-07 22:47:23 -07002436 return;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002437
Paul E. McKenney37c72e52009-10-14 10:15:55 -07002438 /*
2439 * Force the grace period if too many callbacks or too long waiting.
2440 * Enforce hysteresis, and don't invoke force_quiescent_state()
2441 * if some other CPU has recently done so. Also, don't bother
2442 * invoking force_quiescent_state() if the newly enqueued callback
2443 * is the only one waiting for a grace period to complete.
2444 */
Paul E. McKenney2655d572011-04-07 22:47:23 -07002445 if (unlikely(rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) {
Paul E. McKenneyb52573d2010-12-14 17:36:02 -08002446
2447 /* Are we ignoring a completed grace period? */
Paul E. McKenney470716f2013-03-19 11:32:11 -07002448 note_gp_changes(rsp, rdp);
Paul E. McKenneyb52573d2010-12-14 17:36:02 -08002449
2450 /* Start a new grace period if one not already started. */
2451 if (!rcu_gp_in_progress(rsp)) {
Paul E. McKenneyb52573d2010-12-14 17:36:02 -08002452 struct rcu_node *rnp_root = rcu_get_root(rsp);
2453
Paul E. McKenneyb8462082012-12-29 22:04:18 -08002454 raw_spin_lock(&rnp_root->lock);
Paul E. McKenney6303b9c2013-12-11 13:59:10 -08002455 smp_mb__after_unlock_lock();
Paul E. McKenneyb8462082012-12-29 22:04:18 -08002456 rcu_start_gp(rsp);
2457 raw_spin_unlock(&rnp_root->lock);
Paul E. McKenneyb52573d2010-12-14 17:36:02 -08002458 } else {
2459 /* Give the grace period a kick. */
2460 rdp->blimit = LONG_MAX;
2461 if (rsp->n_force_qs == rdp->n_force_qs_snap &&
2462 *rdp->nxttail[RCU_DONE_TAIL] != head)
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07002463 force_quiescent_state(rsp);
Paul E. McKenneyb52573d2010-12-14 17:36:02 -08002464 rdp->n_force_qs_snap = rsp->n_force_qs;
2465 rdp->qlen_last_fqs_check = rdp->qlen;
2466 }
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -07002467 }
Paul E. McKenney29154c52012-05-30 03:21:48 -07002468}
2469
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002470/*
Paul E. McKenneyae150182013-04-23 13:20:57 -07002471 * RCU callback function to leak a callback.
2472 */
2473static void rcu_leak_callback(struct rcu_head *rhp)
2474{
2475}
2476
2477/*
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002478 * Helper function for call_rcu() and friends. The cpu argument will
2479 * normally be -1, indicating "currently running CPU". It may specify
2480 * a CPU only if that CPU is a no-CBs CPU. Currently, only _rcu_barrier()
2481 * is expected to specify a CPU.
2482 */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002483static void
2484__call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002485 struct rcu_state *rsp, int cpu, bool lazy)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002486{
2487 unsigned long flags;
2488 struct rcu_data *rdp;
2489
2490 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
Paul E. McKenneyae150182013-04-23 13:20:57 -07002491 if (debug_rcu_head_queue(head)) {
2492 /* Probable double call_rcu(), so leak the callback. */
2493 ACCESS_ONCE(head->func) = rcu_leak_callback;
2494 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
2495 return;
2496 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002497 head->func = func;
2498 head->next = NULL;
2499
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002500 /*
2501 * Opportunistically note grace-period endings and beginnings.
2502 * Note that we might see a beginning right after we see an
2503 * end, but never vice versa, since this CPU has to pass through
2504 * a quiescent state betweentimes.
2505 */
2506 local_irq_save(flags);
2507 rdp = this_cpu_ptr(rsp->rda);
2508
2509 /* Add the callback to our list. */
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002510 if (unlikely(rdp->nxttail[RCU_NEXT_TAIL] == NULL) || cpu != -1) {
2511 int offline;
2512
2513 if (cpu != -1)
2514 rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07002515 offline = !__call_rcu_nocb(rdp, head, lazy, flags);
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002516 WARN_ON_ONCE(offline);
Paul E. McKenney0d8ee372012-08-03 13:16:15 -07002517 /* _call_rcu() is illegal on offline CPU; leak the callback. */
Paul E. McKenney0d8ee372012-08-03 13:16:15 -07002518 local_irq_restore(flags);
2519 return;
2520 }
Paul E. McKenney1d1fb392012-05-09 15:44:42 -07002521 ACCESS_ONCE(rdp->qlen)++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002522 if (lazy)
2523 rdp->qlen_lazy++;
2524 else
2525 rcu_idle_count_callbacks_posted();
2526 smp_mb(); /* Count before adding callback for rcu_barrier(). */
2527 *rdp->nxttail[RCU_NEXT_TAIL] = head;
2528 rdp->nxttail[RCU_NEXT_TAIL] = &head->next;
2529
2530 if (__is_kfree_rcu_offset((unsigned long)func))
2531 trace_rcu_kfree_callback(rsp->name, head, (unsigned long)func,
2532 rdp->qlen_lazy, rdp->qlen);
2533 else
2534 trace_rcu_callback(rsp->name, head, rdp->qlen_lazy, rdp->qlen);
2535
Paul E. McKenney29154c52012-05-30 03:21:48 -07002536 /* Go handle any RCU core processing required. */
2537 __call_rcu_core(rsp, rdp, head, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002538 local_irq_restore(flags);
2539}
2540
2541/*
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002542 * Queue an RCU-sched callback for invocation after a grace period.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002543 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002544void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002545{
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002546 __call_rcu(head, func, &rcu_sched_state, -1, 0);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002547}
Paul E. McKenneyd6714c22009-08-22 13:56:46 -07002548EXPORT_SYMBOL_GPL(call_rcu_sched);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002549
2550/*
Paul E. McKenney486e2592012-01-06 14:11:30 -08002551 * Queue an RCU callback for invocation after a quicker grace period.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002552 */
2553void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
2554{
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07002555 __call_rcu(head, func, &rcu_bh_state, -1, 0);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002556}
2557EXPORT_SYMBOL_GPL(call_rcu_bh);
2558
Paul E. McKenney6d813392012-02-23 13:30:16 -08002559/*
2560 * Because a context switch is a grace period for RCU-sched and RCU-bh,
2561 * any blocking grace-period wait automatically implies a grace period
2562 * if there is only one CPU online at any point time during execution
2563 * of either synchronize_sched() or synchronize_rcu_bh(). It is OK to
2564 * occasionally incorrectly indicate that there are multiple CPUs online
2565 * when there was in fact only one the whole time, as this just adds
2566 * some overhead: RCU still operates correctly.
Paul E. McKenney6d813392012-02-23 13:30:16 -08002567 */
2568static inline int rcu_blocking_is_gp(void)
2569{
Paul E. McKenney95f0c1d2012-06-19 11:58:27 -07002570 int ret;
2571
Paul E. McKenney6d813392012-02-23 13:30:16 -08002572 might_sleep(); /* Check for RCU read-side critical section. */
Paul E. McKenney95f0c1d2012-06-19 11:58:27 -07002573 preempt_disable();
2574 ret = num_online_cpus() <= 1;
2575 preempt_enable();
2576 return ret;
Paul E. McKenney6d813392012-02-23 13:30:16 -08002577}
2578
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002579/**
2580 * synchronize_sched - wait until an rcu-sched grace period has elapsed.
2581 *
2582 * Control will return to the caller some time after a full rcu-sched
2583 * grace period has elapsed, in other words after all currently executing
2584 * rcu-sched read-side critical sections have completed. These read-side
2585 * critical sections are delimited by rcu_read_lock_sched() and
2586 * rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(),
2587 * local_irq_disable(), and so on may be used in place of
2588 * rcu_read_lock_sched().
2589 *
2590 * This means that all preempt_disable code sequences, including NMI and
Paul E. McKenneyf0a0e6f2012-10-23 13:47:01 -07002591 * non-threaded hardware-interrupt handlers, in progress on entry will
2592 * have completed before this primitive returns. However, this does not
2593 * guarantee that softirq handlers will have completed, since in some
2594 * kernels, these handlers can run in process context, and can block.
2595 *
2596 * Note that this guarantee implies further memory-ordering guarantees.
2597 * On systems with more than one CPU, when synchronize_sched() returns,
2598 * each CPU is guaranteed to have executed a full memory barrier since the
2599 * end of its last RCU-sched read-side critical section whose beginning
2600 * preceded the call to synchronize_sched(). In addition, each CPU having
2601 * an RCU read-side critical section that extends beyond the return from
2602 * synchronize_sched() is guaranteed to have executed a full memory barrier
2603 * after the beginning of synchronize_sched() and before the beginning of
2604 * that RCU read-side critical section. Note that these guarantees include
2605 * CPUs that are offline, idle, or executing in user mode, as well as CPUs
2606 * that are executing in the kernel.
2607 *
2608 * Furthermore, if CPU A invoked synchronize_sched(), which returned
2609 * to its caller on CPU B, then both CPU A and CPU B are guaranteed
2610 * to have executed a full memory barrier during the execution of
2611 * synchronize_sched() -- even if CPU A and CPU B are the same CPU (but
2612 * again only if the system has more than one CPU).
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002613 *
2614 * This primitive provides the guarantees made by the (now removed)
2615 * synchronize_kernel() API. In contrast, synchronize_rcu() only
2616 * guarantees that rcu_read_lock() sections will have completed.
2617 * In "classic RCU", these two guarantees happen to be one and
2618 * the same, but can differ in realtime RCU implementations.
2619 */
2620void synchronize_sched(void)
2621{
Paul E. McKenneyfe15d702012-01-04 13:30:33 -08002622 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
2623 !lock_is_held(&rcu_lock_map) &&
2624 !lock_is_held(&rcu_sched_lock_map),
2625 "Illegal synchronize_sched() in RCU-sched read-side critical section");
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002626 if (rcu_blocking_is_gp())
2627 return;
Antti P Miettinen3705b882012-10-05 09:59:15 +03002628 if (rcu_expedited)
2629 synchronize_sched_expedited();
2630 else
2631 wait_rcu_gp(call_rcu_sched);
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002632}
2633EXPORT_SYMBOL_GPL(synchronize_sched);
2634
2635/**
2636 * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
2637 *
2638 * Control will return to the caller some time after a full rcu_bh grace
2639 * period has elapsed, in other words after all currently executing rcu_bh
2640 * read-side critical sections have completed. RCU read-side critical
2641 * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(),
2642 * and may be nested.
Paul E. McKenneyf0a0e6f2012-10-23 13:47:01 -07002643 *
2644 * See the description of synchronize_sched() for more detailed information
2645 * on memory ordering guarantees.
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002646 */
2647void synchronize_rcu_bh(void)
2648{
Paul E. McKenneyfe15d702012-01-04 13:30:33 -08002649 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
2650 !lock_is_held(&rcu_lock_map) &&
2651 !lock_is_held(&rcu_sched_lock_map),
2652 "Illegal synchronize_rcu_bh() in RCU-bh read-side critical section");
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002653 if (rcu_blocking_is_gp())
2654 return;
Antti P Miettinen3705b882012-10-05 09:59:15 +03002655 if (rcu_expedited)
2656 synchronize_rcu_bh_expedited();
2657 else
2658 wait_rcu_gp(call_rcu_bh);
Paul E. McKenney6ebb2372009-11-22 08:53:50 -08002659}
2660EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
2661
Paul E. McKenney765a3f42014-03-14 16:37:08 -07002662/**
2663 * get_state_synchronize_rcu - Snapshot current RCU state
2664 *
2665 * Returns a cookie that is used by a later call to cond_synchronize_rcu()
2666 * to determine whether or not a full grace period has elapsed in the
2667 * meantime.
2668 */
2669unsigned long get_state_synchronize_rcu(void)
2670{
2671 /*
2672 * Any prior manipulation of RCU-protected data must happen
2673 * before the load from ->gpnum.
2674 */
2675 smp_mb(); /* ^^^ */
2676
2677 /*
2678 * Make sure this load happens before the purportedly
2679 * time-consuming work between get_state_synchronize_rcu()
2680 * and cond_synchronize_rcu().
2681 */
2682 return smp_load_acquire(&rcu_state->gpnum);
2683}
2684EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
2685
2686/**
2687 * cond_synchronize_rcu - Conditionally wait for an RCU grace period
2688 *
2689 * @oldstate: return value from earlier call to get_state_synchronize_rcu()
2690 *
2691 * If a full RCU grace period has elapsed since the earlier call to
2692 * get_state_synchronize_rcu(), just return. Otherwise, invoke
2693 * synchronize_rcu() to wait for a full grace period.
2694 *
2695 * Yes, this function does not take counter wrap into account. But
2696 * counter wrap is harmless. If the counter wraps, we have waited for
2697 * more than 2 billion grace periods (and way more on a 64-bit system!),
2698 * so waiting for one additional grace period should be just fine.
2699 */
2700void cond_synchronize_rcu(unsigned long oldstate)
2701{
2702 unsigned long newstate;
2703
2704 /*
2705 * Ensure that this load happens before any RCU-destructive
2706 * actions the caller might carry out after we return.
2707 */
2708 newstate = smp_load_acquire(&rcu_state->completed);
2709 if (ULONG_CMP_GE(oldstate, newstate))
2710 synchronize_rcu();
2711}
2712EXPORT_SYMBOL_GPL(cond_synchronize_rcu);
2713
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002714static int synchronize_sched_expedited_cpu_stop(void *data)
2715{
2716 /*
2717 * There must be a full memory barrier on each affected CPU
2718 * between the time that try_stop_cpus() is called and the
2719 * time that it returns.
2720 *
2721 * In the current initial implementation of cpu_stop, the
2722 * above condition is already met when the control reaches
2723 * this point and the following smp_mb() is not strictly
2724 * necessary. Do smp_mb() anyway for documentation and
2725 * robustness against future implementation changes.
2726 */
2727 smp_mb(); /* See above comment block. */
2728 return 0;
2729}
2730
Paul E. McKenney236fefa2012-01-31 14:00:41 -08002731/**
2732 * synchronize_sched_expedited - Brute-force RCU-sched grace period
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002733 *
Paul E. McKenney236fefa2012-01-31 14:00:41 -08002734 * Wait for an RCU-sched grace period to elapse, but use a "big hammer"
2735 * approach to force the grace period to end quickly. This consumes
2736 * significant time on all CPUs and is unfriendly to real-time workloads,
2737 * so is thus not recommended for any sort of common-case code. In fact,
2738 * if you are using synchronize_sched_expedited() in a loop, please
2739 * restructure your code to batch your updates, and then use a single
2740 * synchronize_sched() instead.
2741 *
2742 * Note that it is illegal to call this function while holding any lock
2743 * that is acquired by a CPU-hotplug notifier. And yes, it is also illegal
2744 * to call this function from a CPU-hotplug notifier. Failing to observe
2745 * these restriction will result in deadlock.
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002746 *
2747 * This implementation can be thought of as an application of ticket
2748 * locking to RCU, with sync_sched_expedited_started and
2749 * sync_sched_expedited_done taking on the roles of the halves
2750 * of the ticket-lock word. Each task atomically increments
2751 * sync_sched_expedited_started upon entry, snapshotting the old value,
2752 * then attempts to stop all the CPUs. If this succeeds, then each
2753 * CPU will have executed a context switch, resulting in an RCU-sched
2754 * grace period. We are then done, so we use atomic_cmpxchg() to
2755 * update sync_sched_expedited_done to match our snapshot -- but
2756 * only if someone else has not already advanced past our snapshot.
2757 *
2758 * On the other hand, if try_stop_cpus() fails, we check the value
2759 * of sync_sched_expedited_done. If it has advanced past our
2760 * initial snapshot, then someone else must have forced a grace period
2761 * some time after we took our snapshot. In this case, our work is
2762 * done for us, and we can simply return. Otherwise, we try again,
2763 * but keep our initial snapshot for purposes of checking for someone
2764 * doing our work for us.
2765 *
2766 * If we fail too many times in a row, we fall back to synchronize_sched().
2767 */
2768void synchronize_sched_expedited(void)
2769{
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002770 long firstsnap, s, snap;
2771 int trycount = 0;
Paul E. McKenney40694d62012-10-11 15:24:03 -07002772 struct rcu_state *rsp = &rcu_sched_state;
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002773
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002774 /*
2775 * If we are in danger of counter wrap, just do synchronize_sched().
2776 * By allowing sync_sched_expedited_started to advance no more than
2777 * ULONG_MAX/8 ahead of sync_sched_expedited_done, we are ensuring
2778 * that more than 3.5 billion CPUs would be required to force a
2779 * counter wrap on a 32-bit system. Quite a few more CPUs would of
2780 * course be required on a 64-bit system.
2781 */
Paul E. McKenney40694d62012-10-11 15:24:03 -07002782 if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
2783 (ulong)atomic_long_read(&rsp->expedited_done) +
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002784 ULONG_MAX / 8)) {
2785 synchronize_sched();
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002786 atomic_long_inc(&rsp->expedited_wrap);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002787 return;
2788 }
2789
2790 /*
2791 * Take a ticket. Note that atomic_inc_return() implies a
2792 * full memory barrier.
2793 */
Paul E. McKenney40694d62012-10-11 15:24:03 -07002794 snap = atomic_long_inc_return(&rsp->expedited_start);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002795 firstsnap = snap;
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002796 get_online_cpus();
Hugh Dickins1cc85962012-02-17 13:20:31 -08002797 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002798
2799 /*
2800 * Each pass through the following loop attempts to force a
2801 * context switch on each CPU.
2802 */
2803 while (try_stop_cpus(cpu_online_mask,
2804 synchronize_sched_expedited_cpu_stop,
2805 NULL) == -EAGAIN) {
2806 put_online_cpus();
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002807 atomic_long_inc(&rsp->expedited_tryfail);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002808
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002809 /* Check to see if someone else did our work for us. */
Paul E. McKenney40694d62012-10-11 15:24:03 -07002810 s = atomic_long_read(&rsp->expedited_done);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002811 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002812 /* ensure test happens before caller kfree */
2813 smp_mb__before_atomic_inc(); /* ^^^ */
2814 atomic_long_inc(&rsp->expedited_workdone1);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002815 return;
2816 }
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002817
2818 /* No joy, try again later. Or just synchronize_sched(). */
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -07002819 if (trycount++ < 10) {
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002820 udelay(trycount * num_online_cpus());
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -07002821 } else {
Antti P Miettinen3705b882012-10-05 09:59:15 +03002822 wait_rcu_gp(call_rcu_sched);
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002823 atomic_long_inc(&rsp->expedited_normal);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002824 return;
2825 }
2826
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002827 /* Recheck to see if someone else did our work for us. */
Paul E. McKenney40694d62012-10-11 15:24:03 -07002828 s = atomic_long_read(&rsp->expedited_done);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002829 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002830 /* ensure test happens before caller kfree */
2831 smp_mb__before_atomic_inc(); /* ^^^ */
2832 atomic_long_inc(&rsp->expedited_workdone2);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002833 return;
2834 }
2835
2836 /*
2837 * Refetching sync_sched_expedited_started allows later
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002838 * callers to piggyback on our grace period. We retry
2839 * after they started, so our grace period works for them,
2840 * and they started after our first try, so their grace
2841 * period works for us.
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002842 */
2843 get_online_cpus();
Paul E. McKenney40694d62012-10-11 15:24:03 -07002844 snap = atomic_long_read(&rsp->expedited_start);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002845 smp_mb(); /* ensure read is before try_stop_cpus(). */
2846 }
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002847 atomic_long_inc(&rsp->expedited_stoppedcpus);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002848
2849 /*
2850 * Everyone up to our most recent fetch is covered by our grace
2851 * period. Update the counter, but only if our work is still
2852 * relevant -- which it won't be if someone who started later
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002853 * than we did already did their update.
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002854 */
2855 do {
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002856 atomic_long_inc(&rsp->expedited_done_tries);
Paul E. McKenney40694d62012-10-11 15:24:03 -07002857 s = atomic_long_read(&rsp->expedited_done);
Paul E. McKenney1924bcb2012-10-11 12:30:37 -07002858 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002859 /* ensure test happens before caller kfree */
2860 smp_mb__before_atomic_inc(); /* ^^^ */
2861 atomic_long_inc(&rsp->expedited_done_lost);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002862 break;
2863 }
Paul E. McKenney40694d62012-10-11 15:24:03 -07002864 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
Paul E. McKenneya30489c2012-10-11 16:18:09 -07002865 atomic_long_inc(&rsp->expedited_done_exit);
Paul E. McKenney3d3b7db2012-01-23 17:05:46 -08002866
2867 put_online_cpus();
2868}
2869EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
2870
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002871/*
2872 * Check to see if there is any immediate RCU-related work to be done
2873 * by the current CPU, for the specified type of RCU, returning 1 if so.
2874 * The checks are in order of increasing expense: checks that can be
2875 * carried out against CPU-local state are performed first. However,
2876 * we must check for CPU stalls first, else we might not get a chance.
2877 */
2878static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
2879{
Paul E. McKenney2f51f982009-11-13 19:51:39 -08002880 struct rcu_node *rnp = rdp->mynode;
2881
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002882 rdp->n_rcu_pending++;
2883
2884 /* Check for CPU stalls, if enabled. */
2885 check_cpu_stall(rsp, rdp);
2886
Paul E. McKenneya0969322013-11-08 09:03:10 -08002887 /* Is this CPU a NO_HZ_FULL CPU that should ignore RCU? */
2888 if (rcu_nohz_full_cpu(rsp))
2889 return 0;
2890
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002891 /* Is the RCU core waiting for a quiescent state from this CPU? */
Paul E. McKenney5c51dd72011-08-04 06:59:03 -07002892 if (rcu_scheduler_fully_active &&
2893 rdp->qs_pending && !rdp->passed_quiesce) {
Paul E. McKenneyd21670a2010-04-14 17:39:26 -07002894 rdp->n_rp_qs_pending++;
Paul E. McKenneye4cc1f22011-06-27 00:17:43 -07002895 } else if (rdp->qs_pending && rdp->passed_quiesce) {
Paul E. McKenneyd21670a2010-04-14 17:39:26 -07002896 rdp->n_rp_report_qs++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002897 return 1;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002898 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002899
2900 /* Does this CPU have callbacks ready to invoke? */
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002901 if (cpu_has_callbacks_ready_to_invoke(rdp)) {
2902 rdp->n_rp_cb_ready++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002903 return 1;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002904 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002905
2906 /* Has RCU gone idle with this CPU needing another grace period? */
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002907 if (cpu_needs_another_gp(rsp, rdp)) {
2908 rdp->n_rp_cpu_needs_gp++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002909 return 1;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002910 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002911
2912 /* Has another RCU grace period completed? */
Paul E. McKenney2f51f982009-11-13 19:51:39 -08002913 if (ACCESS_ONCE(rnp->completed) != rdp->completed) { /* outside lock */
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002914 rdp->n_rp_gp_completed++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002915 return 1;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002916 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002917
2918 /* Has a new RCU grace period started? */
Paul E. McKenney2f51f982009-11-13 19:51:39 -08002919 if (ACCESS_ONCE(rnp->gpnum) != rdp->gpnum) { /* outside lock */
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002920 rdp->n_rp_gp_started++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002921 return 1;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002922 }
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002923
Paul E. McKenney96d3fd02013-10-04 14:33:34 -07002924 /* Does this CPU need a deferred NOCB wakeup? */
2925 if (rcu_nocb_need_deferred_wakeup(rdp)) {
2926 rdp->n_rp_nocb_defer_wakeup++;
2927 return 1;
2928 }
2929
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002930 /* nothing to do */
Paul E. McKenney7ba5c842009-04-13 21:31:17 -07002931 rdp->n_rp_need_nothing++;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002932 return 0;
2933}
2934
2935/*
2936 * Check to see if there is any immediate RCU-related work to be done
2937 * by the current CPU, returning 1 if so. This function is part of the
2938 * RCU implementation; it is -not- an exported member of the RCU API.
2939 */
Paul E. McKenneya1572292009-08-22 13:56:51 -07002940static int rcu_pending(int cpu)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002941{
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07002942 struct rcu_state *rsp;
2943
2944 for_each_rcu_flavor(rsp)
2945 if (__rcu_pending(rsp, per_cpu_ptr(rsp->rda, cpu)))
2946 return 1;
2947 return 0;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002948}
2949
2950/*
Paul E. McKenneyc0f4dfd2012-12-28 11:30:36 -08002951 * Return true if the specified CPU has any callback. If all_lazy is
2952 * non-NULL, store an indication of whether all callbacks are lazy.
2953 * (If there are no callbacks, all of them are deemed to be lazy.)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002954 */
Paul E. McKenneyffa83fb2013-11-17 19:27:16 -08002955static int __maybe_unused rcu_cpu_has_callbacks(int cpu, bool *all_lazy)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002956{
Paul E. McKenneyc0f4dfd2012-12-28 11:30:36 -08002957 bool al = true;
2958 bool hc = false;
2959 struct rcu_data *rdp;
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07002960 struct rcu_state *rsp;
2961
Paul E. McKenneyc0f4dfd2012-12-28 11:30:36 -08002962 for_each_rcu_flavor(rsp) {
2963 rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenney69c8d282013-09-03 09:52:20 -07002964 if (!rdp->nxtlist)
2965 continue;
2966 hc = true;
2967 if (rdp->qlen != rdp->qlen_lazy || !all_lazy) {
Paul E. McKenneyc0f4dfd2012-12-28 11:30:36 -08002968 al = false;
Paul E. McKenney69c8d282013-09-03 09:52:20 -07002969 break;
2970 }
Paul E. McKenneyc0f4dfd2012-12-28 11:30:36 -08002971 }
2972 if (all_lazy)
2973 *all_lazy = al;
2974 return hc;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01002975}
2976
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002977/*
Paul E. McKenneya83eff02012-05-23 18:47:05 -07002978 * Helper function for _rcu_barrier() tracing. If tracing is disabled,
2979 * the compiler is expected to optimize this away.
2980 */
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04002981static void _rcu_barrier_trace(struct rcu_state *rsp, const char *s,
Paul E. McKenneya83eff02012-05-23 18:47:05 -07002982 int cpu, unsigned long done)
2983{
2984 trace_rcu_barrier(rsp->name, s, cpu,
2985 atomic_read(&rsp->barrier_cpu_count), done);
2986}
2987
2988/*
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08002989 * RCU callback function for _rcu_barrier(). If we are last, wake
2990 * up the task executing _rcu_barrier().
2991 */
Paul E. McKenney24ebbca2012-05-29 00:34:56 -07002992static void rcu_barrier_callback(struct rcu_head *rhp)
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07002993{
Paul E. McKenney24ebbca2012-05-29 00:34:56 -07002994 struct rcu_data *rdp = container_of(rhp, struct rcu_data, barrier_head);
2995 struct rcu_state *rsp = rdp->rsp;
2996
Paul E. McKenneya83eff02012-05-23 18:47:05 -07002997 if (atomic_dec_and_test(&rsp->barrier_cpu_count)) {
2998 _rcu_barrier_trace(rsp, "LastCB", -1, rsp->n_barrier_done);
Paul E. McKenney7db74df2012-05-29 03:03:37 -07002999 complete(&rsp->barrier_completion);
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003000 } else {
3001 _rcu_barrier_trace(rsp, "CB", -1, rsp->n_barrier_done);
3002 }
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003003}
3004
3005/*
3006 * Called with preemption disabled, and from cross-cpu IRQ context.
3007 */
3008static void rcu_barrier_func(void *type)
3009{
Paul E. McKenney037b64e2012-05-28 23:26:01 -07003010 struct rcu_state *rsp = type;
Paul E. McKenney06668ef2012-05-28 23:57:46 -07003011 struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003012
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003013 _rcu_barrier_trace(rsp, "IRQ", -1, rsp->n_barrier_done);
Paul E. McKenney24ebbca2012-05-29 00:34:56 -07003014 atomic_inc(&rsp->barrier_cpu_count);
Paul E. McKenney06668ef2012-05-28 23:57:46 -07003015 rsp->call(&rdp->barrier_head, rcu_barrier_callback);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003016}
3017
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003018/*
3019 * Orchestrate the specified type of RCU barrier, waiting for all
3020 * RCU callbacks of the specified type to complete.
3021 */
Paul E. McKenney037b64e2012-05-28 23:26:01 -07003022static void _rcu_barrier(struct rcu_state *rsp)
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003023{
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003024 int cpu;
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003025 struct rcu_data *rdp;
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003026 unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done);
3027 unsigned long snap_done;
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003028
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003029 _rcu_barrier_trace(rsp, "Begin", -1, snap);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003030
Paul E. McKenneye74f4c42009-10-06 21:48:17 -07003031 /* Take mutex to serialize concurrent rcu_barrier() requests. */
Paul E. McKenney7be7f0b2012-05-29 05:18:53 -07003032 mutex_lock(&rsp->barrier_mutex);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003033
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003034 /*
3035 * Ensure that all prior references, including to ->n_barrier_done,
3036 * are ordered before the _rcu_barrier() machinery.
3037 */
3038 smp_mb(); /* See above block comment. */
3039
3040 /*
3041 * Recheck ->n_barrier_done to see if others did our work for us.
3042 * This means checking ->n_barrier_done for an even-to-odd-to-even
3043 * transition. The "if" expression below therefore rounds the old
3044 * value up to the next even number and adds two before comparing.
3045 */
Paul E. McKenney458fb382013-07-26 20:47:42 -07003046 snap_done = rsp->n_barrier_done;
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003047 _rcu_barrier_trace(rsp, "Check", -1, snap_done);
Paul E. McKenney458fb382013-07-26 20:47:42 -07003048
3049 /*
3050 * If the value in snap is odd, we needed to wait for the current
3051 * rcu_barrier() to complete, then wait for the next one, in other
3052 * words, we need the value of snap_done to be three larger than
3053 * the value of snap. On the other hand, if the value in snap is
3054 * even, we only had to wait for the next rcu_barrier() to complete,
3055 * in other words, we need the value of snap_done to be only two
3056 * greater than the value of snap. The "(snap + 3) & ~0x1" computes
3057 * this for us (thank you, Linus!).
3058 */
3059 if (ULONG_CMP_GE(snap_done, (snap + 3) & ~0x1)) {
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003060 _rcu_barrier_trace(rsp, "EarlyExit", -1, snap_done);
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003061 smp_mb(); /* caller's subsequent code after above check. */
3062 mutex_unlock(&rsp->barrier_mutex);
3063 return;
3064 }
3065
3066 /*
3067 * Increment ->n_barrier_done to avoid duplicate work. Use
3068 * ACCESS_ONCE() to prevent the compiler from speculating
3069 * the increment to precede the early-exit check.
3070 */
3071 ACCESS_ONCE(rsp->n_barrier_done)++;
3072 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003073 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003074 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003075
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003076 /*
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003077 * Initialize the count to one rather than to zero in order to
3078 * avoid a too-soon return to zero in case of a short grace period
Paul E. McKenney1331e7a2012-08-02 17:43:50 -07003079 * (or preemption of this task). Exclude CPU-hotplug operations
3080 * to ensure that no offline CPU has callbacks queued.
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003081 */
Paul E. McKenney7db74df2012-05-29 03:03:37 -07003082 init_completion(&rsp->barrier_completion);
Paul E. McKenney24ebbca2012-05-29 00:34:56 -07003083 atomic_set(&rsp->barrier_cpu_count, 1);
Paul E. McKenney1331e7a2012-08-02 17:43:50 -07003084 get_online_cpus();
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003085
3086 /*
Paul E. McKenney1331e7a2012-08-02 17:43:50 -07003087 * Force each CPU with callbacks to register a new callback.
3088 * When that callback is invoked, we will know that all of the
3089 * corresponding CPU's preceding callbacks have been invoked.
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003090 */
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07003091 for_each_possible_cpu(cpu) {
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +01003092 if (!cpu_online(cpu) && !rcu_is_nocb_cpu(cpu))
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07003093 continue;
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003094 rdp = per_cpu_ptr(rsp->rda, cpu);
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +01003095 if (rcu_is_nocb_cpu(cpu)) {
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07003096 _rcu_barrier_trace(rsp, "OnlineNoCB", cpu,
3097 rsp->n_barrier_done);
3098 atomic_inc(&rsp->barrier_cpu_count);
3099 __call_rcu(&rdp->barrier_head, rcu_barrier_callback,
3100 rsp, cpu, 0);
3101 } else if (ACCESS_ONCE(rdp->qlen)) {
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003102 _rcu_barrier_trace(rsp, "OnlineQ", cpu,
3103 rsp->n_barrier_done);
Paul E. McKenney037b64e2012-05-28 23:26:01 -07003104 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003105 } else {
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003106 _rcu_barrier_trace(rsp, "OnlineNQ", cpu,
3107 rsp->n_barrier_done);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003108 }
3109 }
Paul E. McKenney1331e7a2012-08-02 17:43:50 -07003110 put_online_cpus();
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003111
3112 /*
3113 * Now that we have an rcu_barrier_callback() callback on each
3114 * CPU, and thus each counted, remove the initial count.
3115 */
Paul E. McKenney24ebbca2012-05-29 00:34:56 -07003116 if (atomic_dec_and_test(&rsp->barrier_cpu_count))
Paul E. McKenney7db74df2012-05-29 03:03:37 -07003117 complete(&rsp->barrier_completion);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003118
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003119 /* Increment ->n_barrier_done to prevent duplicate work. */
3120 smp_mb(); /* Keep increment after above mechanism. */
3121 ACCESS_ONCE(rsp->n_barrier_done)++;
3122 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
Paul E. McKenneya83eff02012-05-23 18:47:05 -07003123 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
Paul E. McKenneycf3a9c42012-05-29 14:56:46 -07003124 smp_mb(); /* Keep increment before caller's subsequent code. */
3125
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003126 /* Wait for all rcu_barrier_callback() callbacks to be invoked. */
Paul E. McKenney7db74df2012-05-29 03:03:37 -07003127 wait_for_completion(&rsp->barrier_completion);
Paul E. McKenneyb1420f12012-03-01 13:18:08 -08003128
3129 /* Other rcu_barrier() invocations can now safely proceed. */
Paul E. McKenney7be7f0b2012-05-29 05:18:53 -07003130 mutex_unlock(&rsp->barrier_mutex);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003131}
3132
3133/**
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003134 * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
3135 */
3136void rcu_barrier_bh(void)
3137{
Paul E. McKenney037b64e2012-05-28 23:26:01 -07003138 _rcu_barrier(&rcu_bh_state);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003139}
3140EXPORT_SYMBOL_GPL(rcu_barrier_bh);
3141
3142/**
3143 * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
3144 */
3145void rcu_barrier_sched(void)
3146{
Paul E. McKenney037b64e2012-05-28 23:26:01 -07003147 _rcu_barrier(&rcu_sched_state);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003148}
3149EXPORT_SYMBOL_GPL(rcu_barrier_sched);
3150
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003151/*
Paul E. McKenney27569622009-08-15 09:53:46 -07003152 * Do boot-time initialization of a CPU's per-CPU RCU data.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003153 */
Paul E. McKenney27569622009-08-15 09:53:46 -07003154static void __init
3155rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003156{
3157 unsigned long flags;
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003158 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenney27569622009-08-15 09:53:46 -07003159 struct rcu_node *rnp = rcu_get_root(rsp);
3160
3161 /* Set up local state, ensuring consistent view of global state. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003162 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney27569622009-08-15 09:53:46 -07003163 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
Paul E. McKenney3f5d3ea2012-05-09 15:39:56 -07003164 init_callback_list(rdp);
Paul E. McKenney486e2592012-01-06 14:11:30 -08003165 rdp->qlen_lazy = 0;
Paul E. McKenney1d1fb392012-05-09 15:44:42 -07003166 ACCESS_ONCE(rdp->qlen) = 0;
Paul E. McKenney27569622009-08-15 09:53:46 -07003167 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
Paul E. McKenney29e37d82011-11-17 16:55:56 -08003168 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
Paul E. McKenney9b2e4f12011-09-30 12:10:22 -07003169 WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
Paul E. McKenney27569622009-08-15 09:53:46 -07003170 rdp->cpu = cpu;
Paul E. McKenneyd4c08f22011-06-25 06:36:56 -07003171 rdp->rsp = rsp;
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07003172 rcu_boot_init_nocb_percpu_data(rdp);
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003173 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney27569622009-08-15 09:53:46 -07003174}
3175
3176/*
3177 * Initialize a CPU's per-CPU RCU data. Note that only one online or
3178 * offline event can be happening at a given time. Note also that we
3179 * can accept some slop in the rsp->completed access due to the fact
3180 * that this CPU cannot possibly have any RCU callbacks in flight yet.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003181 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04003182static void
Iulia Manda9b671222014-03-11 13:18:22 +02003183rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003184{
3185 unsigned long flags;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003186 unsigned long mask;
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003187 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003188 struct rcu_node *rnp = rcu_get_root(rsp);
3189
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07003190 /* Exclude new grace periods. */
3191 mutex_lock(&rsp->onoff_mutex);
3192
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003193 /* Set up local state, ensuring consistent view of global state. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003194 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003195 rdp->beenonline = 1; /* We have now been online. */
Paul E. McKenney37c72e52009-10-14 10:15:55 -07003196 rdp->qlen_last_fqs_check = 0;
3197 rdp->n_force_qs_snap = rsp->n_force_qs;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003198 rdp->blimit = blimit;
Paul E. McKenney0d8ee372012-08-03 13:16:15 -07003199 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
Paul E. McKenney29e37d82011-11-17 16:55:56 -08003200 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
Paul E. McKenney23332102013-06-21 12:34:33 -07003201 rcu_sysidle_init_percpu_data(rdp->dynticks);
Paul E. McKenneyc92b1312011-11-23 13:38:58 -08003202 atomic_set(&rdp->dynticks->dynticks,
3203 (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003204 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003205
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003206 /* Add CPU to rcu_node bitmasks. */
3207 rnp = rdp->mynode;
3208 mask = rdp->grpmask;
3209 do {
3210 /* Exclude any attempts to start a new GP on small systems. */
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003211 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003212 rnp->qsmaskinit |= mask;
3213 mask = rnp->grpmask;
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08003214 if (rnp == rdp->mynode) {
Paul E. McKenney06ae115a2011-08-14 15:56:54 -07003215 /*
3216 * If there is a grace period in progress, we will
3217 * set up to wait for it next time we run the
3218 * RCU core code.
3219 */
3220 rdp->gpnum = rnp->completed;
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08003221 rdp->completed = rnp->completed;
Paul E. McKenney06ae115a2011-08-14 15:56:54 -07003222 rdp->passed_quiesce = 0;
3223 rdp->qs_pending = 0;
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04003224 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl"));
Paul E. McKenneyd09b62d2009-11-02 13:52:28 -08003225 }
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003226 raw_spin_unlock(&rnp->lock); /* irqs already disabled. */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003227 rnp = rnp->parent;
3228 } while (rnp != NULL && !(rnp->qsmaskinit & mask));
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07003229 local_irq_restore(flags);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003230
Paul E. McKenneya4fbe352012-10-07 08:36:12 -07003231 mutex_unlock(&rsp->onoff_mutex);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003232}
3233
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04003234static void rcu_prepare_cpu(int cpu)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003235{
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07003236 struct rcu_state *rsp;
3237
3238 for_each_rcu_flavor(rsp)
Iulia Manda9b671222014-03-11 13:18:22 +02003239 rcu_init_percpu_data(cpu, rsp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003240}
3241
3242/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07003243 * Handle CPU online/offline notification events.
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003244 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04003245static int rcu_cpu_notify(struct notifier_block *self,
Paul E. McKenney9f680ab2009-11-22 08:53:49 -08003246 unsigned long action, void *hcpu)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003247{
3248 long cpu = (long)hcpu;
Paul E. McKenney27f4d282011-02-07 12:47:15 -08003249 struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
Paul E. McKenneya26ac242011-01-12 14:10:23 -08003250 struct rcu_node *rnp = rdp->mynode;
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07003251 struct rcu_state *rsp;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003252
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04003253 trace_rcu_utilization(TPS("Start CPU hotplug"));
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003254 switch (action) {
3255 case CPU_UP_PREPARE:
3256 case CPU_UP_PREPARE_FROZEN:
Peter Zijlstrad72bce02011-05-30 13:34:51 +02003257 rcu_prepare_cpu(cpu);
3258 rcu_prepare_kthreads(cpu);
Paul E. McKenneya26ac242011-01-12 14:10:23 -08003259 break;
3260 case CPU_ONLINE:
Paul E. McKenney0f962a52011-04-14 12:13:53 -07003261 case CPU_DOWN_FAILED:
Thomas Gleixner5d01bbd2012-07-16 10:42:35 +00003262 rcu_boost_kthread_setaffinity(rnp, -1);
Paul E. McKenney0f962a52011-04-14 12:13:53 -07003263 break;
3264 case CPU_DOWN_PREPARE:
Paul E. McKenney34ed62462013-01-07 13:37:42 -08003265 rcu_boost_kthread_setaffinity(rnp, cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003266 break;
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003267 case CPU_DYING:
3268 case CPU_DYING_FROZEN:
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07003269 for_each_rcu_flavor(rsp)
3270 rcu_cleanup_dying_cpu(rsp);
Paul E. McKenneyd0ec7742009-10-06 21:48:16 -07003271 break;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003272 case CPU_DEAD:
3273 case CPU_DEAD_FROZEN:
3274 case CPU_UP_CANCELED:
3275 case CPU_UP_CANCELED_FROZEN:
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07003276 for_each_rcu_flavor(rsp)
3277 rcu_cleanup_dead_cpu(cpu, rsp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003278 break;
3279 default:
3280 break;
3281 }
Steven Rostedt (Red Hat)f7f7bac2013-07-12 17:18:47 -04003282 trace_rcu_utilization(TPS("End CPU hotplug"));
Paul E. McKenney34ed62462013-01-07 13:37:42 -08003283 return NOTIFY_OK;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003284}
3285
Borislav Petkovd1d74d12013-04-22 00:12:42 +02003286static int rcu_pm_notify(struct notifier_block *self,
3287 unsigned long action, void *hcpu)
3288{
3289 switch (action) {
3290 case PM_HIBERNATION_PREPARE:
3291 case PM_SUSPEND_PREPARE:
3292 if (nr_cpu_ids <= 256) /* Expediting bad for large systems. */
3293 rcu_expedited = 1;
3294 break;
3295 case PM_POST_HIBERNATION:
3296 case PM_POST_SUSPEND:
3297 rcu_expedited = 0;
3298 break;
3299 default:
3300 break;
3301 }
3302 return NOTIFY_OK;
3303}
3304
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003305/*
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07003306 * Spawn the kthread that handles this RCU flavor's grace periods.
3307 */
3308static int __init rcu_spawn_gp_kthread(void)
3309{
3310 unsigned long flags;
3311 struct rcu_node *rnp;
3312 struct rcu_state *rsp;
3313 struct task_struct *t;
3314
3315 for_each_rcu_flavor(rsp) {
Kees Cookf1701682013-07-03 15:04:58 -07003316 t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07003317 BUG_ON(IS_ERR(t));
3318 rnp = rcu_get_root(rsp);
3319 raw_spin_lock_irqsave(&rnp->lock, flags);
3320 rsp->gp_kthread = t;
3321 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -07003322 rcu_spawn_nocb_kthreads(rsp);
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07003323 }
3324 return 0;
3325}
3326early_initcall(rcu_spawn_gp_kthread);
3327
3328/*
Paul E. McKenneybbad9372010-04-02 16:17:17 -07003329 * This function is invoked towards the end of the scheduler's initialization
3330 * process. Before this is called, the idle task might contain
3331 * RCU read-side critical sections (during which time, this idle
3332 * task is booting the system). After this function is called, the
3333 * idle tasks are prohibited from containing RCU read-side critical
3334 * sections. This function also enables RCU lockdep checking.
3335 */
3336void rcu_scheduler_starting(void)
3337{
3338 WARN_ON(num_online_cpus() != 1);
3339 WARN_ON(nr_context_switches() > 0);
3340 rcu_scheduler_active = 1;
3341}
3342
3343/*
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003344 * Compute the per-level fanout, either using the exact fanout specified
3345 * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT.
3346 */
3347#ifdef CONFIG_RCU_FANOUT_EXACT
3348static void __init rcu_init_levelspread(struct rcu_state *rsp)
3349{
3350 int i;
3351
Paul E. McKenney04f34652013-10-16 08:39:10 -07003352 rsp->levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
3353 for (i = rcu_num_lvls - 2; i >= 0; i--)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003354 rsp->levelspread[i] = CONFIG_RCU_FANOUT;
3355}
3356#else /* #ifdef CONFIG_RCU_FANOUT_EXACT */
3357static void __init rcu_init_levelspread(struct rcu_state *rsp)
3358{
3359 int ccur;
3360 int cprv;
3361 int i;
3362
Paul E. McKenney4dbd6bb2012-09-05 21:43:57 -07003363 cprv = nr_cpu_ids;
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003364 for (i = rcu_num_lvls - 1; i >= 0; i--) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003365 ccur = rsp->levelcnt[i];
3366 rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
3367 cprv = ccur;
3368 }
3369}
3370#endif /* #else #ifdef CONFIG_RCU_FANOUT_EXACT */
3371
3372/*
3373 * Helper function for rcu_init() that initializes one rcu_state structure.
3374 */
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003375static void __init rcu_init_one(struct rcu_state *rsp,
3376 struct rcu_data __percpu *rda)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003377{
Paul E. McKenney394f2762012-06-26 17:00:35 -07003378 static char *buf[] = { "rcu_node_0",
3379 "rcu_node_1",
3380 "rcu_node_2",
3381 "rcu_node_3" }; /* Match MAX_RCU_LVLS */
3382 static char *fqs[] = { "rcu_node_fqs_0",
3383 "rcu_node_fqs_1",
3384 "rcu_node_fqs_2",
3385 "rcu_node_fqs_3" }; /* Match MAX_RCU_LVLS */
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003386 int cpustride = 1;
3387 int i;
3388 int j;
3389 struct rcu_node *rnp;
3390
Paul E. McKenneyb6407e82010-01-04 16:04:02 -08003391 BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */
3392
Paul E. McKenney49305212012-11-29 13:49:00 -08003393 /* Silence gcc 4.8 warning about array index out of range. */
3394 if (rcu_num_lvls > RCU_NUM_LVLS)
3395 panic("rcu_init_one: rcu_num_lvls overflow");
3396
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003397 /* Initialize the level-tracking arrays. */
3398
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003399 for (i = 0; i < rcu_num_lvls; i++)
3400 rsp->levelcnt[i] = num_rcu_lvl[i];
3401 for (i = 1; i < rcu_num_lvls; i++)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003402 rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
3403 rcu_init_levelspread(rsp);
3404
3405 /* Initialize the elements themselves, starting from the leaves. */
3406
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003407 for (i = rcu_num_lvls - 1; i >= 0; i--) {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003408 cpustride *= rsp->levelspread[i];
3409 rnp = rsp->level[i];
3410 for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -08003411 raw_spin_lock_init(&rnp->lock);
Paul E. McKenneyb6407e82010-01-04 16:04:02 -08003412 lockdep_set_class_and_name(&rnp->lock,
3413 &rcu_node_class[i], buf[i]);
Paul E. McKenney394f2762012-06-26 17:00:35 -07003414 raw_spin_lock_init(&rnp->fqslock);
3415 lockdep_set_class_and_name(&rnp->fqslock,
3416 &rcu_fqs_class[i], fqs[i]);
Paul E. McKenney25d30cf2012-07-11 05:23:18 -07003417 rnp->gpnum = rsp->gpnum;
3418 rnp->completed = rsp->completed;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003419 rnp->qsmask = 0;
3420 rnp->qsmaskinit = 0;
3421 rnp->grplo = j * cpustride;
3422 rnp->grphi = (j + 1) * cpustride - 1;
3423 if (rnp->grphi >= NR_CPUS)
3424 rnp->grphi = NR_CPUS - 1;
3425 if (i == 0) {
3426 rnp->grpnum = 0;
3427 rnp->grpmask = 0;
3428 rnp->parent = NULL;
3429 } else {
3430 rnp->grpnum = j % rsp->levelspread[i - 1];
3431 rnp->grpmask = 1UL << rnp->grpnum;
3432 rnp->parent = rsp->level[i - 1] +
3433 j / rsp->levelspread[i - 1];
3434 }
3435 rnp->level = i;
Paul E. McKenney12f5f522010-11-29 21:56:39 -08003436 INIT_LIST_HEAD(&rnp->blkd_tasks);
Paul E. McKenneydae6e642013-02-10 20:48:58 -08003437 rcu_init_one_nocb(rnp);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003438 }
3439 }
Lai Jiangshan0c340292010-03-28 11:12:30 +08003440
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003441 rsp->rda = rda;
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -07003442 init_waitqueue_head(&rsp->gp_wq);
Steven Rostedt016a8d52013-05-28 17:32:53 -04003443 init_irq_work(&rsp->wakeup_work, rsp_wakeup);
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003444 rnp = rsp->level[rcu_num_lvls - 1];
Lai Jiangshan0c340292010-03-28 11:12:30 +08003445 for_each_possible_cpu(i) {
Paul E. McKenney4a90a062010-04-14 16:48:11 -07003446 while (i > rnp->grphi)
Lai Jiangshan0c340292010-03-28 11:12:30 +08003447 rnp++;
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003448 per_cpu_ptr(rsp->rda, i)->mynode = rnp;
Lai Jiangshan0c340292010-03-28 11:12:30 +08003449 rcu_boot_init_percpu_data(i, rsp);
3450 }
Paul E. McKenney6ce75a22012-06-12 11:01:13 -07003451 list_add(&rsp->flavors, &rcu_struct_flavors);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003452}
3453
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003454/*
3455 * Compute the rcu_node tree geometry from kernel parameters. This cannot
Paul E. McKenney4102ada2013-10-08 20:23:47 -07003456 * replace the definitions in tree.h because those are needed to size
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003457 * the ->node array in the rcu_state structure.
3458 */
3459static void __init rcu_init_geometry(void)
3460{
Paul E. McKenney026ad282013-04-03 22:14:11 -07003461 ulong d;
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003462 int i;
3463 int j;
Paul E. McKenneycca6f392012-05-08 21:00:28 -07003464 int n = nr_cpu_ids;
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003465 int rcu_capacity[MAX_RCU_LVLS + 1];
3466
Paul E. McKenney026ad282013-04-03 22:14:11 -07003467 /*
3468 * Initialize any unspecified boot parameters.
3469 * The default values of jiffies_till_first_fqs and
3470 * jiffies_till_next_fqs are set to the RCU_JIFFIES_TILL_FORCE_QS
3471 * value, which is a function of HZ, then adding one for each
3472 * RCU_JIFFIES_FQS_DIV CPUs that might be on the system.
3473 */
3474 d = RCU_JIFFIES_TILL_FORCE_QS + nr_cpu_ids / RCU_JIFFIES_FQS_DIV;
3475 if (jiffies_till_first_fqs == ULONG_MAX)
3476 jiffies_till_first_fqs = d;
3477 if (jiffies_till_next_fqs == ULONG_MAX)
3478 jiffies_till_next_fqs = d;
3479
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003480 /* If the compile-time values are accurate, just leave. */
Paul E. McKenneyb17c7032012-09-06 15:38:02 -07003481 if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF &&
3482 nr_cpu_ids == NR_CPUS)
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003483 return;
Paul E. McKenney39479092013-10-09 15:20:33 -07003484 pr_info("RCU: Adjusting geometry for rcu_fanout_leaf=%d, nr_cpu_ids=%d\n",
3485 rcu_fanout_leaf, nr_cpu_ids);
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003486
3487 /*
3488 * Compute number of nodes that can be handled an rcu_node tree
3489 * with the given number of levels. Setting rcu_capacity[0] makes
3490 * some of the arithmetic easier.
3491 */
3492 rcu_capacity[0] = 1;
3493 rcu_capacity[1] = rcu_fanout_leaf;
3494 for (i = 2; i <= MAX_RCU_LVLS; i++)
3495 rcu_capacity[i] = rcu_capacity[i - 1] * CONFIG_RCU_FANOUT;
3496
3497 /*
3498 * The boot-time rcu_fanout_leaf parameter is only permitted
3499 * to increase the leaf-level fanout, not decrease it. Of course,
3500 * the leaf-level fanout cannot exceed the number of bits in
3501 * the rcu_node masks. Finally, the tree must be able to accommodate
3502 * the configured number of CPUs. Complain and fall back to the
3503 * compile-time values if these limits are exceeded.
3504 */
3505 if (rcu_fanout_leaf < CONFIG_RCU_FANOUT_LEAF ||
3506 rcu_fanout_leaf > sizeof(unsigned long) * 8 ||
3507 n > rcu_capacity[MAX_RCU_LVLS]) {
3508 WARN_ON(1);
3509 return;
3510 }
3511
3512 /* Calculate the number of rcu_nodes at each level of the tree. */
3513 for (i = 1; i <= MAX_RCU_LVLS; i++)
3514 if (n <= rcu_capacity[i]) {
3515 for (j = 0; j <= i; j++)
3516 num_rcu_lvl[j] =
3517 DIV_ROUND_UP(n, rcu_capacity[i - j]);
3518 rcu_num_lvls = i;
3519 for (j = i + 1; j <= MAX_RCU_LVLS; j++)
3520 num_rcu_lvl[j] = 0;
3521 break;
3522 }
3523
3524 /* Calculate the total number of rcu_node structures. */
3525 rcu_num_nodes = 0;
3526 for (i = 0; i <= MAX_RCU_LVLS; i++)
3527 rcu_num_nodes += num_rcu_lvl[i];
3528 rcu_num_nodes -= n;
3529}
3530
Paul E. McKenney9f680ab2009-11-22 08:53:49 -08003531void __init rcu_init(void)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07003532{
Paul E. McKenney017c4262010-01-14 16:10:58 -08003533 int cpu;
Paul E. McKenney9f680ab2009-11-22 08:53:49 -08003534
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07003535 rcu_bootup_announce();
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -07003536 rcu_init_geometry();
Lai Jiangshan394f99a2010-06-28 16:25:04 +08003537 rcu_init_one(&rcu_bh_state, &rcu_bh_data);
Paul E. McKenney69c8d282013-09-03 09:52:20 -07003538 rcu_init_one(&rcu_sched_state, &rcu_sched_data);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07003539 __rcu_init_preempt();
Jiang Fangb5b39362013-02-02 14:13:42 -08003540 open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
Paul E. McKenney9f680ab2009-11-22 08:53:49 -08003541
3542 /*
3543 * We don't need protection against CPU-hotplug here because
3544 * this is called early in boot, before either interrupts
3545 * or the scheduler are operational.
3546 */
3547 cpu_notifier(rcu_cpu_notify, 0);
Borislav Petkovd1d74d12013-04-22 00:12:42 +02003548 pm_notifier(rcu_pm_notify, 0);
Paul E. McKenney017c4262010-01-14 16:10:58 -08003549 for_each_online_cpu(cpu)
3550 rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01003551}
3552
Paul E. McKenney4102ada2013-10-08 20:23:47 -07003553#include "tree_plugin.h"