]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - kernel/rcutree_plugin.h
rcu: Rework detection of use of RCU by offline CPUs
[mirror_ubuntu-bionic-kernel.git] / kernel / rcutree_plugin.h
CommitLineData
f41d911f
PM
1/*
2 * Read-Copy Update mechanism for mutual exclusion (tree-based version)
3 * Internal non-public definitions that provide either classic
6cc68793 4 * or preemptible semantics.
f41d911f
PM
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
d9a3da06 27#include <linux/delay.h>
f41d911f 28
5b61b0ba
MG
29#define RCU_KTHREAD_PRIO 1
30
31#ifdef CONFIG_RCU_BOOST
32#define RCU_BOOST_PRIO CONFIG_RCU_BOOST_PRIO
33#else
34#define RCU_BOOST_PRIO RCU_KTHREAD_PRIO
35#endif
36
26845c28
PM
37/*
38 * Check the RCU kernel configuration parameters and print informative
39 * messages about anything out of the ordinary. If you like #ifdef, you
40 * will love this function.
41 */
42static void __init rcu_bootup_announce_oddness(void)
43{
44#ifdef CONFIG_RCU_TRACE
45 printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n");
46#endif
47#if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)
48 printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
49 CONFIG_RCU_FANOUT);
50#endif
51#ifdef CONFIG_RCU_FANOUT_EXACT
52 printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n");
53#endif
54#ifdef CONFIG_RCU_FAST_NO_HZ
55 printk(KERN_INFO
56 "\tRCU dyntick-idle grace-period acceleration is enabled.\n");
57#endif
58#ifdef CONFIG_PROVE_RCU
59 printk(KERN_INFO "\tRCU lockdep checking is enabled.\n");
60#endif
61#ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE
62 printk(KERN_INFO "\tRCU torture testing starts during boot.\n");
63#endif
81a294c4 64#if defined(CONFIG_TREE_PREEMPT_RCU) && !defined(CONFIG_RCU_CPU_STALL_VERBOSE)
a858af28
PM
65 printk(KERN_INFO "\tDump stacks of tasks blocking RCU-preempt GP.\n");
66#endif
67#if defined(CONFIG_RCU_CPU_STALL_INFO)
68 printk(KERN_INFO "\tAdditional per-CPU info printed with stalls.\n");
26845c28
PM
69#endif
70#if NUM_RCU_LVL_4 != 0
71 printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n");
72#endif
73}
74
f41d911f
PM
75#ifdef CONFIG_TREE_PREEMPT_RCU
76
e99033c5 77struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt);
f41d911f 78DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data);
27f4d280 79static struct rcu_state *rcu_state = &rcu_preempt_state;
f41d911f 80
10f39bb1 81static void rcu_read_unlock_special(struct task_struct *t);
d9a3da06
PM
82static int rcu_preempted_readers_exp(struct rcu_node *rnp);
83
f41d911f
PM
84/*
85 * Tell them what RCU they are running.
86 */
0e0fc1c2 87static void __init rcu_bootup_announce(void)
f41d911f 88{
6cc68793 89 printk(KERN_INFO "Preemptible hierarchical RCU implementation.\n");
26845c28 90 rcu_bootup_announce_oddness();
f41d911f
PM
91}
92
93/*
94 * Return the number of RCU-preempt batches processed thus far
95 * for debug and statistics.
96 */
97long rcu_batches_completed_preempt(void)
98{
99 return rcu_preempt_state.completed;
100}
101EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt);
102
103/*
104 * Return the number of RCU batches processed thus far for debug & stats.
105 */
106long rcu_batches_completed(void)
107{
108 return rcu_batches_completed_preempt();
109}
110EXPORT_SYMBOL_GPL(rcu_batches_completed);
111
bf66f18e
PM
112/*
113 * Force a quiescent state for preemptible RCU.
114 */
115void rcu_force_quiescent_state(void)
116{
117 force_quiescent_state(&rcu_preempt_state, 0);
118}
119EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
120
f41d911f 121/*
6cc68793 122 * Record a preemptible-RCU quiescent state for the specified CPU. Note
f41d911f
PM
123 * that this just means that the task currently running on the CPU is
124 * not in a quiescent state. There might be any number of tasks blocked
125 * while in an RCU read-side critical section.
25502a6c
PM
126 *
127 * Unlike the other rcu_*_qs() functions, callers to this function
128 * must disable irqs in order to protect the assignment to
129 * ->rcu_read_unlock_special.
f41d911f 130 */
c3422bea 131static void rcu_preempt_qs(int cpu)
f41d911f
PM
132{
133 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
25502a6c 134
e4cc1f22 135 rdp->passed_quiesce_gpnum = rdp->gpnum;
c3422bea 136 barrier();
e4cc1f22 137 if (rdp->passed_quiesce == 0)
d4c08f2a 138 trace_rcu_grace_period("rcu_preempt", rdp->gpnum, "cpuqs");
e4cc1f22 139 rdp->passed_quiesce = 1;
25502a6c 140 current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
f41d911f
PM
141}
142
143/*
c3422bea
PM
144 * We have entered the scheduler, and the current task might soon be
145 * context-switched away from. If this task is in an RCU read-side
146 * critical section, we will no longer be able to rely on the CPU to
12f5f524
PM
147 * record that fact, so we enqueue the task on the blkd_tasks list.
148 * The task will dequeue itself when it exits the outermost enclosing
149 * RCU read-side critical section. Therefore, the current grace period
150 * cannot be permitted to complete until the blkd_tasks list entries
151 * predating the current grace period drain, in other words, until
152 * rnp->gp_tasks becomes NULL.
c3422bea
PM
153 *
154 * Caller must disable preemption.
f41d911f 155 */
c3422bea 156static void rcu_preempt_note_context_switch(int cpu)
f41d911f
PM
157{
158 struct task_struct *t = current;
c3422bea 159 unsigned long flags;
f41d911f
PM
160 struct rcu_data *rdp;
161 struct rcu_node *rnp;
162
10f39bb1 163 if (t->rcu_read_lock_nesting > 0 &&
f41d911f
PM
164 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
165
166 /* Possibly blocking in an RCU read-side critical section. */
394f99a9 167 rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu);
f41d911f 168 rnp = rdp->mynode;
1304afb2 169 raw_spin_lock_irqsave(&rnp->lock, flags);
f41d911f 170 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
86848966 171 t->rcu_blocked_node = rnp;
f41d911f
PM
172
173 /*
174 * If this CPU has already checked in, then this task
175 * will hold up the next grace period rather than the
176 * current grace period. Queue the task accordingly.
177 * If the task is queued for the current grace period
178 * (i.e., this CPU has not yet passed through a quiescent
179 * state for the current grace period), then as long
180 * as that task remains queued, the current grace period
12f5f524
PM
181 * cannot end. Note that there is some uncertainty as
182 * to exactly when the current grace period started.
183 * We take a conservative approach, which can result
184 * in unnecessarily waiting on tasks that started very
185 * slightly after the current grace period began. C'est
186 * la vie!!!
b0e165c0
PM
187 *
188 * But first, note that the current CPU must still be
189 * on line!
f41d911f 190 */
b0e165c0 191 WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
e7d8842e 192 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
12f5f524
PM
193 if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) {
194 list_add(&t->rcu_node_entry, rnp->gp_tasks->prev);
195 rnp->gp_tasks = &t->rcu_node_entry;
27f4d280
PM
196#ifdef CONFIG_RCU_BOOST
197 if (rnp->boost_tasks != NULL)
198 rnp->boost_tasks = rnp->gp_tasks;
199#endif /* #ifdef CONFIG_RCU_BOOST */
12f5f524
PM
200 } else {
201 list_add(&t->rcu_node_entry, &rnp->blkd_tasks);
202 if (rnp->qsmask & rdp->grpmask)
203 rnp->gp_tasks = &t->rcu_node_entry;
204 }
d4c08f2a
PM
205 trace_rcu_preempt_task(rdp->rsp->name,
206 t->pid,
207 (rnp->qsmask & rdp->grpmask)
208 ? rnp->gpnum
209 : rnp->gpnum + 1);
1304afb2 210 raw_spin_unlock_irqrestore(&rnp->lock, flags);
10f39bb1
PM
211 } else if (t->rcu_read_lock_nesting < 0 &&
212 t->rcu_read_unlock_special) {
213
214 /*
215 * Complete exit from RCU read-side critical section on
216 * behalf of preempted instance of __rcu_read_unlock().
217 */
218 rcu_read_unlock_special(t);
f41d911f
PM
219 }
220
221 /*
222 * Either we were not in an RCU read-side critical section to
223 * begin with, or we have now recorded that critical section
224 * globally. Either way, we can now note a quiescent state
225 * for this CPU. Again, if we were in an RCU read-side critical
226 * section, and if that critical section was blocking the current
227 * grace period, then the fact that the task has been enqueued
228 * means that we continue to block the current grace period.
229 */
e7d8842e 230 local_irq_save(flags);
25502a6c 231 rcu_preempt_qs(cpu);
e7d8842e 232 local_irq_restore(flags);
f41d911f
PM
233}
234
235/*
6cc68793 236 * Tree-preemptible RCU implementation for rcu_read_lock().
f41d911f
PM
237 * Just increment ->rcu_read_lock_nesting, shared state will be updated
238 * if we block.
239 */
240void __rcu_read_lock(void)
241{
80dcf60e 242 current->rcu_read_lock_nesting++;
f41d911f
PM
243 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
244}
245EXPORT_SYMBOL_GPL(__rcu_read_lock);
246
fc2219d4
PM
247/*
248 * Check for preempted RCU readers blocking the current grace period
249 * for the specified rcu_node structure. If the caller needs a reliable
250 * answer, it must hold the rcu_node's ->lock.
251 */
27f4d280 252static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
fc2219d4 253{
12f5f524 254 return rnp->gp_tasks != NULL;
fc2219d4
PM
255}
256
b668c9cf
PM
257/*
258 * Record a quiescent state for all tasks that were previously queued
259 * on the specified rcu_node structure and that were blocking the current
260 * RCU grace period. The caller must hold the specified rnp->lock with
261 * irqs disabled, and this lock is released upon return, but irqs remain
262 * disabled.
263 */
d3f6bad3 264static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
b668c9cf
PM
265 __releases(rnp->lock)
266{
267 unsigned long mask;
268 struct rcu_node *rnp_p;
269
27f4d280 270 if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
1304afb2 271 raw_spin_unlock_irqrestore(&rnp->lock, flags);
b668c9cf
PM
272 return; /* Still need more quiescent states! */
273 }
274
275 rnp_p = rnp->parent;
276 if (rnp_p == NULL) {
277 /*
278 * Either there is only one rcu_node in the tree,
279 * or tasks were kicked up to root rcu_node due to
280 * CPUs going offline.
281 */
d3f6bad3 282 rcu_report_qs_rsp(&rcu_preempt_state, flags);
b668c9cf
PM
283 return;
284 }
285
286 /* Report up the rest of the hierarchy. */
287 mask = rnp->grpmask;
1304afb2
PM
288 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
289 raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */
d3f6bad3 290 rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
b668c9cf
PM
291}
292
12f5f524
PM
293/*
294 * Advance a ->blkd_tasks-list pointer to the next entry, instead
295 * returning NULL if at the end of the list.
296 */
297static struct list_head *rcu_next_node_entry(struct task_struct *t,
298 struct rcu_node *rnp)
299{
300 struct list_head *np;
301
302 np = t->rcu_node_entry.next;
303 if (np == &rnp->blkd_tasks)
304 np = NULL;
305 return np;
306}
307
b668c9cf
PM
308/*
309 * Handle special cases during rcu_read_unlock(), such as needing to
310 * notify RCU core processing or task having blocked during the RCU
311 * read-side critical section.
312 */
be0e1e21 313static noinline void rcu_read_unlock_special(struct task_struct *t)
f41d911f
PM
314{
315 int empty;
d9a3da06 316 int empty_exp;
389abd48 317 int empty_exp_now;
f41d911f 318 unsigned long flags;
12f5f524 319 struct list_head *np;
82e78d80
PM
320#ifdef CONFIG_RCU_BOOST
321 struct rt_mutex *rbmp = NULL;
322#endif /* #ifdef CONFIG_RCU_BOOST */
f41d911f
PM
323 struct rcu_node *rnp;
324 int special;
325
326 /* NMI handlers cannot block and cannot safely manipulate state. */
327 if (in_nmi())
328 return;
329
330 local_irq_save(flags);
331
332 /*
333 * If RCU core is waiting for this CPU to exit critical section,
334 * let it know that we have done so.
335 */
336 special = t->rcu_read_unlock_special;
337 if (special & RCU_READ_UNLOCK_NEED_QS) {
c3422bea 338 rcu_preempt_qs(smp_processor_id());
f41d911f
PM
339 }
340
341 /* Hardware IRQ handlers cannot block. */
ec433f0c 342 if (in_irq() || in_serving_softirq()) {
f41d911f
PM
343 local_irq_restore(flags);
344 return;
345 }
346
347 /* Clean up if blocked during RCU read-side critical section. */
348 if (special & RCU_READ_UNLOCK_BLOCKED) {
349 t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED;
350
dd5d19ba
PM
351 /*
352 * Remove this task from the list it blocked on. The
353 * task can migrate while we acquire the lock, but at
354 * most one time. So at most two passes through loop.
355 */
356 for (;;) {
86848966 357 rnp = t->rcu_blocked_node;
1304afb2 358 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
86848966 359 if (rnp == t->rcu_blocked_node)
dd5d19ba 360 break;
1304afb2 361 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
dd5d19ba 362 }
27f4d280 363 empty = !rcu_preempt_blocked_readers_cgp(rnp);
d9a3da06
PM
364 empty_exp = !rcu_preempted_readers_exp(rnp);
365 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
12f5f524 366 np = rcu_next_node_entry(t, rnp);
f41d911f 367 list_del_init(&t->rcu_node_entry);
82e78d80 368 t->rcu_blocked_node = NULL;
d4c08f2a
PM
369 trace_rcu_unlock_preempted_task("rcu_preempt",
370 rnp->gpnum, t->pid);
12f5f524
PM
371 if (&t->rcu_node_entry == rnp->gp_tasks)
372 rnp->gp_tasks = np;
373 if (&t->rcu_node_entry == rnp->exp_tasks)
374 rnp->exp_tasks = np;
27f4d280
PM
375#ifdef CONFIG_RCU_BOOST
376 if (&t->rcu_node_entry == rnp->boost_tasks)
377 rnp->boost_tasks = np;
82e78d80
PM
378 /* Snapshot/clear ->rcu_boost_mutex with rcu_node lock held. */
379 if (t->rcu_boost_mutex) {
380 rbmp = t->rcu_boost_mutex;
381 t->rcu_boost_mutex = NULL;
7765be2f 382 }
27f4d280 383#endif /* #ifdef CONFIG_RCU_BOOST */
f41d911f
PM
384
385 /*
386 * If this was the last task on the current list, and if
387 * we aren't waiting on any CPUs, report the quiescent state.
389abd48
PM
388 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,
389 * so we must take a snapshot of the expedited state.
f41d911f 390 */
389abd48 391 empty_exp_now = !rcu_preempted_readers_exp(rnp);
d4c08f2a
PM
392 if (!empty && !rcu_preempt_blocked_readers_cgp(rnp)) {
393 trace_rcu_quiescent_state_report("preempt_rcu",
394 rnp->gpnum,
395 0, rnp->qsmask,
396 rnp->level,
397 rnp->grplo,
398 rnp->grphi,
399 !!rnp->gp_tasks);
d3f6bad3 400 rcu_report_unblock_qs_rnp(rnp, flags);
d4c08f2a
PM
401 } else
402 raw_spin_unlock_irqrestore(&rnp->lock, flags);
d9a3da06 403
27f4d280
PM
404#ifdef CONFIG_RCU_BOOST
405 /* Unboost if we were boosted. */
82e78d80
PM
406 if (rbmp)
407 rt_mutex_unlock(rbmp);
27f4d280
PM
408#endif /* #ifdef CONFIG_RCU_BOOST */
409
d9a3da06
PM
410 /*
411 * If this was the last task on the expedited lists,
412 * then we need to report up the rcu_node hierarchy.
413 */
389abd48 414 if (!empty_exp && empty_exp_now)
b40d293e 415 rcu_report_exp_rnp(&rcu_preempt_state, rnp, true);
b668c9cf
PM
416 } else {
417 local_irq_restore(flags);
f41d911f 418 }
f41d911f
PM
419}
420
421/*
6cc68793 422 * Tree-preemptible RCU implementation for rcu_read_unlock().
f41d911f
PM
423 * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost
424 * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then
425 * invoke rcu_read_unlock_special() to clean up after a context switch
426 * in an RCU read-side critical section and other special cases.
427 */
428void __rcu_read_unlock(void)
429{
430 struct task_struct *t = current;
431
10f39bb1
PM
432 if (t->rcu_read_lock_nesting != 1)
433 --t->rcu_read_lock_nesting;
434 else {
6206ab9b 435 barrier(); /* critical section before exit code. */
10f39bb1
PM
436 t->rcu_read_lock_nesting = INT_MIN;
437 barrier(); /* assign before ->rcu_read_unlock_special load */
be0e1e21
PM
438 if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
439 rcu_read_unlock_special(t);
10f39bb1
PM
440 barrier(); /* ->rcu_read_unlock_special load before assign */
441 t->rcu_read_lock_nesting = 0;
be0e1e21 442 }
cba8244a 443#ifdef CONFIG_PROVE_LOCKING
10f39bb1
PM
444 {
445 int rrln = ACCESS_ONCE(t->rcu_read_lock_nesting);
446
447 WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2);
448 }
cba8244a 449#endif /* #ifdef CONFIG_PROVE_LOCKING */
f41d911f
PM
450}
451EXPORT_SYMBOL_GPL(__rcu_read_unlock);
452
1ed509a2
PM
453#ifdef CONFIG_RCU_CPU_STALL_VERBOSE
454
455/*
456 * Dump detailed information for all tasks blocking the current RCU
457 * grace period on the specified rcu_node structure.
458 */
459static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
460{
461 unsigned long flags;
1ed509a2
PM
462 struct task_struct *t;
463
27f4d280 464 if (!rcu_preempt_blocked_readers_cgp(rnp))
12f5f524
PM
465 return;
466 raw_spin_lock_irqsave(&rnp->lock, flags);
467 t = list_entry(rnp->gp_tasks,
468 struct task_struct, rcu_node_entry);
469 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
470 sched_show_task(t);
471 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1ed509a2
PM
472}
473
474/*
475 * Dump detailed information for all tasks blocking the current RCU
476 * grace period.
477 */
478static void rcu_print_detail_task_stall(struct rcu_state *rsp)
479{
480 struct rcu_node *rnp = rcu_get_root(rsp);
481
482 rcu_print_detail_task_stall_rnp(rnp);
483 rcu_for_each_leaf_node(rsp, rnp)
484 rcu_print_detail_task_stall_rnp(rnp);
485}
486
487#else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
488
489static void rcu_print_detail_task_stall(struct rcu_state *rsp)
490{
491}
492
493#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
494
a858af28
PM
495#ifdef CONFIG_RCU_CPU_STALL_INFO
496
497static void rcu_print_task_stall_begin(struct rcu_node *rnp)
498{
499 printk(KERN_ERR "\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
500 rnp->level, rnp->grplo, rnp->grphi);
501}
502
503static void rcu_print_task_stall_end(void)
504{
505 printk(KERN_CONT "\n");
506}
507
508#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
509
510static void rcu_print_task_stall_begin(struct rcu_node *rnp)
511{
512}
513
514static void rcu_print_task_stall_end(void)
515{
516}
517
518#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */
519
f41d911f
PM
520/*
521 * Scan the current list of tasks blocked within RCU read-side critical
522 * sections, printing out the tid of each.
523 */
9bc8b558 524static int rcu_print_task_stall(struct rcu_node *rnp)
f41d911f 525{
f41d911f 526 struct task_struct *t;
9bc8b558 527 int ndetected = 0;
f41d911f 528
27f4d280 529 if (!rcu_preempt_blocked_readers_cgp(rnp))
9bc8b558 530 return 0;
a858af28 531 rcu_print_task_stall_begin(rnp);
12f5f524
PM
532 t = list_entry(rnp->gp_tasks,
533 struct task_struct, rcu_node_entry);
9bc8b558 534 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
a858af28 535 printk(KERN_CONT " P%d", t->pid);
9bc8b558
PM
536 ndetected++;
537 }
a858af28 538 rcu_print_task_stall_end();
9bc8b558 539 return ndetected;
f41d911f
PM
540}
541
53d84e00
PM
542/*
543 * Suppress preemptible RCU's CPU stall warnings by pushing the
544 * time of the next stall-warning message comfortably far into the
545 * future.
546 */
547static void rcu_preempt_stall_reset(void)
548{
549 rcu_preempt_state.jiffies_stall = jiffies + ULONG_MAX / 2;
550}
551
b0e165c0
PM
552/*
553 * Check that the list of blocked tasks for the newly completed grace
554 * period is in fact empty. It is a serious bug to complete a grace
555 * period that still has RCU readers blocked! This function must be
556 * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
557 * must be held by the caller.
12f5f524
PM
558 *
559 * Also, if there are blocked tasks on the list, they automatically
560 * block the newly created grace period, so set up ->gp_tasks accordingly.
b0e165c0
PM
561 */
562static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
563{
27f4d280 564 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp));
12f5f524
PM
565 if (!list_empty(&rnp->blkd_tasks))
566 rnp->gp_tasks = rnp->blkd_tasks.next;
28ecd580 567 WARN_ON_ONCE(rnp->qsmask);
b0e165c0
PM
568}
569
33f76148
PM
570#ifdef CONFIG_HOTPLUG_CPU
571
dd5d19ba
PM
572/*
573 * Handle tasklist migration for case in which all CPUs covered by the
574 * specified rcu_node have gone offline. Move them up to the root
575 * rcu_node. The reason for not just moving them to the immediate
576 * parent is to remove the need for rcu_read_unlock_special() to
577 * make more than two attempts to acquire the target rcu_node's lock.
b668c9cf
PM
578 * Returns true if there were tasks blocking the current RCU grace
579 * period.
dd5d19ba 580 *
237c80c5
PM
581 * Returns 1 if there was previously a task blocking the current grace
582 * period on the specified rcu_node structure.
583 *
dd5d19ba
PM
584 * The caller must hold rnp->lock with irqs disabled.
585 */
237c80c5
PM
586static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
587 struct rcu_node *rnp,
588 struct rcu_data *rdp)
dd5d19ba 589{
dd5d19ba
PM
590 struct list_head *lp;
591 struct list_head *lp_root;
d9a3da06 592 int retval = 0;
dd5d19ba 593 struct rcu_node *rnp_root = rcu_get_root(rsp);
12f5f524 594 struct task_struct *t;
dd5d19ba 595
86848966
PM
596 if (rnp == rnp_root) {
597 WARN_ONCE(1, "Last CPU thought to be offlined?");
237c80c5 598 return 0; /* Shouldn't happen: at least one CPU online. */
86848966 599 }
12f5f524
PM
600
601 /* If we are on an internal node, complain bitterly. */
602 WARN_ON_ONCE(rnp != rdp->mynode);
dd5d19ba
PM
603
604 /*
12f5f524
PM
605 * Move tasks up to root rcu_node. Don't try to get fancy for
606 * this corner-case operation -- just put this node's tasks
607 * at the head of the root node's list, and update the root node's
608 * ->gp_tasks and ->exp_tasks pointers to those of this node's,
609 * if non-NULL. This might result in waiting for more tasks than
610 * absolutely necessary, but this is a good performance/complexity
611 * tradeoff.
dd5d19ba 612 */
2036d94a 613 if (rcu_preempt_blocked_readers_cgp(rnp) && rnp->qsmask == 0)
d9a3da06
PM
614 retval |= RCU_OFL_TASKS_NORM_GP;
615 if (rcu_preempted_readers_exp(rnp))
616 retval |= RCU_OFL_TASKS_EXP_GP;
12f5f524
PM
617 lp = &rnp->blkd_tasks;
618 lp_root = &rnp_root->blkd_tasks;
619 while (!list_empty(lp)) {
620 t = list_entry(lp->next, typeof(*t), rcu_node_entry);
621 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
622 list_del(&t->rcu_node_entry);
623 t->rcu_blocked_node = rnp_root;
624 list_add(&t->rcu_node_entry, lp_root);
625 if (&t->rcu_node_entry == rnp->gp_tasks)
626 rnp_root->gp_tasks = rnp->gp_tasks;
627 if (&t->rcu_node_entry == rnp->exp_tasks)
628 rnp_root->exp_tasks = rnp->exp_tasks;
27f4d280
PM
629#ifdef CONFIG_RCU_BOOST
630 if (&t->rcu_node_entry == rnp->boost_tasks)
631 rnp_root->boost_tasks = rnp->boost_tasks;
632#endif /* #ifdef CONFIG_RCU_BOOST */
12f5f524 633 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
dd5d19ba 634 }
27f4d280
PM
635
636#ifdef CONFIG_RCU_BOOST
637 /* In case root is being boosted and leaf is not. */
638 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
639 if (rnp_root->boost_tasks != NULL &&
640 rnp_root->boost_tasks != rnp_root->gp_tasks)
641 rnp_root->boost_tasks = rnp_root->gp_tasks;
642 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
643#endif /* #ifdef CONFIG_RCU_BOOST */
644
12f5f524
PM
645 rnp->gp_tasks = NULL;
646 rnp->exp_tasks = NULL;
237c80c5 647 return retval;
dd5d19ba
PM
648}
649
e5601400
PM
650#endif /* #ifdef CONFIG_HOTPLUG_CPU */
651
33f76148 652/*
6cc68793 653 * Do CPU-offline processing for preemptible RCU.
33f76148 654 */
e5601400 655static void rcu_preempt_cleanup_dead_cpu(int cpu)
33f76148 656{
e5601400 657 rcu_cleanup_dead_cpu(cpu, &rcu_preempt_state);
33f76148
PM
658}
659
f41d911f
PM
660/*
661 * Check for a quiescent state from the current CPU. When a task blocks,
662 * the task is recorded in the corresponding CPU's rcu_node structure,
663 * which is checked elsewhere.
664 *
665 * Caller must disable hard irqs.
666 */
667static void rcu_preempt_check_callbacks(int cpu)
668{
669 struct task_struct *t = current;
670
671 if (t->rcu_read_lock_nesting == 0) {
c3422bea 672 rcu_preempt_qs(cpu);
f41d911f
PM
673 return;
674 }
10f39bb1
PM
675 if (t->rcu_read_lock_nesting > 0 &&
676 per_cpu(rcu_preempt_data, cpu).qs_pending)
c3422bea 677 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
f41d911f
PM
678}
679
680/*
6cc68793 681 * Process callbacks for preemptible RCU.
f41d911f
PM
682 */
683static void rcu_preempt_process_callbacks(void)
684{
685 __rcu_process_callbacks(&rcu_preempt_state,
686 &__get_cpu_var(rcu_preempt_data));
687}
688
a46e0899
PM
689#ifdef CONFIG_RCU_BOOST
690
09223371
SL
691static void rcu_preempt_do_callbacks(void)
692{
693 rcu_do_batch(&rcu_preempt_state, &__get_cpu_var(rcu_preempt_data));
694}
695
a46e0899
PM
696#endif /* #ifdef CONFIG_RCU_BOOST */
697
f41d911f 698/*
6cc68793 699 * Queue a preemptible-RCU callback for invocation after a grace period.
f41d911f
PM
700 */
701void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
702{
486e2593 703 __call_rcu(head, func, &rcu_preempt_state, 0);
f41d911f
PM
704}
705EXPORT_SYMBOL_GPL(call_rcu);
706
486e2593
PM
707/*
708 * Queue an RCU callback for lazy invocation after a grace period.
709 * This will likely be later named something like "call_rcu_lazy()",
710 * but this change will require some way of tagging the lazy RCU
711 * callbacks in the list of pending callbacks. Until then, this
712 * function may only be called from __kfree_rcu().
713 */
714void kfree_call_rcu(struct rcu_head *head,
715 void (*func)(struct rcu_head *rcu))
716{
717 __call_rcu(head, func, &rcu_preempt_state, 1);
718}
719EXPORT_SYMBOL_GPL(kfree_call_rcu);
720
6ebb237b
PM
721/**
722 * synchronize_rcu - wait until a grace period has elapsed.
723 *
724 * Control will return to the caller some time after a full grace
725 * period has elapsed, in other words after all currently executing RCU
77d8485a
PM
726 * read-side critical sections have completed. Note, however, that
727 * upon return from synchronize_rcu(), the caller might well be executing
728 * concurrently with new RCU read-side critical sections that began while
729 * synchronize_rcu() was waiting. RCU read-side critical sections are
730 * delimited by rcu_read_lock() and rcu_read_unlock(), and may be nested.
6ebb237b
PM
731 */
732void synchronize_rcu(void)
733{
fe15d706
PM
734 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
735 !lock_is_held(&rcu_lock_map) &&
736 !lock_is_held(&rcu_sched_lock_map),
737 "Illegal synchronize_rcu() in RCU read-side critical section");
6ebb237b
PM
738 if (!rcu_scheduler_active)
739 return;
2c42818e 740 wait_rcu_gp(call_rcu);
6ebb237b
PM
741}
742EXPORT_SYMBOL_GPL(synchronize_rcu);
743
d9a3da06
PM
744static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
745static long sync_rcu_preempt_exp_count;
746static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
747
748/*
749 * Return non-zero if there are any tasks in RCU read-side critical
750 * sections blocking the current preemptible-RCU expedited grace period.
751 * If there is no preemptible-RCU expedited grace period currently in
752 * progress, returns zero unconditionally.
753 */
754static int rcu_preempted_readers_exp(struct rcu_node *rnp)
755{
12f5f524 756 return rnp->exp_tasks != NULL;
d9a3da06
PM
757}
758
759/*
760 * return non-zero if there is no RCU expedited grace period in progress
761 * for the specified rcu_node structure, in other words, if all CPUs and
762 * tasks covered by the specified rcu_node structure have done their bit
763 * for the current expedited grace period. Works only for preemptible
764 * RCU -- other RCU implementation use other means.
765 *
766 * Caller must hold sync_rcu_preempt_exp_mutex.
767 */
768static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
769{
770 return !rcu_preempted_readers_exp(rnp) &&
771 ACCESS_ONCE(rnp->expmask) == 0;
772}
773
774/*
775 * Report the exit from RCU read-side critical section for the last task
776 * that queued itself during or before the current expedited preemptible-RCU
777 * grace period. This event is reported either to the rcu_node structure on
778 * which the task was queued or to one of that rcu_node structure's ancestors,
779 * recursively up the tree. (Calm down, calm down, we do the recursion
780 * iteratively!)
781 *
b40d293e
TG
782 * Most callers will set the "wake" flag, but the task initiating the
783 * expedited grace period need not wake itself.
784 *
d9a3da06
PM
785 * Caller must hold sync_rcu_preempt_exp_mutex.
786 */
b40d293e
TG
787static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
788 bool wake)
d9a3da06
PM
789{
790 unsigned long flags;
791 unsigned long mask;
792
1304afb2 793 raw_spin_lock_irqsave(&rnp->lock, flags);
d9a3da06 794 for (;;) {
131906b0
PM
795 if (!sync_rcu_preempt_exp_done(rnp)) {
796 raw_spin_unlock_irqrestore(&rnp->lock, flags);
d9a3da06 797 break;
131906b0 798 }
d9a3da06 799 if (rnp->parent == NULL) {
131906b0 800 raw_spin_unlock_irqrestore(&rnp->lock, flags);
b40d293e
TG
801 if (wake)
802 wake_up(&sync_rcu_preempt_exp_wq);
d9a3da06
PM
803 break;
804 }
805 mask = rnp->grpmask;
1304afb2 806 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
d9a3da06 807 rnp = rnp->parent;
1304afb2 808 raw_spin_lock(&rnp->lock); /* irqs already disabled */
d9a3da06
PM
809 rnp->expmask &= ~mask;
810 }
d9a3da06
PM
811}
812
813/*
814 * Snapshot the tasks blocking the newly started preemptible-RCU expedited
815 * grace period for the specified rcu_node structure. If there are no such
816 * tasks, report it up the rcu_node hierarchy.
817 *
818 * Caller must hold sync_rcu_preempt_exp_mutex and rsp->onofflock.
819 */
820static void
821sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp)
822{
1217ed1b 823 unsigned long flags;
12f5f524 824 int must_wait = 0;
d9a3da06 825
1217ed1b
PM
826 raw_spin_lock_irqsave(&rnp->lock, flags);
827 if (list_empty(&rnp->blkd_tasks))
828 raw_spin_unlock_irqrestore(&rnp->lock, flags);
829 else {
12f5f524 830 rnp->exp_tasks = rnp->blkd_tasks.next;
1217ed1b 831 rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
12f5f524
PM
832 must_wait = 1;
833 }
d9a3da06 834 if (!must_wait)
b40d293e 835 rcu_report_exp_rnp(rsp, rnp, false); /* Don't wake self. */
d9a3da06
PM
836}
837
019129d5 838/*
d9a3da06
PM
839 * Wait for an rcu-preempt grace period, but expedite it. The basic idea
840 * is to invoke synchronize_sched_expedited() to push all the tasks to
12f5f524 841 * the ->blkd_tasks lists and wait for this list to drain.
019129d5
PM
842 */
843void synchronize_rcu_expedited(void)
844{
d9a3da06
PM
845 unsigned long flags;
846 struct rcu_node *rnp;
847 struct rcu_state *rsp = &rcu_preempt_state;
848 long snap;
849 int trycount = 0;
850
851 smp_mb(); /* Caller's modifications seen first by other CPUs. */
852 snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1;
853 smp_mb(); /* Above access cannot bleed into critical section. */
854
855 /*
856 * Acquire lock, falling back to synchronize_rcu() if too many
857 * lock-acquisition failures. Of course, if someone does the
858 * expedited grace period for us, just leave.
859 */
860 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
861 if (trycount++ < 10)
862 udelay(trycount * num_online_cpus());
863 else {
864 synchronize_rcu();
865 return;
866 }
867 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
868 goto mb_ret; /* Others did our work for us. */
869 }
870 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
871 goto unlock_mb_ret; /* Others did our work for us. */
872
12f5f524 873 /* force all RCU readers onto ->blkd_tasks lists. */
d9a3da06
PM
874 synchronize_sched_expedited();
875
1304afb2 876 raw_spin_lock_irqsave(&rsp->onofflock, flags);
d9a3da06
PM
877
878 /* Initialize ->expmask for all non-leaf rcu_node structures. */
879 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
1304afb2 880 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
d9a3da06 881 rnp->expmask = rnp->qsmaskinit;
1304afb2 882 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
d9a3da06
PM
883 }
884
12f5f524 885 /* Snapshot current state of ->blkd_tasks lists. */
d9a3da06
PM
886 rcu_for_each_leaf_node(rsp, rnp)
887 sync_rcu_preempt_exp_init(rsp, rnp);
888 if (NUM_RCU_NODES > 1)
889 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
890
1304afb2 891 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
d9a3da06 892
12f5f524 893 /* Wait for snapshotted ->blkd_tasks lists to drain. */
d9a3da06
PM
894 rnp = rcu_get_root(rsp);
895 wait_event(sync_rcu_preempt_exp_wq,
896 sync_rcu_preempt_exp_done(rnp));
897
898 /* Clean up and exit. */
899 smp_mb(); /* ensure expedited GP seen before counter increment. */
900 ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
901unlock_mb_ret:
902 mutex_unlock(&sync_rcu_preempt_exp_mutex);
903mb_ret:
904 smp_mb(); /* ensure subsequent action seen after grace period. */
019129d5
PM
905}
906EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
907
f41d911f 908/*
6cc68793 909 * Check to see if there is any immediate preemptible-RCU-related work
f41d911f
PM
910 * to be done.
911 */
912static int rcu_preempt_pending(int cpu)
913{
914 return __rcu_pending(&rcu_preempt_state,
915 &per_cpu(rcu_preempt_data, cpu));
916}
917
918/*
30fbcc90 919 * Does preemptible RCU have callbacks on this CPU?
f41d911f 920 */
30fbcc90 921static int rcu_preempt_cpu_has_callbacks(int cpu)
f41d911f
PM
922{
923 return !!per_cpu(rcu_preempt_data, cpu).nxtlist;
924}
925
e74f4c45
PM
926/**
927 * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
928 */
929void rcu_barrier(void)
930{
931 _rcu_barrier(&rcu_preempt_state, call_rcu);
932}
933EXPORT_SYMBOL_GPL(rcu_barrier);
934
f41d911f 935/*
6cc68793 936 * Initialize preemptible RCU's per-CPU data.
f41d911f
PM
937 */
938static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
939{
940 rcu_init_percpu_data(cpu, &rcu_preempt_state, 1);
941}
942
e74f4c45 943/*
e5601400
PM
944 * Move preemptible RCU's callbacks from dying CPU to other online CPU
945 * and record a quiescent state.
e74f4c45 946 */
e5601400 947static void rcu_preempt_cleanup_dying_cpu(void)
e74f4c45 948{
e5601400 949 rcu_cleanup_dying_cpu(&rcu_preempt_state);
e74f4c45
PM
950}
951
1eba8f84 952/*
6cc68793 953 * Initialize preemptible RCU's state structures.
1eba8f84
PM
954 */
955static void __init __rcu_init_preempt(void)
956{
394f99a9 957 rcu_init_one(&rcu_preempt_state, &rcu_preempt_data);
1eba8f84
PM
958}
959
f41d911f 960/*
6cc68793 961 * Check for a task exiting while in a preemptible-RCU read-side
f41d911f
PM
962 * critical section, clean up if so. No need to issue warnings,
963 * as debug_check_no_locks_held() already does this if lockdep
964 * is enabled.
965 */
966void exit_rcu(void)
967{
968 struct task_struct *t = current;
969
970 if (t->rcu_read_lock_nesting == 0)
971 return;
972 t->rcu_read_lock_nesting = 1;
13491a0e 973 __rcu_read_unlock();
f41d911f
PM
974}
975
976#else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
977
27f4d280
PM
978static struct rcu_state *rcu_state = &rcu_sched_state;
979
f41d911f
PM
980/*
981 * Tell them what RCU they are running.
982 */
0e0fc1c2 983static void __init rcu_bootup_announce(void)
f41d911f
PM
984{
985 printk(KERN_INFO "Hierarchical RCU implementation.\n");
26845c28 986 rcu_bootup_announce_oddness();
f41d911f
PM
987}
988
989/*
990 * Return the number of RCU batches processed thus far for debug & stats.
991 */
992long rcu_batches_completed(void)
993{
994 return rcu_batches_completed_sched();
995}
996EXPORT_SYMBOL_GPL(rcu_batches_completed);
997
bf66f18e
PM
998/*
999 * Force a quiescent state for RCU, which, because there is no preemptible
1000 * RCU, becomes the same as rcu-sched.
1001 */
1002void rcu_force_quiescent_state(void)
1003{
1004 rcu_sched_force_quiescent_state();
1005}
1006EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
1007
f41d911f 1008/*
6cc68793 1009 * Because preemptible RCU does not exist, we never have to check for
f41d911f
PM
1010 * CPUs being in quiescent states.
1011 */
c3422bea 1012static void rcu_preempt_note_context_switch(int cpu)
f41d911f
PM
1013{
1014}
1015
fc2219d4 1016/*
6cc68793 1017 * Because preemptible RCU does not exist, there are never any preempted
fc2219d4
PM
1018 * RCU readers.
1019 */
27f4d280 1020static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
fc2219d4
PM
1021{
1022 return 0;
1023}
1024
b668c9cf
PM
1025#ifdef CONFIG_HOTPLUG_CPU
1026
1027/* Because preemptible RCU does not exist, no quieting of tasks. */
d3f6bad3 1028static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
b668c9cf 1029{
1304afb2 1030 raw_spin_unlock_irqrestore(&rnp->lock, flags);
b668c9cf
PM
1031}
1032
1033#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1034
1ed509a2 1035/*
6cc68793 1036 * Because preemptible RCU does not exist, we never have to check for
1ed509a2
PM
1037 * tasks blocked within RCU read-side critical sections.
1038 */
1039static void rcu_print_detail_task_stall(struct rcu_state *rsp)
1040{
1041}
1042
f41d911f 1043/*
6cc68793 1044 * Because preemptible RCU does not exist, we never have to check for
f41d911f
PM
1045 * tasks blocked within RCU read-side critical sections.
1046 */
9bc8b558 1047static int rcu_print_task_stall(struct rcu_node *rnp)
f41d911f 1048{
9bc8b558 1049 return 0;
f41d911f
PM
1050}
1051
53d84e00
PM
1052/*
1053 * Because preemptible RCU does not exist, there is no need to suppress
1054 * its CPU stall warnings.
1055 */
1056static void rcu_preempt_stall_reset(void)
1057{
1058}
1059
b0e165c0 1060/*
6cc68793 1061 * Because there is no preemptible RCU, there can be no readers blocked,
49e29126
PM
1062 * so there is no need to check for blocked tasks. So check only for
1063 * bogus qsmask values.
b0e165c0
PM
1064 */
1065static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
1066{
49e29126 1067 WARN_ON_ONCE(rnp->qsmask);
b0e165c0
PM
1068}
1069
33f76148
PM
1070#ifdef CONFIG_HOTPLUG_CPU
1071
dd5d19ba 1072/*
6cc68793 1073 * Because preemptible RCU does not exist, it never needs to migrate
237c80c5
PM
1074 * tasks that were blocked within RCU read-side critical sections, and
1075 * such non-existent tasks cannot possibly have been blocking the current
1076 * grace period.
dd5d19ba 1077 */
237c80c5
PM
1078static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
1079 struct rcu_node *rnp,
1080 struct rcu_data *rdp)
dd5d19ba 1081{
237c80c5 1082 return 0;
dd5d19ba
PM
1083}
1084
e5601400
PM
1085#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1086
33f76148 1087/*
6cc68793 1088 * Because preemptible RCU does not exist, it never needs CPU-offline
33f76148
PM
1089 * processing.
1090 */
e5601400 1091static void rcu_preempt_cleanup_dead_cpu(int cpu)
33f76148
PM
1092{
1093}
1094
f41d911f 1095/*
6cc68793 1096 * Because preemptible RCU does not exist, it never has any callbacks
f41d911f
PM
1097 * to check.
1098 */
1eba8f84 1099static void rcu_preempt_check_callbacks(int cpu)
f41d911f
PM
1100{
1101}
1102
1103/*
6cc68793 1104 * Because preemptible RCU does not exist, it never has any callbacks
f41d911f
PM
1105 * to process.
1106 */
1eba8f84 1107static void rcu_preempt_process_callbacks(void)
f41d911f
PM
1108{
1109}
1110
486e2593
PM
1111/*
1112 * Queue an RCU callback for lazy invocation after a grace period.
1113 * This will likely be later named something like "call_rcu_lazy()",
1114 * but this change will require some way of tagging the lazy RCU
1115 * callbacks in the list of pending callbacks. Until then, this
1116 * function may only be called from __kfree_rcu().
1117 *
1118 * Because there is no preemptible RCU, we use RCU-sched instead.
1119 */
1120void kfree_call_rcu(struct rcu_head *head,
1121 void (*func)(struct rcu_head *rcu))
1122{
1123 __call_rcu(head, func, &rcu_sched_state, 1);
1124}
1125EXPORT_SYMBOL_GPL(kfree_call_rcu);
1126
019129d5
PM
1127/*
1128 * Wait for an rcu-preempt grace period, but make it happen quickly.
6cc68793 1129 * But because preemptible RCU does not exist, map to rcu-sched.
019129d5
PM
1130 */
1131void synchronize_rcu_expedited(void)
1132{
1133 synchronize_sched_expedited();
1134}
1135EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
1136
d9a3da06
PM
1137#ifdef CONFIG_HOTPLUG_CPU
1138
1139/*
6cc68793 1140 * Because preemptible RCU does not exist, there is never any need to
d9a3da06
PM
1141 * report on tasks preempted in RCU read-side critical sections during
1142 * expedited RCU grace periods.
1143 */
b40d293e
TG
1144static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
1145 bool wake)
d9a3da06 1146{
d9a3da06
PM
1147}
1148
1149#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1150
f41d911f 1151/*
6cc68793 1152 * Because preemptible RCU does not exist, it never has any work to do.
f41d911f
PM
1153 */
1154static int rcu_preempt_pending(int cpu)
1155{
1156 return 0;
1157}
1158
1159/*
30fbcc90 1160 * Because preemptible RCU does not exist, it never has callbacks
f41d911f 1161 */
30fbcc90 1162static int rcu_preempt_cpu_has_callbacks(int cpu)
f41d911f
PM
1163{
1164 return 0;
1165}
1166
e74f4c45 1167/*
6cc68793 1168 * Because preemptible RCU does not exist, rcu_barrier() is just
e74f4c45
PM
1169 * another name for rcu_barrier_sched().
1170 */
1171void rcu_barrier(void)
1172{
1173 rcu_barrier_sched();
1174}
1175EXPORT_SYMBOL_GPL(rcu_barrier);
1176
f41d911f 1177/*
6cc68793 1178 * Because preemptible RCU does not exist, there is no per-CPU
f41d911f
PM
1179 * data to initialize.
1180 */
1181static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
1182{
1183}
1184
e74f4c45 1185/*
e5601400 1186 * Because there is no preemptible RCU, there is no cleanup to do.
e74f4c45 1187 */
e5601400 1188static void rcu_preempt_cleanup_dying_cpu(void)
e74f4c45
PM
1189{
1190}
1191
1eba8f84 1192/*
6cc68793 1193 * Because preemptible RCU does not exist, it need not be initialized.
1eba8f84
PM
1194 */
1195static void __init __rcu_init_preempt(void)
1196{
1197}
1198
f41d911f 1199#endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */
8bd93a2c 1200
27f4d280
PM
1201#ifdef CONFIG_RCU_BOOST
1202
1203#include "rtmutex_common.h"
1204
0ea1f2eb
PM
1205#ifdef CONFIG_RCU_TRACE
1206
1207static void rcu_initiate_boost_trace(struct rcu_node *rnp)
1208{
1209 if (list_empty(&rnp->blkd_tasks))
1210 rnp->n_balk_blkd_tasks++;
1211 else if (rnp->exp_tasks == NULL && rnp->gp_tasks == NULL)
1212 rnp->n_balk_exp_gp_tasks++;
1213 else if (rnp->gp_tasks != NULL && rnp->boost_tasks != NULL)
1214 rnp->n_balk_boost_tasks++;
1215 else if (rnp->gp_tasks != NULL && rnp->qsmask != 0)
1216 rnp->n_balk_notblocked++;
1217 else if (rnp->gp_tasks != NULL &&
a9f4793d 1218 ULONG_CMP_LT(jiffies, rnp->boost_time))
0ea1f2eb
PM
1219 rnp->n_balk_notyet++;
1220 else
1221 rnp->n_balk_nos++;
1222}
1223
1224#else /* #ifdef CONFIG_RCU_TRACE */
1225
1226static void rcu_initiate_boost_trace(struct rcu_node *rnp)
1227{
1228}
1229
1230#endif /* #else #ifdef CONFIG_RCU_TRACE */
1231
27f4d280
PM
1232/*
1233 * Carry out RCU priority boosting on the task indicated by ->exp_tasks
1234 * or ->boost_tasks, advancing the pointer to the next task in the
1235 * ->blkd_tasks list.
1236 *
1237 * Note that irqs must be enabled: boosting the task can block.
1238 * Returns 1 if there are more tasks needing to be boosted.
1239 */
1240static int rcu_boost(struct rcu_node *rnp)
1241{
1242 unsigned long flags;
1243 struct rt_mutex mtx;
1244 struct task_struct *t;
1245 struct list_head *tb;
1246
1247 if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL)
1248 return 0; /* Nothing left to boost. */
1249
1250 raw_spin_lock_irqsave(&rnp->lock, flags);
1251
1252 /*
1253 * Recheck under the lock: all tasks in need of boosting
1254 * might exit their RCU read-side critical sections on their own.
1255 */
1256 if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL) {
1257 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1258 return 0;
1259 }
1260
1261 /*
1262 * Preferentially boost tasks blocking expedited grace periods.
1263 * This cannot starve the normal grace periods because a second
1264 * expedited grace period must boost all blocked tasks, including
1265 * those blocking the pre-existing normal grace period.
1266 */
0ea1f2eb 1267 if (rnp->exp_tasks != NULL) {
27f4d280 1268 tb = rnp->exp_tasks;
0ea1f2eb
PM
1269 rnp->n_exp_boosts++;
1270 } else {
27f4d280 1271 tb = rnp->boost_tasks;
0ea1f2eb
PM
1272 rnp->n_normal_boosts++;
1273 }
1274 rnp->n_tasks_boosted++;
27f4d280
PM
1275
1276 /*
1277 * We boost task t by manufacturing an rt_mutex that appears to
1278 * be held by task t. We leave a pointer to that rt_mutex where
1279 * task t can find it, and task t will release the mutex when it
1280 * exits its outermost RCU read-side critical section. Then
1281 * simply acquiring this artificial rt_mutex will boost task
1282 * t's priority. (Thanks to tglx for suggesting this approach!)
1283 *
1284 * Note that task t must acquire rnp->lock to remove itself from
1285 * the ->blkd_tasks list, which it will do from exit() if from
1286 * nowhere else. We therefore are guaranteed that task t will
1287 * stay around at least until we drop rnp->lock. Note that
1288 * rnp->lock also resolves races between our priority boosting
1289 * and task t's exiting its outermost RCU read-side critical
1290 * section.
1291 */
1292 t = container_of(tb, struct task_struct, rcu_node_entry);
1293 rt_mutex_init_proxy_locked(&mtx, t);
1294 t->rcu_boost_mutex = &mtx;
27f4d280
PM
1295 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1296 rt_mutex_lock(&mtx); /* Side effect: boosts task t's priority. */
1297 rt_mutex_unlock(&mtx); /* Keep lockdep happy. */
1298
4f89b336
PM
1299 return ACCESS_ONCE(rnp->exp_tasks) != NULL ||
1300 ACCESS_ONCE(rnp->boost_tasks) != NULL;
27f4d280
PM
1301}
1302
1303/*
1304 * Timer handler to initiate waking up of boost kthreads that
1305 * have yielded the CPU due to excessive numbers of tasks to
1306 * boost. We wake up the per-rcu_node kthread, which in turn
1307 * will wake up the booster kthread.
1308 */
1309static void rcu_boost_kthread_timer(unsigned long arg)
1310{
1217ed1b 1311 invoke_rcu_node_kthread((struct rcu_node *)arg);
27f4d280
PM
1312}
1313
1314/*
1315 * Priority-boosting kthread. One per leaf rcu_node and one for the
1316 * root rcu_node.
1317 */
1318static int rcu_boost_kthread(void *arg)
1319{
1320 struct rcu_node *rnp = (struct rcu_node *)arg;
1321 int spincnt = 0;
1322 int more2boost;
1323
385680a9 1324 trace_rcu_utilization("Start boost kthread@init");
27f4d280 1325 for (;;) {
d71df90e 1326 rnp->boost_kthread_status = RCU_KTHREAD_WAITING;
385680a9 1327 trace_rcu_utilization("End boost kthread@rcu_wait");
08bca60a 1328 rcu_wait(rnp->boost_tasks || rnp->exp_tasks);
385680a9 1329 trace_rcu_utilization("Start boost kthread@rcu_wait");
d71df90e 1330 rnp->boost_kthread_status = RCU_KTHREAD_RUNNING;
27f4d280
PM
1331 more2boost = rcu_boost(rnp);
1332 if (more2boost)
1333 spincnt++;
1334 else
1335 spincnt = 0;
1336 if (spincnt > 10) {
385680a9 1337 trace_rcu_utilization("End boost kthread@rcu_yield");
27f4d280 1338 rcu_yield(rcu_boost_kthread_timer, (unsigned long)rnp);
385680a9 1339 trace_rcu_utilization("Start boost kthread@rcu_yield");
27f4d280
PM
1340 spincnt = 0;
1341 }
1342 }
1217ed1b 1343 /* NOTREACHED */
385680a9 1344 trace_rcu_utilization("End boost kthread@notreached");
27f4d280
PM
1345 return 0;
1346}
1347
1348/*
1349 * Check to see if it is time to start boosting RCU readers that are
1350 * blocking the current grace period, and, if so, tell the per-rcu_node
1351 * kthread to start boosting them. If there is an expedited grace
1352 * period in progress, it is always time to boost.
1353 *
1217ed1b
PM
1354 * The caller must hold rnp->lock, which this function releases,
1355 * but irqs remain disabled. The ->boost_kthread_task is immortal,
1356 * so we don't need to worry about it going away.
27f4d280 1357 */
1217ed1b 1358static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
27f4d280
PM
1359{
1360 struct task_struct *t;
1361
0ea1f2eb
PM
1362 if (!rcu_preempt_blocked_readers_cgp(rnp) && rnp->exp_tasks == NULL) {
1363 rnp->n_balk_exp_gp_tasks++;
1217ed1b 1364 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280 1365 return;
0ea1f2eb 1366 }
27f4d280
PM
1367 if (rnp->exp_tasks != NULL ||
1368 (rnp->gp_tasks != NULL &&
1369 rnp->boost_tasks == NULL &&
1370 rnp->qsmask == 0 &&
1371 ULONG_CMP_GE(jiffies, rnp->boost_time))) {
1372 if (rnp->exp_tasks == NULL)
1373 rnp->boost_tasks = rnp->gp_tasks;
1217ed1b 1374 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280
PM
1375 t = rnp->boost_kthread_task;
1376 if (t != NULL)
1377 wake_up_process(t);
1217ed1b 1378 } else {
0ea1f2eb 1379 rcu_initiate_boost_trace(rnp);
1217ed1b
PM
1380 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1381 }
27f4d280
PM
1382}
1383
a46e0899
PM
1384/*
1385 * Wake up the per-CPU kthread to invoke RCU callbacks.
1386 */
1387static void invoke_rcu_callbacks_kthread(void)
1388{
1389 unsigned long flags;
1390
1391 local_irq_save(flags);
1392 __this_cpu_write(rcu_cpu_has_work, 1);
1eb52121
SL
1393 if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
1394 current != __this_cpu_read(rcu_cpu_kthread_task))
1395 wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
a46e0899
PM
1396 local_irq_restore(flags);
1397}
1398
dff1672d
PM
1399/*
1400 * Is the current CPU running the RCU-callbacks kthread?
1401 * Caller must have preemption disabled.
1402 */
1403static bool rcu_is_callbacks_kthread(void)
1404{
1405 return __get_cpu_var(rcu_cpu_kthread_task) == current;
1406}
1407
0f962a5e
PM
1408/*
1409 * Set the affinity of the boost kthread. The CPU-hotplug locks are
1410 * held, so no one should be messing with the existence of the boost
1411 * kthread.
1412 */
27f4d280
PM
1413static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp,
1414 cpumask_var_t cm)
1415{
27f4d280
PM
1416 struct task_struct *t;
1417
27f4d280
PM
1418 t = rnp->boost_kthread_task;
1419 if (t != NULL)
1420 set_cpus_allowed_ptr(rnp->boost_kthread_task, cm);
27f4d280
PM
1421}
1422
1423#define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000)
1424
1425/*
1426 * Do priority-boost accounting for the start of a new grace period.
1427 */
1428static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1429{
1430 rnp->boost_time = jiffies + RCU_BOOST_DELAY_JIFFIES;
1431}
1432
27f4d280
PM
1433/*
1434 * Create an RCU-boost kthread for the specified node if one does not
1435 * already exist. We only create this kthread for preemptible RCU.
1436 * Returns zero if all is well, a negated errno otherwise.
1437 */
1438static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
1439 struct rcu_node *rnp,
1440 int rnp_index)
1441{
1442 unsigned long flags;
1443 struct sched_param sp;
1444 struct task_struct *t;
1445
1446 if (&rcu_preempt_state != rsp)
1447 return 0;
a46e0899 1448 rsp->boost = 1;
27f4d280
PM
1449 if (rnp->boost_kthread_task != NULL)
1450 return 0;
1451 t = kthread_create(rcu_boost_kthread, (void *)rnp,
5b61b0ba 1452 "rcub/%d", rnp_index);
27f4d280
PM
1453 if (IS_ERR(t))
1454 return PTR_ERR(t);
1455 raw_spin_lock_irqsave(&rnp->lock, flags);
1456 rnp->boost_kthread_task = t;
1457 raw_spin_unlock_irqrestore(&rnp->lock, flags);
5b61b0ba 1458 sp.sched_priority = RCU_BOOST_PRIO;
27f4d280 1459 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
9a432736 1460 wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
27f4d280
PM
1461 return 0;
1462}
1463
f8b7fc6b
PM
1464#ifdef CONFIG_HOTPLUG_CPU
1465
1466/*
1467 * Stop the RCU's per-CPU kthread when its CPU goes offline,.
1468 */
1469static void rcu_stop_cpu_kthread(int cpu)
1470{
1471 struct task_struct *t;
1472
1473 /* Stop the CPU's kthread. */
1474 t = per_cpu(rcu_cpu_kthread_task, cpu);
1475 if (t != NULL) {
1476 per_cpu(rcu_cpu_kthread_task, cpu) = NULL;
1477 kthread_stop(t);
1478 }
1479}
1480
1481#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1482
1483static void rcu_kthread_do_work(void)
1484{
1485 rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data));
1486 rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
1487 rcu_preempt_do_callbacks();
1488}
1489
1490/*
1491 * Wake up the specified per-rcu_node-structure kthread.
1492 * Because the per-rcu_node kthreads are immortal, we don't need
1493 * to do anything to keep them alive.
1494 */
1495static void invoke_rcu_node_kthread(struct rcu_node *rnp)
1496{
1497 struct task_struct *t;
1498
1499 t = rnp->node_kthread_task;
1500 if (t != NULL)
1501 wake_up_process(t);
1502}
1503
1504/*
1505 * Set the specified CPU's kthread to run RT or not, as specified by
1506 * the to_rt argument. The CPU-hotplug locks are held, so the task
1507 * is not going away.
1508 */
1509static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
1510{
1511 int policy;
1512 struct sched_param sp;
1513 struct task_struct *t;
1514
1515 t = per_cpu(rcu_cpu_kthread_task, cpu);
1516 if (t == NULL)
1517 return;
1518 if (to_rt) {
1519 policy = SCHED_FIFO;
1520 sp.sched_priority = RCU_KTHREAD_PRIO;
1521 } else {
1522 policy = SCHED_NORMAL;
1523 sp.sched_priority = 0;
1524 }
1525 sched_setscheduler_nocheck(t, policy, &sp);
1526}
1527
1528/*
1529 * Timer handler to initiate the waking up of per-CPU kthreads that
1530 * have yielded the CPU due to excess numbers of RCU callbacks.
1531 * We wake up the per-rcu_node kthread, which in turn will wake up
1532 * the booster kthread.
1533 */
1534static void rcu_cpu_kthread_timer(unsigned long arg)
1535{
1536 struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, arg);
1537 struct rcu_node *rnp = rdp->mynode;
1538
1539 atomic_or(rdp->grpmask, &rnp->wakemask);
1540 invoke_rcu_node_kthread(rnp);
1541}
1542
1543/*
1544 * Drop to non-real-time priority and yield, but only after posting a
1545 * timer that will cause us to regain our real-time priority if we
1546 * remain preempted. Either way, we restore our real-time priority
1547 * before returning.
1548 */
1549static void rcu_yield(void (*f)(unsigned long), unsigned long arg)
1550{
1551 struct sched_param sp;
1552 struct timer_list yield_timer;
5b61b0ba 1553 int prio = current->rt_priority;
f8b7fc6b
PM
1554
1555 setup_timer_on_stack(&yield_timer, f, arg);
1556 mod_timer(&yield_timer, jiffies + 2);
1557 sp.sched_priority = 0;
1558 sched_setscheduler_nocheck(current, SCHED_NORMAL, &sp);
1559 set_user_nice(current, 19);
1560 schedule();
5b61b0ba
MG
1561 set_user_nice(current, 0);
1562 sp.sched_priority = prio;
f8b7fc6b
PM
1563 sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
1564 del_timer(&yield_timer);
1565}
1566
1567/*
1568 * Handle cases where the rcu_cpu_kthread() ends up on the wrong CPU.
1569 * This can happen while the corresponding CPU is either coming online
1570 * or going offline. We cannot wait until the CPU is fully online
1571 * before starting the kthread, because the various notifier functions
1572 * can wait for RCU grace periods. So we park rcu_cpu_kthread() until
1573 * the corresponding CPU is online.
1574 *
1575 * Return 1 if the kthread needs to stop, 0 otherwise.
1576 *
1577 * Caller must disable bh. This function can momentarily enable it.
1578 */
1579static int rcu_cpu_kthread_should_stop(int cpu)
1580{
1581 while (cpu_is_offline(cpu) ||
1582 !cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)) ||
1583 smp_processor_id() != cpu) {
1584 if (kthread_should_stop())
1585 return 1;
1586 per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
1587 per_cpu(rcu_cpu_kthread_cpu, cpu) = raw_smp_processor_id();
1588 local_bh_enable();
1589 schedule_timeout_uninterruptible(1);
1590 if (!cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)))
1591 set_cpus_allowed_ptr(current, cpumask_of(cpu));
1592 local_bh_disable();
1593 }
1594 per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
1595 return 0;
1596}
1597
1598/*
1599 * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
e0f23060
PM
1600 * RCU softirq used in flavors and configurations of RCU that do not
1601 * support RCU priority boosting.
f8b7fc6b
PM
1602 */
1603static int rcu_cpu_kthread(void *arg)
1604{
1605 int cpu = (int)(long)arg;
1606 unsigned long flags;
1607 int spincnt = 0;
1608 unsigned int *statusp = &per_cpu(rcu_cpu_kthread_status, cpu);
1609 char work;
1610 char *workp = &per_cpu(rcu_cpu_has_work, cpu);
1611
385680a9 1612 trace_rcu_utilization("Start CPU kthread@init");
f8b7fc6b
PM
1613 for (;;) {
1614 *statusp = RCU_KTHREAD_WAITING;
385680a9 1615 trace_rcu_utilization("End CPU kthread@rcu_wait");
f8b7fc6b 1616 rcu_wait(*workp != 0 || kthread_should_stop());
385680a9 1617 trace_rcu_utilization("Start CPU kthread@rcu_wait");
f8b7fc6b
PM
1618 local_bh_disable();
1619 if (rcu_cpu_kthread_should_stop(cpu)) {
1620 local_bh_enable();
1621 break;
1622 }
1623 *statusp = RCU_KTHREAD_RUNNING;
1624 per_cpu(rcu_cpu_kthread_loops, cpu)++;
1625 local_irq_save(flags);
1626 work = *workp;
1627 *workp = 0;
1628 local_irq_restore(flags);
1629 if (work)
1630 rcu_kthread_do_work();
1631 local_bh_enable();
1632 if (*workp != 0)
1633 spincnt++;
1634 else
1635 spincnt = 0;
1636 if (spincnt > 10) {
1637 *statusp = RCU_KTHREAD_YIELDING;
385680a9 1638 trace_rcu_utilization("End CPU kthread@rcu_yield");
f8b7fc6b 1639 rcu_yield(rcu_cpu_kthread_timer, (unsigned long)cpu);
385680a9 1640 trace_rcu_utilization("Start CPU kthread@rcu_yield");
f8b7fc6b
PM
1641 spincnt = 0;
1642 }
1643 }
1644 *statusp = RCU_KTHREAD_STOPPED;
385680a9 1645 trace_rcu_utilization("End CPU kthread@term");
f8b7fc6b
PM
1646 return 0;
1647}
1648
1649/*
1650 * Spawn a per-CPU kthread, setting up affinity and priority.
1651 * Because the CPU hotplug lock is held, no other CPU will be attempting
1652 * to manipulate rcu_cpu_kthread_task. There might be another CPU
1653 * attempting to access it during boot, but the locking in kthread_bind()
1654 * will enforce sufficient ordering.
1655 *
1656 * Please note that we cannot simply refuse to wake up the per-CPU
1657 * kthread because kthreads are created in TASK_UNINTERRUPTIBLE state,
1658 * which can result in softlockup complaints if the task ends up being
1659 * idle for more than a couple of minutes.
1660 *
1661 * However, please note also that we cannot bind the per-CPU kthread to its
1662 * CPU until that CPU is fully online. We also cannot wait until the
1663 * CPU is fully online before we create its per-CPU kthread, as this would
1664 * deadlock the system when CPU notifiers tried waiting for grace
1665 * periods. So we bind the per-CPU kthread to its CPU only if the CPU
1666 * is online. If its CPU is not yet fully online, then the code in
1667 * rcu_cpu_kthread() will wait until it is fully online, and then do
1668 * the binding.
1669 */
1670static int __cpuinit rcu_spawn_one_cpu_kthread(int cpu)
1671{
1672 struct sched_param sp;
1673 struct task_struct *t;
1674
b0d30417 1675 if (!rcu_scheduler_fully_active ||
f8b7fc6b
PM
1676 per_cpu(rcu_cpu_kthread_task, cpu) != NULL)
1677 return 0;
1f288094
ED
1678 t = kthread_create_on_node(rcu_cpu_kthread,
1679 (void *)(long)cpu,
1680 cpu_to_node(cpu),
5b61b0ba 1681 "rcuc/%d", cpu);
f8b7fc6b
PM
1682 if (IS_ERR(t))
1683 return PTR_ERR(t);
1684 if (cpu_online(cpu))
1685 kthread_bind(t, cpu);
1686 per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
1687 WARN_ON_ONCE(per_cpu(rcu_cpu_kthread_task, cpu) != NULL);
1688 sp.sched_priority = RCU_KTHREAD_PRIO;
1689 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1690 per_cpu(rcu_cpu_kthread_task, cpu) = t;
1691 wake_up_process(t); /* Get to TASK_INTERRUPTIBLE quickly. */
1692 return 0;
1693}
1694
1695/*
1696 * Per-rcu_node kthread, which is in charge of waking up the per-CPU
1697 * kthreads when needed. We ignore requests to wake up kthreads
1698 * for offline CPUs, which is OK because force_quiescent_state()
1699 * takes care of this case.
1700 */
1701static int rcu_node_kthread(void *arg)
1702{
1703 int cpu;
1704 unsigned long flags;
1705 unsigned long mask;
1706 struct rcu_node *rnp = (struct rcu_node *)arg;
1707 struct sched_param sp;
1708 struct task_struct *t;
1709
1710 for (;;) {
1711 rnp->node_kthread_status = RCU_KTHREAD_WAITING;
1712 rcu_wait(atomic_read(&rnp->wakemask) != 0);
1713 rnp->node_kthread_status = RCU_KTHREAD_RUNNING;
1714 raw_spin_lock_irqsave(&rnp->lock, flags);
1715 mask = atomic_xchg(&rnp->wakemask, 0);
1716 rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */
1717 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) {
1718 if ((mask & 0x1) == 0)
1719 continue;
1720 preempt_disable();
1721 t = per_cpu(rcu_cpu_kthread_task, cpu);
1722 if (!cpu_online(cpu) || t == NULL) {
1723 preempt_enable();
1724 continue;
1725 }
1726 per_cpu(rcu_cpu_has_work, cpu) = 1;
1727 sp.sched_priority = RCU_KTHREAD_PRIO;
1728 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1729 preempt_enable();
1730 }
1731 }
1732 /* NOTREACHED */
1733 rnp->node_kthread_status = RCU_KTHREAD_STOPPED;
1734 return 0;
1735}
1736
1737/*
1738 * Set the per-rcu_node kthread's affinity to cover all CPUs that are
1739 * served by the rcu_node in question. The CPU hotplug lock is still
1740 * held, so the value of rnp->qsmaskinit will be stable.
1741 *
1742 * We don't include outgoingcpu in the affinity set, use -1 if there is
1743 * no outgoing CPU. If there are no CPUs left in the affinity set,
1744 * this function allows the kthread to execute on any CPU.
1745 */
1746static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1747{
1748 cpumask_var_t cm;
1749 int cpu;
1750 unsigned long mask = rnp->qsmaskinit;
1751
1752 if (rnp->node_kthread_task == NULL)
1753 return;
1754 if (!alloc_cpumask_var(&cm, GFP_KERNEL))
1755 return;
1756 cpumask_clear(cm);
1757 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1)
1758 if ((mask & 0x1) && cpu != outgoingcpu)
1759 cpumask_set_cpu(cpu, cm);
1760 if (cpumask_weight(cm) == 0) {
1761 cpumask_setall(cm);
1762 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++)
1763 cpumask_clear_cpu(cpu, cm);
1764 WARN_ON_ONCE(cpumask_weight(cm) == 0);
1765 }
1766 set_cpus_allowed_ptr(rnp->node_kthread_task, cm);
1767 rcu_boost_kthread_setaffinity(rnp, cm);
1768 free_cpumask_var(cm);
1769}
1770
1771/*
1772 * Spawn a per-rcu_node kthread, setting priority and affinity.
1773 * Called during boot before online/offline can happen, or, if
1774 * during runtime, with the main CPU-hotplug locks held. So only
1775 * one of these can be executing at a time.
1776 */
1777static int __cpuinit rcu_spawn_one_node_kthread(struct rcu_state *rsp,
1778 struct rcu_node *rnp)
1779{
1780 unsigned long flags;
1781 int rnp_index = rnp - &rsp->node[0];
1782 struct sched_param sp;
1783 struct task_struct *t;
1784
b0d30417 1785 if (!rcu_scheduler_fully_active ||
f8b7fc6b
PM
1786 rnp->qsmaskinit == 0)
1787 return 0;
1788 if (rnp->node_kthread_task == NULL) {
1789 t = kthread_create(rcu_node_kthread, (void *)rnp,
5b61b0ba 1790 "rcun/%d", rnp_index);
f8b7fc6b
PM
1791 if (IS_ERR(t))
1792 return PTR_ERR(t);
1793 raw_spin_lock_irqsave(&rnp->lock, flags);
1794 rnp->node_kthread_task = t;
1795 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1796 sp.sched_priority = 99;
1797 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1798 wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
1799 }
1800 return rcu_spawn_one_boost_kthread(rsp, rnp, rnp_index);
1801}
1802
1803/*
1804 * Spawn all kthreads -- called as soon as the scheduler is running.
1805 */
1806static int __init rcu_spawn_kthreads(void)
1807{
1808 int cpu;
1809 struct rcu_node *rnp;
1810
b0d30417 1811 rcu_scheduler_fully_active = 1;
f8b7fc6b
PM
1812 for_each_possible_cpu(cpu) {
1813 per_cpu(rcu_cpu_has_work, cpu) = 0;
1814 if (cpu_online(cpu))
1815 (void)rcu_spawn_one_cpu_kthread(cpu);
1816 }
1817 rnp = rcu_get_root(rcu_state);
1818 (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
1819 if (NUM_RCU_NODES > 1) {
1820 rcu_for_each_leaf_node(rcu_state, rnp)
1821 (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
1822 }
1823 return 0;
1824}
1825early_initcall(rcu_spawn_kthreads);
1826
1827static void __cpuinit rcu_prepare_kthreads(int cpu)
1828{
1829 struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
1830 struct rcu_node *rnp = rdp->mynode;
1831
1832 /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */
b0d30417 1833 if (rcu_scheduler_fully_active) {
f8b7fc6b
PM
1834 (void)rcu_spawn_one_cpu_kthread(cpu);
1835 if (rnp->node_kthread_task == NULL)
1836 (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
1837 }
1838}
1839
27f4d280
PM
1840#else /* #ifdef CONFIG_RCU_BOOST */
1841
1217ed1b 1842static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
27f4d280 1843{
1217ed1b 1844 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280
PM
1845}
1846
a46e0899 1847static void invoke_rcu_callbacks_kthread(void)
27f4d280 1848{
a46e0899 1849 WARN_ON_ONCE(1);
27f4d280
PM
1850}
1851
dff1672d
PM
1852static bool rcu_is_callbacks_kthread(void)
1853{
1854 return false;
1855}
1856
27f4d280
PM
1857static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1858{
1859}
1860
f8b7fc6b
PM
1861#ifdef CONFIG_HOTPLUG_CPU
1862
1863static void rcu_stop_cpu_kthread(int cpu)
1864{
1865}
1866
1867#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1868
1869static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1870{
1871}
1872
1873static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
1874{
1875}
1876
b0d30417
PM
1877static int __init rcu_scheduler_really_started(void)
1878{
1879 rcu_scheduler_fully_active = 1;
1880 return 0;
1881}
1882early_initcall(rcu_scheduler_really_started);
1883
f8b7fc6b
PM
1884static void __cpuinit rcu_prepare_kthreads(int cpu)
1885{
1886}
1887
27f4d280
PM
1888#endif /* #else #ifdef CONFIG_RCU_BOOST */
1889
8bd93a2c
PM
1890#if !defined(CONFIG_RCU_FAST_NO_HZ)
1891
1892/*
1893 * Check to see if any future RCU-related work will need to be done
1894 * by the current CPU, even if none need be done immediately, returning
1895 * 1 if so. This function is part of the RCU implementation; it is -not-
1896 * an exported member of the RCU API.
1897 *
7cb92499
PM
1898 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs
1899 * any flavor of RCU.
8bd93a2c
PM
1900 */
1901int rcu_needs_cpu(int cpu)
1902{
aea1b35e
PM
1903 return rcu_cpu_has_callbacks(cpu);
1904}
1905
7cb92499
PM
1906/*
1907 * Because we do not have RCU_FAST_NO_HZ, don't bother initializing for it.
1908 */
1909static void rcu_prepare_for_idle_init(int cpu)
1910{
1911}
1912
1913/*
1914 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
1915 * after it.
1916 */
1917static void rcu_cleanup_after_idle(int cpu)
1918{
1919}
1920
aea1b35e 1921/*
a858af28 1922 * Do the idle-entry grace-period work, which, because CONFIG_RCU_FAST_NO_HZ=n,
aea1b35e
PM
1923 * is nothing.
1924 */
1925static void rcu_prepare_for_idle(int cpu)
1926{
1927}
1928
8bd93a2c
PM
1929#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
1930
f23f7fa1
PM
1931/*
1932 * This code is invoked when a CPU goes idle, at which point we want
1933 * to have the CPU do everything required for RCU so that it can enter
1934 * the energy-efficient dyntick-idle mode. This is handled by a
1935 * state machine implemented by rcu_prepare_for_idle() below.
1936 *
1937 * The following three proprocessor symbols control this state machine:
1938 *
1939 * RCU_IDLE_FLUSHES gives the maximum number of times that we will attempt
1940 * to satisfy RCU. Beyond this point, it is better to incur a periodic
1941 * scheduling-clock interrupt than to loop through the state machine
1942 * at full power.
1943 * RCU_IDLE_OPT_FLUSHES gives the number of RCU_IDLE_FLUSHES that are
1944 * optional if RCU does not need anything immediately from this
1945 * CPU, even if this CPU still has RCU callbacks queued. The first
1946 * times through the state machine are mandatory: we need to give
1947 * the state machine a chance to communicate a quiescent state
1948 * to the RCU core.
1949 * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted
1950 * to sleep in dyntick-idle mode with RCU callbacks pending. This
1951 * is sized to be roughly one RCU grace period. Those energy-efficiency
1952 * benchmarkers who might otherwise be tempted to set this to a large
1953 * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your
1954 * system. And if you are -that- concerned about energy efficiency,
1955 * just power the system down and be done with it!
778d250a
PM
1956 * RCU_IDLE_LAZY_GP_DELAY gives the number of jiffies that a CPU is
1957 * permitted to sleep in dyntick-idle mode with only lazy RCU
1958 * callbacks pending. Setting this too high can OOM your system.
f23f7fa1
PM
1959 *
1960 * The values below work well in practice. If future workloads require
1961 * adjustment, they can be converted into kernel config parameters, though
1962 * making the state machine smarter might be a better option.
1963 */
1964#define RCU_IDLE_FLUSHES 5 /* Number of dyntick-idle tries. */
1965#define RCU_IDLE_OPT_FLUSHES 3 /* Optional dyntick-idle tries. */
7cb92499 1966#define RCU_IDLE_GP_DELAY 6 /* Roughly one grace period. */
778d250a 1967#define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
f23f7fa1 1968
a47cd880 1969static DEFINE_PER_CPU(int, rcu_dyntick_drain);
71da8132 1970static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
7cb92499 1971static DEFINE_PER_CPU(struct hrtimer, rcu_idle_gp_timer);
778d250a
PM
1972static ktime_t rcu_idle_gp_wait; /* If some non-lazy callbacks. */
1973static ktime_t rcu_idle_lazy_gp_wait; /* If only lazy callbacks. */
8bd93a2c
PM
1974
1975/*
aea1b35e
PM
1976 * Allow the CPU to enter dyntick-idle mode if either: (1) There are no
1977 * callbacks on this CPU, (2) this CPU has not yet attempted to enter
1978 * dyntick-idle mode, or (3) this CPU is in the process of attempting to
1979 * enter dyntick-idle mode. Otherwise, if we have recently tried and failed
1980 * to enter dyntick-idle mode, we refuse to try to enter it. After all,
1981 * it is better to incur scheduling-clock interrupts than to spin
1982 * continuously for the same time duration!
1983 */
1984int rcu_needs_cpu(int cpu)
1985{
1986 /* If no callbacks, RCU doesn't need the CPU. */
1987 if (!rcu_cpu_has_callbacks(cpu))
1988 return 0;
1989 /* Otherwise, RCU needs the CPU only if it recently tried and failed. */
1990 return per_cpu(rcu_dyntick_holdoff, cpu) == jiffies;
1991}
1992
486e2593
PM
1993/*
1994 * Does the specified flavor of RCU have non-lazy callbacks pending on
1995 * the specified CPU? Both RCU flavor and CPU are specified by the
1996 * rcu_data structure.
1997 */
1998static bool __rcu_cpu_has_nonlazy_callbacks(struct rcu_data *rdp)
1999{
2000 return rdp->qlen != rdp->qlen_lazy;
2001}
2002
2003#ifdef CONFIG_TREE_PREEMPT_RCU
2004
2005/*
2006 * Are there non-lazy RCU-preempt callbacks? (There cannot be if there
2007 * is no RCU-preempt in the kernel.)
2008 */
2009static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
2010{
2011 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
2012
2013 return __rcu_cpu_has_nonlazy_callbacks(rdp);
2014}
2015
2016#else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2017
2018static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
2019{
2020 return 0;
2021}
2022
2023#endif /* else #ifdef CONFIG_TREE_PREEMPT_RCU */
2024
2025/*
2026 * Does any flavor of RCU have non-lazy callbacks on the specified CPU?
2027 */
2028static bool rcu_cpu_has_nonlazy_callbacks(int cpu)
2029{
2030 return __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_sched_data, cpu)) ||
2031 __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_bh_data, cpu)) ||
2032 rcu_preempt_cpu_has_nonlazy_callbacks(cpu);
2033}
2034
7cb92499
PM
2035/*
2036 * Timer handler used to force CPU to start pushing its remaining RCU
2037 * callbacks in the case where it entered dyntick-idle mode with callbacks
2038 * pending. The hander doesn't really need to do anything because the
2039 * real work is done upon re-entry to idle, or by the next scheduling-clock
2040 * interrupt should idle not be re-entered.
2041 */
2042static enum hrtimer_restart rcu_idle_gp_timer_func(struct hrtimer *hrtp)
2043{
2044 trace_rcu_prep_idle("Timer");
2045 return HRTIMER_NORESTART;
2046}
2047
2048/*
2049 * Initialize the timer used to pull CPUs out of dyntick-idle mode.
2050 */
2051static void rcu_prepare_for_idle_init(int cpu)
2052{
2053 static int firsttime = 1;
2054 struct hrtimer *hrtp = &per_cpu(rcu_idle_gp_timer, cpu);
2055
2056 hrtimer_init(hrtp, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2057 hrtp->function = rcu_idle_gp_timer_func;
2058 if (firsttime) {
2059 unsigned int upj = jiffies_to_usecs(RCU_IDLE_GP_DELAY);
2060
2061 rcu_idle_gp_wait = ns_to_ktime(upj * (u64)1000);
778d250a
PM
2062 upj = jiffies_to_usecs(RCU_IDLE_LAZY_GP_DELAY);
2063 rcu_idle_lazy_gp_wait = ns_to_ktime(upj * (u64)1000);
7cb92499
PM
2064 firsttime = 0;
2065 }
2066}
2067
2068/*
2069 * Clean up for exit from idle. Because we are exiting from idle, there
2070 * is no longer any point to rcu_idle_gp_timer, so cancel it. This will
2071 * do nothing if this timer is not active, so just cancel it unconditionally.
2072 */
2073static void rcu_cleanup_after_idle(int cpu)
2074{
2075 hrtimer_cancel(&per_cpu(rcu_idle_gp_timer, cpu));
2076}
2077
aea1b35e
PM
2078/*
2079 * Check to see if any RCU-related work can be done by the current CPU,
2080 * and if so, schedule a softirq to get it done. This function is part
2081 * of the RCU implementation; it is -not- an exported member of the RCU API.
8bd93a2c 2082 *
aea1b35e
PM
2083 * The idea is for the current CPU to clear out all work required by the
2084 * RCU core for the current grace period, so that this CPU can be permitted
2085 * to enter dyntick-idle mode. In some cases, it will need to be awakened
2086 * at the end of the grace period by whatever CPU ends the grace period.
2087 * This allows CPUs to go dyntick-idle more quickly, and to reduce the
2088 * number of wakeups by a modest integer factor.
a47cd880
PM
2089 *
2090 * Because it is not legal to invoke rcu_process_callbacks() with irqs
2091 * disabled, we do one pass of force_quiescent_state(), then do a
a46e0899 2092 * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked
27f4d280 2093 * later. The per-cpu rcu_dyntick_drain variable controls the sequencing.
aea1b35e
PM
2094 *
2095 * The caller must have disabled interrupts.
8bd93a2c 2096 */
aea1b35e 2097static void rcu_prepare_for_idle(int cpu)
8bd93a2c 2098{
3084f2f8 2099 /*
f535a607
PM
2100 * If there are no callbacks on this CPU, enter dyntick-idle mode.
2101 * Also reset state to avoid prejudicing later attempts.
3084f2f8 2102 */
aea1b35e
PM
2103 if (!rcu_cpu_has_callbacks(cpu)) {
2104 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
3084f2f8 2105 per_cpu(rcu_dyntick_drain, cpu) = 0;
433cdddc 2106 trace_rcu_prep_idle("No callbacks");
aea1b35e 2107 return;
77e38ed3 2108 }
3084f2f8
PM
2109
2110 /*
2111 * If in holdoff mode, just return. We will presumably have
2112 * refrained from disabling the scheduling-clock tick.
2113 */
433cdddc
PM
2114 if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies) {
2115 trace_rcu_prep_idle("In holdoff");
aea1b35e 2116 return;
433cdddc 2117 }
a47cd880
PM
2118
2119 /* Check and update the rcu_dyntick_drain sequencing. */
2120 if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
2121 /* First time through, initialize the counter. */
f23f7fa1
PM
2122 per_cpu(rcu_dyntick_drain, cpu) = RCU_IDLE_FLUSHES;
2123 } else if (per_cpu(rcu_dyntick_drain, cpu) <= RCU_IDLE_OPT_FLUSHES &&
2124 !rcu_pending(cpu)) {
7cb92499 2125 /* Can we go dyntick-idle despite still having callbacks? */
f23f7fa1
PM
2126 trace_rcu_prep_idle("Dyntick with callbacks");
2127 per_cpu(rcu_dyntick_drain, cpu) = 0;
2128 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
486e2593
PM
2129 if (rcu_cpu_has_nonlazy_callbacks(cpu))
2130 hrtimer_start(&per_cpu(rcu_idle_gp_timer, cpu),
2131 rcu_idle_gp_wait, HRTIMER_MODE_REL);
778d250a
PM
2132 else
2133 hrtimer_start(&per_cpu(rcu_idle_gp_timer, cpu),
2134 rcu_idle_lazy_gp_wait, HRTIMER_MODE_REL);
f23f7fa1
PM
2135 return; /* Nothing more to do immediately. */
2136 } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
a47cd880 2137 /* We have hit the limit, so time to give up. */
71da8132 2138 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
433cdddc 2139 trace_rcu_prep_idle("Begin holdoff");
aea1b35e
PM
2140 invoke_rcu_core(); /* Force the CPU out of dyntick-idle. */
2141 return;
a47cd880
PM
2142 }
2143
aea1b35e
PM
2144 /*
2145 * Do one step of pushing the remaining RCU callbacks through
2146 * the RCU core state machine.
2147 */
2148#ifdef CONFIG_TREE_PREEMPT_RCU
2149 if (per_cpu(rcu_preempt_data, cpu).nxtlist) {
2150 rcu_preempt_qs(cpu);
2151 force_quiescent_state(&rcu_preempt_state, 0);
aea1b35e
PM
2152 }
2153#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
a47cd880
PM
2154 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
2155 rcu_sched_qs(cpu);
2156 force_quiescent_state(&rcu_sched_state, 0);
a47cd880
PM
2157 }
2158 if (per_cpu(rcu_bh_data, cpu).nxtlist) {
2159 rcu_bh_qs(cpu);
2160 force_quiescent_state(&rcu_bh_state, 0);
8bd93a2c
PM
2161 }
2162
433cdddc
PM
2163 /*
2164 * If RCU callbacks are still pending, RCU still needs this CPU.
2165 * So try forcing the callbacks through the grace period.
2166 */
3ad0decf 2167 if (rcu_cpu_has_callbacks(cpu)) {
433cdddc 2168 trace_rcu_prep_idle("More callbacks");
a46e0899 2169 invoke_rcu_core();
c0cfbbb0 2170 } else
433cdddc 2171 trace_rcu_prep_idle("Callbacks drained");
8bd93a2c
PM
2172}
2173
2174#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
a858af28
PM
2175
2176#ifdef CONFIG_RCU_CPU_STALL_INFO
2177
2178#ifdef CONFIG_RCU_FAST_NO_HZ
2179
2180static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
2181{
2182 struct hrtimer *hrtp = &per_cpu(rcu_idle_gp_timer, cpu);
2183
2184 sprintf(cp, "drain=%d %c timer=%lld",
2185 per_cpu(rcu_dyntick_drain, cpu),
2186 per_cpu(rcu_dyntick_holdoff, cpu) == jiffies ? 'H' : '.',
2187 hrtimer_active(hrtp)
2188 ? ktime_to_us(hrtimer_get_remaining(hrtp))
2189 : -1);
2190}
2191
2192#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
2193
2194static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
2195{
2196}
2197
2198#endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
2199
2200/* Initiate the stall-info list. */
2201static void print_cpu_stall_info_begin(void)
2202{
2203 printk(KERN_CONT "\n");
2204}
2205
2206/*
2207 * Print out diagnostic information for the specified stalled CPU.
2208 *
2209 * If the specified CPU is aware of the current RCU grace period
2210 * (flavor specified by rsp), then print the number of scheduling
2211 * clock interrupts the CPU has taken during the time that it has
2212 * been aware. Otherwise, print the number of RCU grace periods
2213 * that this CPU is ignorant of, for example, "1" if the CPU was
2214 * aware of the previous grace period.
2215 *
2216 * Also print out idle and (if CONFIG_RCU_FAST_NO_HZ) idle-entry info.
2217 */
2218static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
2219{
2220 char fast_no_hz[72];
2221 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2222 struct rcu_dynticks *rdtp = rdp->dynticks;
2223 char *ticks_title;
2224 unsigned long ticks_value;
2225
2226 if (rsp->gpnum == rdp->gpnum) {
2227 ticks_title = "ticks this GP";
2228 ticks_value = rdp->ticks_this_gp;
2229 } else {
2230 ticks_title = "GPs behind";
2231 ticks_value = rsp->gpnum - rdp->gpnum;
2232 }
2233 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
2234 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
2235 cpu, ticks_value, ticks_title,
2236 atomic_read(&rdtp->dynticks) & 0xfff,
2237 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
2238 fast_no_hz);
2239}
2240
2241/* Terminate the stall-info list. */
2242static void print_cpu_stall_info_end(void)
2243{
2244 printk(KERN_ERR "\t");
2245}
2246
2247/* Zero ->ticks_this_gp for all flavors of RCU. */
2248static void zero_cpu_stall_ticks(struct rcu_data *rdp)
2249{
2250 rdp->ticks_this_gp = 0;
2251}
2252
2253/* Increment ->ticks_this_gp for all flavors of RCU. */
2254static void increment_cpu_stall_ticks(void)
2255{
2256 __get_cpu_var(rcu_sched_data).ticks_this_gp++;
2257 __get_cpu_var(rcu_bh_data).ticks_this_gp++;
2258#ifdef CONFIG_TREE_PREEMPT_RCU
2259 __get_cpu_var(rcu_preempt_data).ticks_this_gp++;
2260#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2261}
2262
2263#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
2264
2265static void print_cpu_stall_info_begin(void)
2266{
2267 printk(KERN_CONT " {");
2268}
2269
2270static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
2271{
2272 printk(KERN_CONT " %d", cpu);
2273}
2274
2275static void print_cpu_stall_info_end(void)
2276{
2277 printk(KERN_CONT "} ");
2278}
2279
2280static void zero_cpu_stall_ticks(struct rcu_data *rdp)
2281{
2282}
2283
2284static void increment_cpu_stall_ticks(void)
2285{
2286}
2287
2288#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */