blob: 561410f70d4a507723c939f568c1cc9adf2204d6 [file] [log] [blame]
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001/*
2 * Read-Copy Update mechanism for mutual exclusion (tree-based version)
3 * Internal non-public definitions that provide either classic
4 * or preemptable semantics.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 * Copyright Red Hat, 2009
21 * Copyright IBM Corporation, 2009
22 *
23 * Author: Ingo Molnar <mingo@elte.hu>
24 * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
25 */
26
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -080027#include <linux/delay.h>
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070028
Paul E. McKenney26845c22010-04-13 14:19:23 -070029/*
30 * Check the RCU kernel configuration parameters and print informative
31 * messages about anything out of the ordinary. If you like #ifdef, you
32 * will love this function.
33 */
34static void __init rcu_bootup_announce_oddness(void)
35{
36#ifdef CONFIG_RCU_TRACE
37 printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n");
38#endif
39#if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)
40 printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
41 CONFIG_RCU_FANOUT);
42#endif
43#ifdef CONFIG_RCU_FANOUT_EXACT
44 printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n");
45#endif
46#ifdef CONFIG_RCU_FAST_NO_HZ
47 printk(KERN_INFO
48 "\tRCU dyntick-idle grace-period acceleration is enabled.\n");
49#endif
50#ifdef CONFIG_PROVE_RCU
51 printk(KERN_INFO "\tRCU lockdep checking is enabled.\n");
52#endif
53#ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE
54 printk(KERN_INFO "\tRCU torture testing starts during boot.\n");
55#endif
56#ifndef CONFIG_RCU_CPU_STALL_DETECTOR
57 printk(KERN_INFO
58 "\tRCU-based detection of stalled CPUs is disabled.\n");
59#endif
60#ifndef CONFIG_RCU_CPU_STALL_VERBOSE
61 printk(KERN_INFO "\tVerbose stalled-CPUs detection is disabled.\n");
62#endif
63#if NUM_RCU_LVL_4 != 0
64 printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n");
65#endif
66}
67
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070068#ifdef CONFIG_TREE_PREEMPT_RCU
69
70struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state);
71DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data);
72
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -080073static int rcu_preempted_readers_exp(struct rcu_node *rnp);
74
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070075/*
76 * Tell them what RCU they are running.
77 */
Paul E. McKenney0e0fc1c2009-11-11 11:28:06 -080078static void __init rcu_bootup_announce(void)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070079{
Paul E. McKenney26845c22010-04-13 14:19:23 -070080 printk(KERN_INFO "Preemptable hierarchical RCU implementation.\n");
81 rcu_bootup_announce_oddness();
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070082}
83
84/*
85 * Return the number of RCU-preempt batches processed thus far
86 * for debug and statistics.
87 */
88long rcu_batches_completed_preempt(void)
89{
90 return rcu_preempt_state.completed;
91}
92EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt);
93
94/*
95 * Return the number of RCU batches processed thus far for debug & stats.
96 */
97long rcu_batches_completed(void)
98{
99 return rcu_batches_completed_preempt();
100}
101EXPORT_SYMBOL_GPL(rcu_batches_completed);
102
103/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800104 * Force a quiescent state for preemptible RCU.
105 */
106void rcu_force_quiescent_state(void)
107{
108 force_quiescent_state(&rcu_preempt_state, 0);
109}
110EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
111
112/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700113 * Record a preemptable-RCU quiescent state for the specified CPU. Note
114 * that this just means that the task currently running on the CPU is
115 * not in a quiescent state. There might be any number of tasks blocked
116 * while in an RCU read-side critical section.
Paul E. McKenney25502a62010-04-01 17:37:01 -0700117 *
118 * Unlike the other rcu_*_qs() functions, callers to this function
119 * must disable irqs in order to protect the assignment to
120 * ->rcu_read_unlock_special.
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700121 */
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700122static void rcu_preempt_qs(int cpu)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700123{
124 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
Paul E. McKenney25502a62010-04-01 17:37:01 -0700125
Paul E. McKenneyc64ac3c2009-11-10 13:37:22 -0800126 rdp->passed_quiesc_completed = rdp->gpnum - 1;
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700127 barrier();
128 rdp->passed_quiesc = 1;
Paul E. McKenney25502a62010-04-01 17:37:01 -0700129 current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700130}
131
132/*
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700133 * We have entered the scheduler, and the current task might soon be
134 * context-switched away from. If this task is in an RCU read-side
135 * critical section, we will no longer be able to rely on the CPU to
136 * record that fact, so we enqueue the task on the appropriate entry
137 * of the blocked_tasks[] array. The task will dequeue itself when
138 * it exits the outermost enclosing RCU read-side critical section.
139 * Therefore, the current grace period cannot be permitted to complete
140 * until the blocked_tasks[] entry indexed by the low-order bit of
141 * rnp->gpnum empties.
142 *
143 * Caller must disable preemption.
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700144 */
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700145static void rcu_preempt_note_context_switch(int cpu)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700146{
147 struct task_struct *t = current;
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700148 unsigned long flags;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700149 int phase;
150 struct rcu_data *rdp;
151 struct rcu_node *rnp;
152
153 if (t->rcu_read_lock_nesting &&
154 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
155
156 /* Possibly blocking in an RCU read-side critical section. */
Lai Jiangshan394f99a2010-06-28 16:25:04 +0800157 rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700158 rnp = rdp->mynode;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800159 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700160 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
Paul E. McKenney86848962009-08-27 15:00:12 -0700161 t->rcu_blocked_node = rnp;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700162
163 /*
164 * If this CPU has already checked in, then this task
165 * will hold up the next grace period rather than the
166 * current grace period. Queue the task accordingly.
167 * If the task is queued for the current grace period
168 * (i.e., this CPU has not yet passed through a quiescent
169 * state for the current grace period), then as long
170 * as that task remains queued, the current grace period
171 * cannot end.
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700172 *
173 * But first, note that the current CPU must still be
174 * on line!
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700175 */
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700176 WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
Paul E. McKenneye7d88422009-09-18 09:50:18 -0700177 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
178 phase = (rnp->gpnum + !(rnp->qsmask & rdp->grpmask)) & 0x1;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700179 list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]);
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800180 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700181 }
182
183 /*
184 * Either we were not in an RCU read-side critical section to
185 * begin with, or we have now recorded that critical section
186 * globally. Either way, we can now note a quiescent state
187 * for this CPU. Again, if we were in an RCU read-side critical
188 * section, and if that critical section was blocking the current
189 * grace period, then the fact that the task has been enqueued
190 * means that we continue to block the current grace period.
191 */
Paul E. McKenneye7d88422009-09-18 09:50:18 -0700192 local_irq_save(flags);
Paul E. McKenney25502a62010-04-01 17:37:01 -0700193 rcu_preempt_qs(cpu);
Paul E. McKenneye7d88422009-09-18 09:50:18 -0700194 local_irq_restore(flags);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700195}
196
197/*
198 * Tree-preemptable RCU implementation for rcu_read_lock().
199 * Just increment ->rcu_read_lock_nesting, shared state will be updated
200 * if we block.
201 */
202void __rcu_read_lock(void)
203{
204 ACCESS_ONCE(current->rcu_read_lock_nesting)++;
205 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
206}
207EXPORT_SYMBOL_GPL(__rcu_read_lock);
208
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700209/*
210 * Check for preempted RCU readers blocking the current grace period
211 * for the specified rcu_node structure. If the caller needs a reliable
212 * answer, it must hold the rcu_node's ->lock.
213 */
214static int rcu_preempted_readers(struct rcu_node *rnp)
215{
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800216 int phase = rnp->gpnum & 0x1;
217
218 return !list_empty(&rnp->blocked_tasks[phase]) ||
219 !list_empty(&rnp->blocked_tasks[phase + 2]);
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700220}
221
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800222/*
223 * Record a quiescent state for all tasks that were previously queued
224 * on the specified rcu_node structure and that were blocking the current
225 * RCU grace period. The caller must hold the specified rnp->lock with
226 * irqs disabled, and this lock is released upon return, but irqs remain
227 * disabled.
228 */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800229static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800230 __releases(rnp->lock)
231{
232 unsigned long mask;
233 struct rcu_node *rnp_p;
234
235 if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800236 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800237 return; /* Still need more quiescent states! */
238 }
239
240 rnp_p = rnp->parent;
241 if (rnp_p == NULL) {
242 /*
243 * Either there is only one rcu_node in the tree,
244 * or tasks were kicked up to root rcu_node due to
245 * CPUs going offline.
246 */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800247 rcu_report_qs_rsp(&rcu_preempt_state, flags);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800248 return;
249 }
250
251 /* Report up the rest of the hierarchy. */
252 mask = rnp->grpmask;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800253 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
254 raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800255 rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800256}
257
258/*
259 * Handle special cases during rcu_read_unlock(), such as needing to
260 * notify RCU core processing or task having blocked during the RCU
261 * read-side critical section.
262 */
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700263static void rcu_read_unlock_special(struct task_struct *t)
264{
265 int empty;
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800266 int empty_exp;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700267 unsigned long flags;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700268 struct rcu_node *rnp;
269 int special;
270
271 /* NMI handlers cannot block and cannot safely manipulate state. */
272 if (in_nmi())
273 return;
274
275 local_irq_save(flags);
276
277 /*
278 * If RCU core is waiting for this CPU to exit critical section,
279 * let it know that we have done so.
280 */
281 special = t->rcu_read_unlock_special;
282 if (special & RCU_READ_UNLOCK_NEED_QS) {
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700283 rcu_preempt_qs(smp_processor_id());
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700284 }
285
286 /* Hardware IRQ handlers cannot block. */
287 if (in_irq()) {
288 local_irq_restore(flags);
289 return;
290 }
291
292 /* Clean up if blocked during RCU read-side critical section. */
293 if (special & RCU_READ_UNLOCK_BLOCKED) {
294 t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED;
295
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700296 /*
297 * Remove this task from the list it blocked on. The
298 * task can migrate while we acquire the lock, but at
299 * most one time. So at most two passes through loop.
300 */
301 for (;;) {
Paul E. McKenney86848962009-08-27 15:00:12 -0700302 rnp = t->rcu_blocked_node;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800303 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
Paul E. McKenney86848962009-08-27 15:00:12 -0700304 if (rnp == t->rcu_blocked_node)
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700305 break;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800306 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700307 }
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700308 empty = !rcu_preempted_readers(rnp);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800309 empty_exp = !rcu_preempted_readers_exp(rnp);
310 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700311 list_del_init(&t->rcu_node_entry);
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700312 t->rcu_blocked_node = NULL;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700313
314 /*
315 * If this was the last task on the current list, and if
316 * we aren't waiting on any CPUs, report the quiescent state.
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800317 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock.
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700318 */
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800319 if (empty)
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800320 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800321 else
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800322 rcu_report_unblock_qs_rnp(rnp, flags);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800323
324 /*
325 * If this was the last task on the expedited lists,
326 * then we need to report up the rcu_node hierarchy.
327 */
328 if (!empty_exp && !rcu_preempted_readers_exp(rnp))
329 rcu_report_exp_rnp(&rcu_preempt_state, rnp);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800330 } else {
331 local_irq_restore(flags);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700332 }
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700333}
334
335/*
336 * Tree-preemptable RCU implementation for rcu_read_unlock().
337 * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost
338 * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then
339 * invoke rcu_read_unlock_special() to clean up after a context switch
340 * in an RCU read-side critical section and other special cases.
341 */
342void __rcu_read_unlock(void)
343{
344 struct task_struct *t = current;
345
346 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
347 if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
348 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
349 rcu_read_unlock_special(t);
Paul E. McKenneycba82442010-01-04 16:04:01 -0800350#ifdef CONFIG_PROVE_LOCKING
351 WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0);
352#endif /* #ifdef CONFIG_PROVE_LOCKING */
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700353}
354EXPORT_SYMBOL_GPL(__rcu_read_unlock);
355
356#ifdef CONFIG_RCU_CPU_STALL_DETECTOR
357
Paul E. McKenney1ed509a2010-02-22 17:05:05 -0800358#ifdef CONFIG_RCU_CPU_STALL_VERBOSE
359
360/*
361 * Dump detailed information for all tasks blocking the current RCU
362 * grace period on the specified rcu_node structure.
363 */
364static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
365{
366 unsigned long flags;
367 struct list_head *lp;
368 int phase;
369 struct task_struct *t;
370
371 if (rcu_preempted_readers(rnp)) {
372 raw_spin_lock_irqsave(&rnp->lock, flags);
373 phase = rnp->gpnum & 0x1;
374 lp = &rnp->blocked_tasks[phase];
375 list_for_each_entry(t, lp, rcu_node_entry)
376 sched_show_task(t);
377 raw_spin_unlock_irqrestore(&rnp->lock, flags);
378 }
379}
380
381/*
382 * Dump detailed information for all tasks blocking the current RCU
383 * grace period.
384 */
385static void rcu_print_detail_task_stall(struct rcu_state *rsp)
386{
387 struct rcu_node *rnp = rcu_get_root(rsp);
388
389 rcu_print_detail_task_stall_rnp(rnp);
390 rcu_for_each_leaf_node(rsp, rnp)
391 rcu_print_detail_task_stall_rnp(rnp);
392}
393
394#else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
395
396static void rcu_print_detail_task_stall(struct rcu_state *rsp)
397{
398}
399
400#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
401
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700402/*
403 * Scan the current list of tasks blocked within RCU read-side critical
404 * sections, printing out the tid of each.
405 */
406static void rcu_print_task_stall(struct rcu_node *rnp)
407{
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700408 struct list_head *lp;
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700409 int phase;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700410 struct task_struct *t;
411
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700412 if (rcu_preempted_readers(rnp)) {
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700413 phase = rnp->gpnum & 0x1;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700414 lp = &rnp->blocked_tasks[phase];
415 list_for_each_entry(t, lp, rcu_node_entry)
416 printk(" P%d", t->pid);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700417 }
418}
419
Paul E. McKenney53d84e02010-08-10 14:28:53 -0700420/*
421 * Suppress preemptible RCU's CPU stall warnings by pushing the
422 * time of the next stall-warning message comfortably far into the
423 * future.
424 */
425static void rcu_preempt_stall_reset(void)
426{
427 rcu_preempt_state.jiffies_stall = jiffies + ULONG_MAX / 2;
428}
429
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700430#endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
431
432/*
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700433 * Check that the list of blocked tasks for the newly completed grace
434 * period is in fact empty. It is a serious bug to complete a grace
435 * period that still has RCU readers blocked! This function must be
436 * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
437 * must be held by the caller.
438 */
439static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
440{
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700441 WARN_ON_ONCE(rcu_preempted_readers(rnp));
Paul E. McKenney28ecd582009-09-18 09:50:17 -0700442 WARN_ON_ONCE(rnp->qsmask);
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700443}
444
Paul E. McKenney33f76142009-08-24 09:42:01 -0700445#ifdef CONFIG_HOTPLUG_CPU
446
447/*
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700448 * Handle tasklist migration for case in which all CPUs covered by the
449 * specified rcu_node have gone offline. Move them up to the root
450 * rcu_node. The reason for not just moving them to the immediate
451 * parent is to remove the need for rcu_read_unlock_special() to
452 * make more than two attempts to acquire the target rcu_node's lock.
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800453 * Returns true if there were tasks blocking the current RCU grace
454 * period.
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700455 *
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700456 * Returns 1 if there was previously a task blocking the current grace
457 * period on the specified rcu_node structure.
458 *
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700459 * The caller must hold rnp->lock with irqs disabled.
460 */
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700461static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
462 struct rcu_node *rnp,
463 struct rcu_data *rdp)
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700464{
465 int i;
466 struct list_head *lp;
467 struct list_head *lp_root;
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800468 int retval = 0;
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700469 struct rcu_node *rnp_root = rcu_get_root(rsp);
470 struct task_struct *tp;
471
Paul E. McKenney86848962009-08-27 15:00:12 -0700472 if (rnp == rnp_root) {
473 WARN_ONCE(1, "Last CPU thought to be offlined?");
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700474 return 0; /* Shouldn't happen: at least one CPU online. */
Paul E. McKenney86848962009-08-27 15:00:12 -0700475 }
Paul E. McKenney28ecd582009-09-18 09:50:17 -0700476 WARN_ON_ONCE(rnp != rdp->mynode &&
477 (!list_empty(&rnp->blocked_tasks[0]) ||
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800478 !list_empty(&rnp->blocked_tasks[1]) ||
479 !list_empty(&rnp->blocked_tasks[2]) ||
480 !list_empty(&rnp->blocked_tasks[3])));
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700481
482 /*
483 * Move tasks up to root rcu_node. Rely on the fact that the
484 * root rcu_node can be at most one ahead of the rest of the
485 * rcu_nodes in terms of gp_num value. This fact allows us to
486 * move the blocked_tasks[] array directly, element by element.
487 */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800488 if (rcu_preempted_readers(rnp))
489 retval |= RCU_OFL_TASKS_NORM_GP;
490 if (rcu_preempted_readers_exp(rnp))
491 retval |= RCU_OFL_TASKS_EXP_GP;
492 for (i = 0; i < 4; i++) {
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700493 lp = &rnp->blocked_tasks[i];
494 lp_root = &rnp_root->blocked_tasks[i];
495 while (!list_empty(lp)) {
496 tp = list_entry(lp->next, typeof(*tp), rcu_node_entry);
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800497 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700498 list_del(&tp->rcu_node_entry);
499 tp->rcu_blocked_node = rnp_root;
500 list_add(&tp->rcu_node_entry, lp_root);
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800501 raw_spin_unlock(&rnp_root->lock); /* irqs remain disabled */
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700502 }
503 }
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700504 return retval;
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700505}
506
507/*
Paul E. McKenney33f76142009-08-24 09:42:01 -0700508 * Do CPU-offline processing for preemptable RCU.
509 */
510static void rcu_preempt_offline_cpu(int cpu)
511{
512 __rcu_offline_cpu(cpu, &rcu_preempt_state);
513}
514
515#endif /* #ifdef CONFIG_HOTPLUG_CPU */
516
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700517/*
518 * Check for a quiescent state from the current CPU. When a task blocks,
519 * the task is recorded in the corresponding CPU's rcu_node structure,
520 * which is checked elsewhere.
521 *
522 * Caller must disable hard irqs.
523 */
524static void rcu_preempt_check_callbacks(int cpu)
525{
526 struct task_struct *t = current;
527
528 if (t->rcu_read_lock_nesting == 0) {
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700529 rcu_preempt_qs(cpu);
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700530 return;
531 }
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700532 if (per_cpu(rcu_preempt_data, cpu).qs_pending)
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700533 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700534}
535
536/*
537 * Process callbacks for preemptable RCU.
538 */
539static void rcu_preempt_process_callbacks(void)
540{
541 __rcu_process_callbacks(&rcu_preempt_state,
542 &__get_cpu_var(rcu_preempt_data));
543}
544
545/*
546 * Queue a preemptable-RCU callback for invocation after a grace period.
547 */
548void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
549{
550 __call_rcu(head, func, &rcu_preempt_state);
551}
552EXPORT_SYMBOL_GPL(call_rcu);
553
Paul E. McKenney6ebb2372009-11-22 08:53:50 -0800554/**
555 * synchronize_rcu - wait until a grace period has elapsed.
556 *
557 * Control will return to the caller some time after a full grace
558 * period has elapsed, in other words after all currently executing RCU
Paul E. McKenney77d84852010-07-08 17:38:59 -0700559 * read-side critical sections have completed. Note, however, that
560 * upon return from synchronize_rcu(), the caller might well be executing
561 * concurrently with new RCU read-side critical sections that began while
562 * synchronize_rcu() was waiting. RCU read-side critical sections are
563 * delimited by rcu_read_lock() and rcu_read_unlock(), and may be nested.
Paul E. McKenney6ebb2372009-11-22 08:53:50 -0800564 */
565void synchronize_rcu(void)
566{
567 struct rcu_synchronize rcu;
568
569 if (!rcu_scheduler_active)
570 return;
571
Paul E. McKenney72d5a9f2010-05-10 17:12:17 -0700572 init_rcu_head_on_stack(&rcu.head);
Paul E. McKenney6ebb2372009-11-22 08:53:50 -0800573 init_completion(&rcu.completion);
574 /* Will wake me after RCU finished. */
575 call_rcu(&rcu.head, wakeme_after_rcu);
576 /* Wait for it. */
577 wait_for_completion(&rcu.completion);
Paul E. McKenney72d5a9f2010-05-10 17:12:17 -0700578 destroy_rcu_head_on_stack(&rcu.head);
Paul E. McKenney6ebb2372009-11-22 08:53:50 -0800579}
580EXPORT_SYMBOL_GPL(synchronize_rcu);
581
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800582static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
583static long sync_rcu_preempt_exp_count;
584static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
585
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700586/*
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800587 * Return non-zero if there are any tasks in RCU read-side critical
588 * sections blocking the current preemptible-RCU expedited grace period.
589 * If there is no preemptible-RCU expedited grace period currently in
590 * progress, returns zero unconditionally.
591 */
592static int rcu_preempted_readers_exp(struct rcu_node *rnp)
593{
594 return !list_empty(&rnp->blocked_tasks[2]) ||
595 !list_empty(&rnp->blocked_tasks[3]);
596}
597
598/*
599 * return non-zero if there is no RCU expedited grace period in progress
600 * for the specified rcu_node structure, in other words, if all CPUs and
601 * tasks covered by the specified rcu_node structure have done their bit
602 * for the current expedited grace period. Works only for preemptible
603 * RCU -- other RCU implementation use other means.
604 *
605 * Caller must hold sync_rcu_preempt_exp_mutex.
606 */
607static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
608{
609 return !rcu_preempted_readers_exp(rnp) &&
610 ACCESS_ONCE(rnp->expmask) == 0;
611}
612
613/*
614 * Report the exit from RCU read-side critical section for the last task
615 * that queued itself during or before the current expedited preemptible-RCU
616 * grace period. This event is reported either to the rcu_node structure on
617 * which the task was queued or to one of that rcu_node structure's ancestors,
618 * recursively up the tree. (Calm down, calm down, we do the recursion
619 * iteratively!)
620 *
621 * Caller must hold sync_rcu_preempt_exp_mutex.
622 */
623static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
624{
625 unsigned long flags;
626 unsigned long mask;
627
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800628 raw_spin_lock_irqsave(&rnp->lock, flags);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800629 for (;;) {
630 if (!sync_rcu_preempt_exp_done(rnp))
631 break;
632 if (rnp->parent == NULL) {
633 wake_up(&sync_rcu_preempt_exp_wq);
634 break;
635 }
636 mask = rnp->grpmask;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800637 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800638 rnp = rnp->parent;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800639 raw_spin_lock(&rnp->lock); /* irqs already disabled */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800640 rnp->expmask &= ~mask;
641 }
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800642 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800643}
644
645/*
646 * Snapshot the tasks blocking the newly started preemptible-RCU expedited
647 * grace period for the specified rcu_node structure. If there are no such
648 * tasks, report it up the rcu_node hierarchy.
649 *
650 * Caller must hold sync_rcu_preempt_exp_mutex and rsp->onofflock.
651 */
652static void
653sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp)
654{
655 int must_wait;
656
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800657 raw_spin_lock(&rnp->lock); /* irqs already disabled */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800658 list_splice_init(&rnp->blocked_tasks[0], &rnp->blocked_tasks[2]);
659 list_splice_init(&rnp->blocked_tasks[1], &rnp->blocked_tasks[3]);
660 must_wait = rcu_preempted_readers_exp(rnp);
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800661 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800662 if (!must_wait)
663 rcu_report_exp_rnp(rsp, rnp);
664}
665
666/*
667 * Wait for an rcu-preempt grace period, but expedite it. The basic idea
668 * is to invoke synchronize_sched_expedited() to push all the tasks to
669 * the ->blocked_tasks[] lists, move all entries from the first set of
670 * ->blocked_tasks[] lists to the second set, and finally wait for this
671 * second set to drain.
Paul E. McKenney019129d2009-10-14 10:15:56 -0700672 */
673void synchronize_rcu_expedited(void)
674{
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800675 unsigned long flags;
676 struct rcu_node *rnp;
677 struct rcu_state *rsp = &rcu_preempt_state;
678 long snap;
679 int trycount = 0;
680
681 smp_mb(); /* Caller's modifications seen first by other CPUs. */
682 snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1;
683 smp_mb(); /* Above access cannot bleed into critical section. */
684
685 /*
686 * Acquire lock, falling back to synchronize_rcu() if too many
687 * lock-acquisition failures. Of course, if someone does the
688 * expedited grace period for us, just leave.
689 */
690 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
691 if (trycount++ < 10)
692 udelay(trycount * num_online_cpus());
693 else {
694 synchronize_rcu();
695 return;
696 }
697 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
698 goto mb_ret; /* Others did our work for us. */
699 }
700 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
701 goto unlock_mb_ret; /* Others did our work for us. */
702
703 /* force all RCU readers onto blocked_tasks[]. */
704 synchronize_sched_expedited();
705
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800706 raw_spin_lock_irqsave(&rsp->onofflock, flags);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800707
708 /* Initialize ->expmask for all non-leaf rcu_node structures. */
709 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800710 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800711 rnp->expmask = rnp->qsmaskinit;
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800712 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800713 }
714
715 /* Snapshot current state of ->blocked_tasks[] lists. */
716 rcu_for_each_leaf_node(rsp, rnp)
717 sync_rcu_preempt_exp_init(rsp, rnp);
718 if (NUM_RCU_NODES > 1)
719 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
720
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800721 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800722
723 /* Wait for snapshotted ->blocked_tasks[] lists to drain. */
724 rnp = rcu_get_root(rsp);
725 wait_event(sync_rcu_preempt_exp_wq,
726 sync_rcu_preempt_exp_done(rnp));
727
728 /* Clean up and exit. */
729 smp_mb(); /* ensure expedited GP seen before counter increment. */
730 ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
731unlock_mb_ret:
732 mutex_unlock(&sync_rcu_preempt_exp_mutex);
733mb_ret:
734 smp_mb(); /* ensure subsequent action seen after grace period. */
Paul E. McKenney019129d2009-10-14 10:15:56 -0700735}
736EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
737
738/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700739 * Check to see if there is any immediate preemptable-RCU-related work
740 * to be done.
741 */
742static int rcu_preempt_pending(int cpu)
743{
744 return __rcu_pending(&rcu_preempt_state,
745 &per_cpu(rcu_preempt_data, cpu));
746}
747
748/*
749 * Does preemptable RCU need the CPU to stay out of dynticks mode?
750 */
751static int rcu_preempt_needs_cpu(int cpu)
752{
753 return !!per_cpu(rcu_preempt_data, cpu).nxtlist;
754}
755
Paul E. McKenneye74f4c42009-10-06 21:48:17 -0700756/**
757 * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
758 */
759void rcu_barrier(void)
760{
761 _rcu_barrier(&rcu_preempt_state, call_rcu);
762}
763EXPORT_SYMBOL_GPL(rcu_barrier);
764
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700765/*
766 * Initialize preemptable RCU's per-CPU data.
767 */
768static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
769{
770 rcu_init_percpu_data(cpu, &rcu_preempt_state, 1);
771}
772
773/*
Paul E. McKenneye74f4c42009-10-06 21:48:17 -0700774 * Move preemptable RCU's callbacks to ->orphan_cbs_list.
775 */
776static void rcu_preempt_send_cbs_to_orphanage(void)
777{
778 rcu_send_cbs_to_orphanage(&rcu_preempt_state);
779}
780
781/*
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700782 * Initialize preemptable RCU's state structures.
783 */
784static void __init __rcu_init_preempt(void)
785{
Lai Jiangshan394f99a2010-06-28 16:25:04 +0800786 rcu_init_one(&rcu_preempt_state, &rcu_preempt_data);
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700787}
788
789/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700790 * Check for a task exiting while in a preemptable-RCU read-side
791 * critical section, clean up if so. No need to issue warnings,
792 * as debug_check_no_locks_held() already does this if lockdep
793 * is enabled.
794 */
795void exit_rcu(void)
796{
797 struct task_struct *t = current;
798
799 if (t->rcu_read_lock_nesting == 0)
800 return;
801 t->rcu_read_lock_nesting = 1;
802 rcu_read_unlock();
803}
804
805#else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
806
807/*
808 * Tell them what RCU they are running.
809 */
Paul E. McKenney0e0fc1c2009-11-11 11:28:06 -0800810static void __init rcu_bootup_announce(void)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700811{
812 printk(KERN_INFO "Hierarchical RCU implementation.\n");
Paul E. McKenney26845c22010-04-13 14:19:23 -0700813 rcu_bootup_announce_oddness();
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700814}
815
816/*
817 * Return the number of RCU batches processed thus far for debug & stats.
818 */
819long rcu_batches_completed(void)
820{
821 return rcu_batches_completed_sched();
822}
823EXPORT_SYMBOL_GPL(rcu_batches_completed);
824
825/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800826 * Force a quiescent state for RCU, which, because there is no preemptible
827 * RCU, becomes the same as rcu-sched.
828 */
829void rcu_force_quiescent_state(void)
830{
831 rcu_sched_force_quiescent_state();
832}
833EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
834
835/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700836 * Because preemptable RCU does not exist, we never have to check for
837 * CPUs being in quiescent states.
838 */
Paul E. McKenneyc3422be2009-09-13 09:15:10 -0700839static void rcu_preempt_note_context_switch(int cpu)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700840{
841}
842
Paul E. McKenneyfc2219d2009-09-23 09:50:41 -0700843/*
844 * Because preemptable RCU does not exist, there are never any preempted
845 * RCU readers.
846 */
847static int rcu_preempted_readers(struct rcu_node *rnp)
848{
849 return 0;
850}
851
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800852#ifdef CONFIG_HOTPLUG_CPU
853
854/* Because preemptible RCU does not exist, no quieting of tasks. */
Paul E. McKenneyd3f6bad2009-12-02 12:10:13 -0800855static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800856{
Paul E. McKenney1304afb2010-02-22 17:05:02 -0800857 raw_spin_unlock_irqrestore(&rnp->lock, flags);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800858}
859
860#endif /* #ifdef CONFIG_HOTPLUG_CPU */
861
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700862#ifdef CONFIG_RCU_CPU_STALL_DETECTOR
863
864/*
865 * Because preemptable RCU does not exist, we never have to check for
866 * tasks blocked within RCU read-side critical sections.
867 */
Paul E. McKenney1ed509a2010-02-22 17:05:05 -0800868static void rcu_print_detail_task_stall(struct rcu_state *rsp)
869{
870}
871
872/*
873 * Because preemptable RCU does not exist, we never have to check for
874 * tasks blocked within RCU read-side critical sections.
875 */
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700876static void rcu_print_task_stall(struct rcu_node *rnp)
877{
878}
879
Paul E. McKenney53d84e02010-08-10 14:28:53 -0700880/*
881 * Because preemptible RCU does not exist, there is no need to suppress
882 * its CPU stall warnings.
883 */
884static void rcu_preempt_stall_reset(void)
885{
886}
887
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700888#endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
889
890/*
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700891 * Because there is no preemptable RCU, there can be no readers blocked,
Paul E. McKenney49e29122009-09-18 09:50:19 -0700892 * so there is no need to check for blocked tasks. So check only for
893 * bogus qsmask values.
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700894 */
895static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
896{
Paul E. McKenney49e29122009-09-18 09:50:19 -0700897 WARN_ON_ONCE(rnp->qsmask);
Paul E. McKenneyb0e165c2009-09-13 09:15:09 -0700898}
899
Paul E. McKenney33f76142009-08-24 09:42:01 -0700900#ifdef CONFIG_HOTPLUG_CPU
901
902/*
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700903 * Because preemptable RCU does not exist, it never needs to migrate
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700904 * tasks that were blocked within RCU read-side critical sections, and
905 * such non-existent tasks cannot possibly have been blocking the current
906 * grace period.
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700907 */
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700908static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
909 struct rcu_node *rnp,
910 struct rcu_data *rdp)
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700911{
Paul E. McKenney237c80c2009-10-15 09:26:14 -0700912 return 0;
Paul E. McKenneydd5d19b2009-08-27 14:58:16 -0700913}
914
915/*
Paul E. McKenney33f76142009-08-24 09:42:01 -0700916 * Because preemptable RCU does not exist, it never needs CPU-offline
917 * processing.
918 */
919static void rcu_preempt_offline_cpu(int cpu)
920{
921}
922
923#endif /* #ifdef CONFIG_HOTPLUG_CPU */
924
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700925/*
926 * Because preemptable RCU does not exist, it never has any callbacks
927 * to check.
928 */
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700929static void rcu_preempt_check_callbacks(int cpu)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700930{
931}
932
933/*
934 * Because preemptable RCU does not exist, it never has any callbacks
935 * to process.
936 */
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700937static void rcu_preempt_process_callbacks(void)
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700938{
939}
940
941/*
942 * In classic RCU, call_rcu() is just call_rcu_sched().
943 */
944void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
945{
946 call_rcu_sched(head, func);
947}
948EXPORT_SYMBOL_GPL(call_rcu);
949
950/*
Paul E. McKenney019129d2009-10-14 10:15:56 -0700951 * Wait for an rcu-preempt grace period, but make it happen quickly.
952 * But because preemptable RCU does not exist, map to rcu-sched.
953 */
954void synchronize_rcu_expedited(void)
955{
956 synchronize_sched_expedited();
957}
958EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
959
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800960#ifdef CONFIG_HOTPLUG_CPU
961
962/*
963 * Because preemptable RCU does not exist, there is never any need to
964 * report on tasks preempted in RCU read-side critical sections during
965 * expedited RCU grace periods.
966 */
967static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
968{
969 return;
970}
971
972#endif /* #ifdef CONFIG_HOTPLUG_CPU */
973
Paul E. McKenney019129d2009-10-14 10:15:56 -0700974/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700975 * Because preemptable RCU does not exist, it never has any work to do.
976 */
977static int rcu_preempt_pending(int cpu)
978{
979 return 0;
980}
981
982/*
983 * Because preemptable RCU does not exist, it never needs any CPU.
984 */
985static int rcu_preempt_needs_cpu(int cpu)
986{
987 return 0;
988}
989
990/*
Paul E. McKenneye74f4c42009-10-06 21:48:17 -0700991 * Because preemptable RCU does not exist, rcu_barrier() is just
992 * another name for rcu_barrier_sched().
993 */
994void rcu_barrier(void)
995{
996 rcu_barrier_sched();
997}
998EXPORT_SYMBOL_GPL(rcu_barrier);
999
1000/*
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001001 * Because preemptable RCU does not exist, there is no per-CPU
1002 * data to initialize.
1003 */
1004static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
1005{
1006}
1007
Paul E. McKenney1eba8f82009-09-23 09:50:42 -07001008/*
Paul E. McKenneye74f4c42009-10-06 21:48:17 -07001009 * Because there is no preemptable RCU, there are no callbacks to move.
1010 */
1011static void rcu_preempt_send_cbs_to_orphanage(void)
1012{
1013}
1014
1015/*
Paul E. McKenney1eba8f82009-09-23 09:50:42 -07001016 * Because preemptable RCU does not exist, it need not be initialized.
1017 */
1018static void __init __rcu_init_preempt(void)
1019{
1020}
1021
Paul E. McKenneyf41d9112009-08-22 13:56:52 -07001022#endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001023
1024#if !defined(CONFIG_RCU_FAST_NO_HZ)
1025
1026/*
1027 * Check to see if any future RCU-related work will need to be done
1028 * by the current CPU, even if none need be done immediately, returning
1029 * 1 if so. This function is part of the RCU implementation; it is -not-
1030 * an exported member of the RCU API.
1031 *
1032 * Because we have preemptible RCU, just check whether this CPU needs
1033 * any flavor of RCU. Do not chew up lots of CPU cycles with preemption
1034 * disabled in a most-likely vain attempt to cause RCU not to need this CPU.
1035 */
1036int rcu_needs_cpu(int cpu)
1037{
1038 return rcu_needs_cpu_quick_check(cpu);
1039}
1040
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001041/*
1042 * Check to see if we need to continue a callback-flush operations to
1043 * allow the last CPU to enter dyntick-idle mode. But fast dyntick-idle
1044 * entry is not configured, so we never do need to.
1045 */
1046static void rcu_needs_cpu_flush(void)
1047{
1048}
1049
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001050#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
1051
1052#define RCU_NEEDS_CPU_FLUSHES 5
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001053static DEFINE_PER_CPU(int, rcu_dyntick_drain);
Paul E. McKenney71da8132010-02-26 16:38:58 -08001054static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001055
1056/*
1057 * Check to see if any future RCU-related work will need to be done
1058 * by the current CPU, even if none need be done immediately, returning
1059 * 1 if so. This function is part of the RCU implementation; it is -not-
1060 * an exported member of the RCU API.
1061 *
1062 * Because we are not supporting preemptible RCU, attempt to accelerate
1063 * any current grace periods so that RCU no longer needs this CPU, but
1064 * only if all other CPUs are already in dynticks-idle mode. This will
1065 * allow the CPU cores to be powered down immediately, as opposed to after
1066 * waiting many milliseconds for grace periods to elapse.
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001067 *
1068 * Because it is not legal to invoke rcu_process_callbacks() with irqs
1069 * disabled, we do one pass of force_quiescent_state(), then do a
1070 * raise_softirq() to cause rcu_process_callbacks() to be invoked later.
1071 * The per-cpu rcu_dyntick_drain variable controls the sequencing.
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001072 */
1073int rcu_needs_cpu(int cpu)
1074{
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001075 int c = 0;
Paul E. McKenney77e38ed2010-04-25 21:04:29 -07001076 int snap;
1077 int snap_nmi;
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001078 int thatcpu;
1079
Paul E. McKenney622ea682010-02-27 14:53:07 -08001080 /* Check for being in the holdoff period. */
1081 if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies)
1082 return rcu_needs_cpu_quick_check(cpu);
1083
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001084 /* Don't bother unless we are the last non-dyntick-idle CPU. */
Paul E. McKenney77e38ed2010-04-25 21:04:29 -07001085 for_each_online_cpu(thatcpu) {
1086 if (thatcpu == cpu)
1087 continue;
Paul E. McKenneyd822ed12010-05-08 19:58:22 -07001088 snap = per_cpu(rcu_dynticks, thatcpu).dynticks;
1089 snap_nmi = per_cpu(rcu_dynticks, thatcpu).dynticks_nmi;
Paul E. McKenney77e38ed2010-04-25 21:04:29 -07001090 smp_mb(); /* Order sampling of snap with end of grace period. */
1091 if (((snap & 0x1) != 0) || ((snap_nmi & 0x1) != 0)) {
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001092 per_cpu(rcu_dyntick_drain, cpu) = 0;
Paul E. McKenney71da8132010-02-26 16:38:58 -08001093 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001094 return rcu_needs_cpu_quick_check(cpu);
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001095 }
Paul E. McKenney77e38ed2010-04-25 21:04:29 -07001096 }
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001097
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001098 /* Check and update the rcu_dyntick_drain sequencing. */
1099 if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1100 /* First time through, initialize the counter. */
1101 per_cpu(rcu_dyntick_drain, cpu) = RCU_NEEDS_CPU_FLUSHES;
1102 } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1103 /* We have hit the limit, so time to give up. */
Paul E. McKenney71da8132010-02-26 16:38:58 -08001104 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001105 return rcu_needs_cpu_quick_check(cpu);
1106 }
1107
1108 /* Do one step pushing remaining RCU callbacks through. */
1109 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
1110 rcu_sched_qs(cpu);
1111 force_quiescent_state(&rcu_sched_state, 0);
1112 c = c || per_cpu(rcu_sched_data, cpu).nxtlist;
1113 }
1114 if (per_cpu(rcu_bh_data, cpu).nxtlist) {
1115 rcu_bh_qs(cpu);
1116 force_quiescent_state(&rcu_bh_state, 0);
1117 c = c || per_cpu(rcu_bh_data, cpu).nxtlist;
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001118 }
1119
1120 /* If RCU callbacks are still pending, RCU still needs this CPU. */
Paul E. McKenney622ea682010-02-27 14:53:07 -08001121 if (c)
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001122 raise_softirq(RCU_SOFTIRQ);
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001123 return c;
1124}
1125
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001126/*
1127 * Check to see if we need to continue a callback-flush operations to
1128 * allow the last CPU to enter dyntick-idle mode.
1129 */
1130static void rcu_needs_cpu_flush(void)
1131{
1132 int cpu = smp_processor_id();
Paul E. McKenney71da8132010-02-26 16:38:58 -08001133 unsigned long flags;
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001134
1135 if (per_cpu(rcu_dyntick_drain, cpu) <= 0)
1136 return;
Paul E. McKenney71da8132010-02-26 16:38:58 -08001137 local_irq_save(flags);
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001138 (void)rcu_needs_cpu(cpu);
Paul E. McKenney71da8132010-02-26 16:38:58 -08001139 local_irq_restore(flags);
Paul E. McKenneya47cd882010-02-26 16:38:56 -08001140}
1141
Paul E. McKenney8bd93a22010-02-22 17:04:59 -08001142#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */