2 * Read-Copy Update mechanism for mutual exclusion (tree-based version)
3 * Internal non-public definitions that provide either classic
4 * or preemptable semantics.
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.
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.
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.
20 * Copyright Red Hat, 2009
21 * Copyright IBM Corporation, 2009
23 * Author: Ingo Molnar <mingo@elte.hu>
24 * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
27 #include <linux/delay.h>
29 #ifdef CONFIG_TREE_PREEMPT_RCU
31 struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state);
32 DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data);
34 static int rcu_preempted_readers_exp(struct rcu_node *rnp);
37 * Tell them what RCU they are running.
39 static void __init rcu_bootup_announce(void)
42 "Experimental preemptable hierarchical RCU implementation.\n");
46 * Return the number of RCU-preempt batches processed thus far
47 * for debug and statistics.
49 long rcu_batches_completed_preempt(void)
51 return rcu_preempt_state.completed;
53 EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt);
56 * Return the number of RCU batches processed thus far for debug & stats.
58 long rcu_batches_completed(void)
60 return rcu_batches_completed_preempt();
62 EXPORT_SYMBOL_GPL(rcu_batches_completed);
65 * Force a quiescent state for preemptible RCU.
67 void rcu_force_quiescent_state(void)
69 force_quiescent_state(&rcu_preempt_state, 0);
71 EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
74 * Record a preemptable-RCU quiescent state for the specified CPU. Note
75 * that this just means that the task currently running on the CPU is
76 * not in a quiescent state. There might be any number of tasks blocked
77 * while in an RCU read-side critical section.
79 * Unlike the other rcu_*_qs() functions, callers to this function
80 * must disable irqs in order to protect the assignment to
81 * ->rcu_read_unlock_special.
83 static void rcu_preempt_qs(int cpu)
85 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
87 rdp->passed_quiesc_completed = rdp->gpnum - 1;
89 rdp->passed_quiesc = 1;
90 current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
94 * We have entered the scheduler, and the current task might soon be
95 * context-switched away from. If this task is in an RCU read-side
96 * critical section, we will no longer be able to rely on the CPU to
97 * record that fact, so we enqueue the task on the appropriate entry
98 * of the blocked_tasks[] array. The task will dequeue itself when
99 * it exits the outermost enclosing RCU read-side critical section.
100 * Therefore, the current grace period cannot be permitted to complete
101 * until the blocked_tasks[] entry indexed by the low-order bit of
102 * rnp->gpnum empties.
104 * Caller must disable preemption.
106 static void rcu_preempt_note_context_switch(int cpu)
108 struct task_struct *t = current;
111 struct rcu_data *rdp;
112 struct rcu_node *rnp;
114 if (t->rcu_read_lock_nesting &&
115 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
117 /* Possibly blocking in an RCU read-side critical section. */
118 rdp = rcu_preempt_state.rda[cpu];
120 raw_spin_lock_irqsave(&rnp->lock, flags);
121 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
122 t->rcu_blocked_node = rnp;
125 * If this CPU has already checked in, then this task
126 * will hold up the next grace period rather than the
127 * current grace period. Queue the task accordingly.
128 * If the task is queued for the current grace period
129 * (i.e., this CPU has not yet passed through a quiescent
130 * state for the current grace period), then as long
131 * as that task remains queued, the current grace period
134 * But first, note that the current CPU must still be
137 WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
138 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
139 phase = (rnp->gpnum + !(rnp->qsmask & rdp->grpmask)) & 0x1;
140 list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]);
141 raw_spin_unlock_irqrestore(&rnp->lock, flags);
145 * Either we were not in an RCU read-side critical section to
146 * begin with, or we have now recorded that critical section
147 * globally. Either way, we can now note a quiescent state
148 * for this CPU. Again, if we were in an RCU read-side critical
149 * section, and if that critical section was blocking the current
150 * grace period, then the fact that the task has been enqueued
151 * means that we continue to block the current grace period.
153 local_irq_save(flags);
155 local_irq_restore(flags);
159 * Tree-preemptable RCU implementation for rcu_read_lock().
160 * Just increment ->rcu_read_lock_nesting, shared state will be updated
163 void __rcu_read_lock(void)
165 ACCESS_ONCE(current->rcu_read_lock_nesting)++;
166 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
168 EXPORT_SYMBOL_GPL(__rcu_read_lock);
171 * Check for preempted RCU readers blocking the current grace period
172 * for the specified rcu_node structure. If the caller needs a reliable
173 * answer, it must hold the rcu_node's ->lock.
175 static int rcu_preempted_readers(struct rcu_node *rnp)
177 int phase = rnp->gpnum & 0x1;
179 return !list_empty(&rnp->blocked_tasks[phase]) ||
180 !list_empty(&rnp->blocked_tasks[phase + 2]);
184 * Record a quiescent state for all tasks that were previously queued
185 * on the specified rcu_node structure and that were blocking the current
186 * RCU grace period. The caller must hold the specified rnp->lock with
187 * irqs disabled, and this lock is released upon return, but irqs remain
190 static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
191 __releases(rnp->lock)
194 struct rcu_node *rnp_p;
196 if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) {
197 raw_spin_unlock_irqrestore(&rnp->lock, flags);
198 return; /* Still need more quiescent states! */
204 * Either there is only one rcu_node in the tree,
205 * or tasks were kicked up to root rcu_node due to
206 * CPUs going offline.
208 rcu_report_qs_rsp(&rcu_preempt_state, flags);
212 /* Report up the rest of the hierarchy. */
214 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
215 raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */
216 rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
220 * Handle special cases during rcu_read_unlock(), such as needing to
221 * notify RCU core processing or task having blocked during the RCU
222 * read-side critical section.
224 static void rcu_read_unlock_special(struct task_struct *t)
229 struct rcu_node *rnp;
232 /* NMI handlers cannot block and cannot safely manipulate state. */
236 local_irq_save(flags);
239 * If RCU core is waiting for this CPU to exit critical section,
240 * let it know that we have done so.
242 special = t->rcu_read_unlock_special;
243 if (special & RCU_READ_UNLOCK_NEED_QS) {
244 rcu_preempt_qs(smp_processor_id());
247 /* Hardware IRQ handlers cannot block. */
249 local_irq_restore(flags);
253 /* Clean up if blocked during RCU read-side critical section. */
254 if (special & RCU_READ_UNLOCK_BLOCKED) {
255 t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED;
258 * Remove this task from the list it blocked on. The
259 * task can migrate while we acquire the lock, but at
260 * most one time. So at most two passes through loop.
263 rnp = t->rcu_blocked_node;
264 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
265 if (rnp == t->rcu_blocked_node)
267 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
269 empty = !rcu_preempted_readers(rnp);
270 empty_exp = !rcu_preempted_readers_exp(rnp);
271 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
272 list_del_init(&t->rcu_node_entry);
273 t->rcu_blocked_node = NULL;
276 * If this was the last task on the current list, and if
277 * we aren't waiting on any CPUs, report the quiescent state.
278 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock.
281 raw_spin_unlock_irqrestore(&rnp->lock, flags);
283 rcu_report_unblock_qs_rnp(rnp, flags);
286 * If this was the last task on the expedited lists,
287 * then we need to report up the rcu_node hierarchy.
289 if (!empty_exp && !rcu_preempted_readers_exp(rnp))
290 rcu_report_exp_rnp(&rcu_preempt_state, rnp);
292 local_irq_restore(flags);
297 * Tree-preemptable RCU implementation for rcu_read_unlock().
298 * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost
299 * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then
300 * invoke rcu_read_unlock_special() to clean up after a context switch
301 * in an RCU read-side critical section and other special cases.
303 void __rcu_read_unlock(void)
305 struct task_struct *t = current;
307 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
308 if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
309 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
310 rcu_read_unlock_special(t);
311 #ifdef CONFIG_PROVE_LOCKING
312 WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0);
313 #endif /* #ifdef CONFIG_PROVE_LOCKING */
315 EXPORT_SYMBOL_GPL(__rcu_read_unlock);
317 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
319 #ifdef CONFIG_RCU_CPU_STALL_VERBOSE
322 * Dump detailed information for all tasks blocking the current RCU
323 * grace period on the specified rcu_node structure.
325 static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
328 struct list_head *lp;
330 struct task_struct *t;
332 if (rcu_preempted_readers(rnp)) {
333 raw_spin_lock_irqsave(&rnp->lock, flags);
334 phase = rnp->gpnum & 0x1;
335 lp = &rnp->blocked_tasks[phase];
336 list_for_each_entry(t, lp, rcu_node_entry)
338 raw_spin_unlock_irqrestore(&rnp->lock, flags);
343 * Dump detailed information for all tasks blocking the current RCU
346 static void rcu_print_detail_task_stall(struct rcu_state *rsp)
348 struct rcu_node *rnp = rcu_get_root(rsp);
350 rcu_print_detail_task_stall_rnp(rnp);
351 rcu_for_each_leaf_node(rsp, rnp)
352 rcu_print_detail_task_stall_rnp(rnp);
355 #else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
357 static void rcu_print_detail_task_stall(struct rcu_state *rsp)
361 #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
364 * Scan the current list of tasks blocked within RCU read-side critical
365 * sections, printing out the tid of each.
367 static void rcu_print_task_stall(struct rcu_node *rnp)
369 struct list_head *lp;
371 struct task_struct *t;
373 if (rcu_preempted_readers(rnp)) {
374 phase = rnp->gpnum & 0x1;
375 lp = &rnp->blocked_tasks[phase];
376 list_for_each_entry(t, lp, rcu_node_entry)
377 printk(" P%d", t->pid);
381 #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
384 * Check that the list of blocked tasks for the newly completed grace
385 * period is in fact empty. It is a serious bug to complete a grace
386 * period that still has RCU readers blocked! This function must be
387 * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
388 * must be held by the caller.
390 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
392 WARN_ON_ONCE(rcu_preempted_readers(rnp));
393 WARN_ON_ONCE(rnp->qsmask);
396 #ifdef CONFIG_HOTPLUG_CPU
399 * Handle tasklist migration for case in which all CPUs covered by the
400 * specified rcu_node have gone offline. Move them up to the root
401 * rcu_node. The reason for not just moving them to the immediate
402 * parent is to remove the need for rcu_read_unlock_special() to
403 * make more than two attempts to acquire the target rcu_node's lock.
404 * Returns true if there were tasks blocking the current RCU grace
407 * Returns 1 if there was previously a task blocking the current grace
408 * period on the specified rcu_node structure.
410 * The caller must hold rnp->lock with irqs disabled.
412 static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
413 struct rcu_node *rnp,
414 struct rcu_data *rdp)
417 struct list_head *lp;
418 struct list_head *lp_root;
420 struct rcu_node *rnp_root = rcu_get_root(rsp);
421 struct task_struct *tp;
423 if (rnp == rnp_root) {
424 WARN_ONCE(1, "Last CPU thought to be offlined?");
425 return 0; /* Shouldn't happen: at least one CPU online. */
427 WARN_ON_ONCE(rnp != rdp->mynode &&
428 (!list_empty(&rnp->blocked_tasks[0]) ||
429 !list_empty(&rnp->blocked_tasks[1]) ||
430 !list_empty(&rnp->blocked_tasks[2]) ||
431 !list_empty(&rnp->blocked_tasks[3])));
434 * Move tasks up to root rcu_node. Rely on the fact that the
435 * root rcu_node can be at most one ahead of the rest of the
436 * rcu_nodes in terms of gp_num value. This fact allows us to
437 * move the blocked_tasks[] array directly, element by element.
439 if (rcu_preempted_readers(rnp))
440 retval |= RCU_OFL_TASKS_NORM_GP;
441 if (rcu_preempted_readers_exp(rnp))
442 retval |= RCU_OFL_TASKS_EXP_GP;
443 for (i = 0; i < 4; i++) {
444 lp = &rnp->blocked_tasks[i];
445 lp_root = &rnp_root->blocked_tasks[i];
446 while (!list_empty(lp)) {
447 tp = list_entry(lp->next, typeof(*tp), rcu_node_entry);
448 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
449 list_del(&tp->rcu_node_entry);
450 tp->rcu_blocked_node = rnp_root;
451 list_add(&tp->rcu_node_entry, lp_root);
452 raw_spin_unlock(&rnp_root->lock); /* irqs remain disabled */
459 * Do CPU-offline processing for preemptable RCU.
461 static void rcu_preempt_offline_cpu(int cpu)
463 __rcu_offline_cpu(cpu, &rcu_preempt_state);
466 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
469 * Check for a quiescent state from the current CPU. When a task blocks,
470 * the task is recorded in the corresponding CPU's rcu_node structure,
471 * which is checked elsewhere.
473 * Caller must disable hard irqs.
475 static void rcu_preempt_check_callbacks(int cpu)
477 struct task_struct *t = current;
479 if (t->rcu_read_lock_nesting == 0) {
483 if (per_cpu(rcu_preempt_data, cpu).qs_pending)
484 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
488 * Process callbacks for preemptable RCU.
490 static void rcu_preempt_process_callbacks(void)
492 __rcu_process_callbacks(&rcu_preempt_state,
493 &__get_cpu_var(rcu_preempt_data));
497 * Queue a preemptable-RCU callback for invocation after a grace period.
499 void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
501 __call_rcu(head, func, &rcu_preempt_state);
503 EXPORT_SYMBOL_GPL(call_rcu);
506 * synchronize_rcu - wait until a grace period has elapsed.
508 * Control will return to the caller some time after a full grace
509 * period has elapsed, in other words after all currently executing RCU
510 * read-side critical sections have completed. RCU read-side critical
511 * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
514 void synchronize_rcu(void)
516 struct rcu_synchronize rcu;
518 if (!rcu_scheduler_active)
521 init_completion(&rcu.completion);
522 /* Will wake me after RCU finished. */
523 call_rcu(&rcu.head, wakeme_after_rcu);
525 wait_for_completion(&rcu.completion);
527 EXPORT_SYMBOL_GPL(synchronize_rcu);
529 static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
530 static long sync_rcu_preempt_exp_count;
531 static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
534 * Return non-zero if there are any tasks in RCU read-side critical
535 * sections blocking the current preemptible-RCU expedited grace period.
536 * If there is no preemptible-RCU expedited grace period currently in
537 * progress, returns zero unconditionally.
539 static int rcu_preempted_readers_exp(struct rcu_node *rnp)
541 return !list_empty(&rnp->blocked_tasks[2]) ||
542 !list_empty(&rnp->blocked_tasks[3]);
546 * return non-zero if there is no RCU expedited grace period in progress
547 * for the specified rcu_node structure, in other words, if all CPUs and
548 * tasks covered by the specified rcu_node structure have done their bit
549 * for the current expedited grace period. Works only for preemptible
550 * RCU -- other RCU implementation use other means.
552 * Caller must hold sync_rcu_preempt_exp_mutex.
554 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
556 return !rcu_preempted_readers_exp(rnp) &&
557 ACCESS_ONCE(rnp->expmask) == 0;
561 * Report the exit from RCU read-side critical section for the last task
562 * that queued itself during or before the current expedited preemptible-RCU
563 * grace period. This event is reported either to the rcu_node structure on
564 * which the task was queued or to one of that rcu_node structure's ancestors,
565 * recursively up the tree. (Calm down, calm down, we do the recursion
568 * Caller must hold sync_rcu_preempt_exp_mutex.
570 static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
575 raw_spin_lock_irqsave(&rnp->lock, flags);
577 if (!sync_rcu_preempt_exp_done(rnp))
579 if (rnp->parent == NULL) {
580 wake_up(&sync_rcu_preempt_exp_wq);
584 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
586 raw_spin_lock(&rnp->lock); /* irqs already disabled */
587 rnp->expmask &= ~mask;
589 raw_spin_unlock_irqrestore(&rnp->lock, flags);
593 * Snapshot the tasks blocking the newly started preemptible-RCU expedited
594 * grace period for the specified rcu_node structure. If there are no such
595 * tasks, report it up the rcu_node hierarchy.
597 * Caller must hold sync_rcu_preempt_exp_mutex and rsp->onofflock.
600 sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp)
604 raw_spin_lock(&rnp->lock); /* irqs already disabled */
605 list_splice_init(&rnp->blocked_tasks[0], &rnp->blocked_tasks[2]);
606 list_splice_init(&rnp->blocked_tasks[1], &rnp->blocked_tasks[3]);
607 must_wait = rcu_preempted_readers_exp(rnp);
608 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
610 rcu_report_exp_rnp(rsp, rnp);
614 * Wait for an rcu-preempt grace period, but expedite it. The basic idea
615 * is to invoke synchronize_sched_expedited() to push all the tasks to
616 * the ->blocked_tasks[] lists, move all entries from the first set of
617 * ->blocked_tasks[] lists to the second set, and finally wait for this
618 * second set to drain.
620 void synchronize_rcu_expedited(void)
623 struct rcu_node *rnp;
624 struct rcu_state *rsp = &rcu_preempt_state;
628 smp_mb(); /* Caller's modifications seen first by other CPUs. */
629 snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1;
630 smp_mb(); /* Above access cannot bleed into critical section. */
633 * Acquire lock, falling back to synchronize_rcu() if too many
634 * lock-acquisition failures. Of course, if someone does the
635 * expedited grace period for us, just leave.
637 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
639 udelay(trycount * num_online_cpus());
644 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
645 goto mb_ret; /* Others did our work for us. */
647 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
648 goto unlock_mb_ret; /* Others did our work for us. */
650 /* force all RCU readers onto blocked_tasks[]. */
651 synchronize_sched_expedited();
653 raw_spin_lock_irqsave(&rsp->onofflock, flags);
655 /* Initialize ->expmask for all non-leaf rcu_node structures. */
656 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
657 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
658 rnp->expmask = rnp->qsmaskinit;
659 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
662 /* Snapshot current state of ->blocked_tasks[] lists. */
663 rcu_for_each_leaf_node(rsp, rnp)
664 sync_rcu_preempt_exp_init(rsp, rnp);
665 if (NUM_RCU_NODES > 1)
666 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
668 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
670 /* Wait for snapshotted ->blocked_tasks[] lists to drain. */
671 rnp = rcu_get_root(rsp);
672 wait_event(sync_rcu_preempt_exp_wq,
673 sync_rcu_preempt_exp_done(rnp));
675 /* Clean up and exit. */
676 smp_mb(); /* ensure expedited GP seen before counter increment. */
677 ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
679 mutex_unlock(&sync_rcu_preempt_exp_mutex);
681 smp_mb(); /* ensure subsequent action seen after grace period. */
683 EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
686 * Check to see if there is any immediate preemptable-RCU-related work
689 static int rcu_preempt_pending(int cpu)
691 return __rcu_pending(&rcu_preempt_state,
692 &per_cpu(rcu_preempt_data, cpu));
696 * Does preemptable RCU need the CPU to stay out of dynticks mode?
698 static int rcu_preempt_needs_cpu(int cpu)
700 return !!per_cpu(rcu_preempt_data, cpu).nxtlist;
704 * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
706 void rcu_barrier(void)
708 _rcu_barrier(&rcu_preempt_state, call_rcu);
710 EXPORT_SYMBOL_GPL(rcu_barrier);
713 * Initialize preemptable RCU's per-CPU data.
715 static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
717 rcu_init_percpu_data(cpu, &rcu_preempt_state, 1);
721 * Move preemptable RCU's callbacks to ->orphan_cbs_list.
723 static void rcu_preempt_send_cbs_to_orphanage(void)
725 rcu_send_cbs_to_orphanage(&rcu_preempt_state);
729 * Initialize preemptable RCU's state structures.
731 static void __init __rcu_init_preempt(void)
733 RCU_INIT_FLAVOR(&rcu_preempt_state, rcu_preempt_data);
737 * Check for a task exiting while in a preemptable-RCU read-side
738 * critical section, clean up if so. No need to issue warnings,
739 * as debug_check_no_locks_held() already does this if lockdep
744 struct task_struct *t = current;
746 if (t->rcu_read_lock_nesting == 0)
748 t->rcu_read_lock_nesting = 1;
752 #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
755 * Tell them what RCU they are running.
757 static void __init rcu_bootup_announce(void)
759 printk(KERN_INFO "Hierarchical RCU implementation.\n");
763 * Return the number of RCU batches processed thus far for debug & stats.
765 long rcu_batches_completed(void)
767 return rcu_batches_completed_sched();
769 EXPORT_SYMBOL_GPL(rcu_batches_completed);
772 * Force a quiescent state for RCU, which, because there is no preemptible
773 * RCU, becomes the same as rcu-sched.
775 void rcu_force_quiescent_state(void)
777 rcu_sched_force_quiescent_state();
779 EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
782 * Because preemptable RCU does not exist, we never have to check for
783 * CPUs being in quiescent states.
785 static void rcu_preempt_note_context_switch(int cpu)
790 * Because preemptable RCU does not exist, there are never any preempted
793 static int rcu_preempted_readers(struct rcu_node *rnp)
798 #ifdef CONFIG_HOTPLUG_CPU
800 /* Because preemptible RCU does not exist, no quieting of tasks. */
801 static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
803 raw_spin_unlock_irqrestore(&rnp->lock, flags);
806 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
808 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
811 * Because preemptable RCU does not exist, we never have to check for
812 * tasks blocked within RCU read-side critical sections.
814 static void rcu_print_detail_task_stall(struct rcu_state *rsp)
819 * Because preemptable RCU does not exist, we never have to check for
820 * tasks blocked within RCU read-side critical sections.
822 static void rcu_print_task_stall(struct rcu_node *rnp)
826 #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
829 * Because there is no preemptable RCU, there can be no readers blocked,
830 * so there is no need to check for blocked tasks. So check only for
831 * bogus qsmask values.
833 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
835 WARN_ON_ONCE(rnp->qsmask);
838 #ifdef CONFIG_HOTPLUG_CPU
841 * Because preemptable RCU does not exist, it never needs to migrate
842 * tasks that were blocked within RCU read-side critical sections, and
843 * such non-existent tasks cannot possibly have been blocking the current
846 static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
847 struct rcu_node *rnp,
848 struct rcu_data *rdp)
854 * Because preemptable RCU does not exist, it never needs CPU-offline
857 static void rcu_preempt_offline_cpu(int cpu)
861 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
864 * Because preemptable RCU does not exist, it never has any callbacks
867 static void rcu_preempt_check_callbacks(int cpu)
872 * Because preemptable RCU does not exist, it never has any callbacks
875 static void rcu_preempt_process_callbacks(void)
880 * In classic RCU, call_rcu() is just call_rcu_sched().
882 void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
884 call_rcu_sched(head, func);
886 EXPORT_SYMBOL_GPL(call_rcu);
889 * Wait for an rcu-preempt grace period, but make it happen quickly.
890 * But because preemptable RCU does not exist, map to rcu-sched.
892 void synchronize_rcu_expedited(void)
894 synchronize_sched_expedited();
896 EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
898 #ifdef CONFIG_HOTPLUG_CPU
901 * Because preemptable RCU does not exist, there is never any need to
902 * report on tasks preempted in RCU read-side critical sections during
903 * expedited RCU grace periods.
905 static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp)
910 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
913 * Because preemptable RCU does not exist, it never has any work to do.
915 static int rcu_preempt_pending(int cpu)
921 * Because preemptable RCU does not exist, it never needs any CPU.
923 static int rcu_preempt_needs_cpu(int cpu)
929 * Because preemptable RCU does not exist, rcu_barrier() is just
930 * another name for rcu_barrier_sched().
932 void rcu_barrier(void)
936 EXPORT_SYMBOL_GPL(rcu_barrier);
939 * Because preemptable RCU does not exist, there is no per-CPU
940 * data to initialize.
942 static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
947 * Because there is no preemptable RCU, there are no callbacks to move.
949 static void rcu_preempt_send_cbs_to_orphanage(void)
954 * Because preemptable RCU does not exist, it need not be initialized.
956 static void __init __rcu_init_preempt(void)
960 #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */
962 #if !defined(CONFIG_RCU_FAST_NO_HZ)
965 * Check to see if any future RCU-related work will need to be done
966 * by the current CPU, even if none need be done immediately, returning
967 * 1 if so. This function is part of the RCU implementation; it is -not-
968 * an exported member of the RCU API.
970 * Because we have preemptible RCU, just check whether this CPU needs
971 * any flavor of RCU. Do not chew up lots of CPU cycles with preemption
972 * disabled in a most-likely vain attempt to cause RCU not to need this CPU.
974 int rcu_needs_cpu(int cpu)
976 return rcu_needs_cpu_quick_check(cpu);
980 * Check to see if we need to continue a callback-flush operations to
981 * allow the last CPU to enter dyntick-idle mode. But fast dyntick-idle
982 * entry is not configured, so we never do need to.
984 static void rcu_needs_cpu_flush(void)
988 #else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
990 #define RCU_NEEDS_CPU_FLUSHES 5
991 static DEFINE_PER_CPU(int, rcu_dyntick_drain);
992 static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
995 * Check to see if any future RCU-related work will need to be done
996 * by the current CPU, even if none need be done immediately, returning
997 * 1 if so. This function is part of the RCU implementation; it is -not-
998 * an exported member of the RCU API.
1000 * Because we are not supporting preemptible RCU, attempt to accelerate
1001 * any current grace periods so that RCU no longer needs this CPU, but
1002 * only if all other CPUs are already in dynticks-idle mode. This will
1003 * allow the CPU cores to be powered down immediately, as opposed to after
1004 * waiting many milliseconds for grace periods to elapse.
1006 * Because it is not legal to invoke rcu_process_callbacks() with irqs
1007 * disabled, we do one pass of force_quiescent_state(), then do a
1008 * raise_softirq() to cause rcu_process_callbacks() to be invoked later.
1009 * The per-cpu rcu_dyntick_drain variable controls the sequencing.
1011 int rcu_needs_cpu(int cpu)
1016 /* Check for being in the holdoff period. */
1017 if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies)
1018 return rcu_needs_cpu_quick_check(cpu);
1020 /* Don't bother unless we are the last non-dyntick-idle CPU. */
1021 for_each_cpu_not(thatcpu, nohz_cpu_mask)
1022 if (cpu_online(thatcpu) && thatcpu != cpu) {
1023 per_cpu(rcu_dyntick_drain, cpu) = 0;
1024 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
1025 return rcu_needs_cpu_quick_check(cpu);
1028 /* Check and update the rcu_dyntick_drain sequencing. */
1029 if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1030 /* First time through, initialize the counter. */
1031 per_cpu(rcu_dyntick_drain, cpu) = RCU_NEEDS_CPU_FLUSHES;
1032 } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1033 /* We have hit the limit, so time to give up. */
1034 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
1035 return rcu_needs_cpu_quick_check(cpu);
1038 /* Do one step pushing remaining RCU callbacks through. */
1039 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
1041 force_quiescent_state(&rcu_sched_state, 0);
1042 c = c || per_cpu(rcu_sched_data, cpu).nxtlist;
1044 if (per_cpu(rcu_bh_data, cpu).nxtlist) {
1046 force_quiescent_state(&rcu_bh_state, 0);
1047 c = c || per_cpu(rcu_bh_data, cpu).nxtlist;
1050 /* If RCU callbacks are still pending, RCU still needs this CPU. */
1052 raise_softirq(RCU_SOFTIRQ);
1057 * Check to see if we need to continue a callback-flush operations to
1058 * allow the last CPU to enter dyntick-idle mode.
1060 static void rcu_needs_cpu_flush(void)
1062 int cpu = smp_processor_id();
1063 unsigned long flags;
1065 if (per_cpu(rcu_dyntick_drain, cpu) <= 0)
1067 local_irq_save(flags);
1068 (void)rcu_needs_cpu(cpu);
1069 local_irq_restore(flags);
1072 #endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */