Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) |
| 3 | * Internal non-public definitions that provide either classic |
| 4 | * or preemptable semantics. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | * |
| 20 | * Copyright Red Hat, 2009 |
| 21 | * Copyright IBM Corporation, 2009 |
| 22 | * |
| 23 | * Author: Ingo Molnar <mingo@elte.hu> |
| 24 | * Paul E. McKenney <paulmck@linux.vnet.ibm.com> |
| 25 | */ |
| 26 | |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 27 | #include <linux/delay.h> |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 28 | #include <linux/stop_machine.h> |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 29 | |
Paul E. McKenney | 26845c2 | 2010-04-13 14:19:23 -0700 | [diff] [blame] | 30 | /* |
| 31 | * Check the RCU kernel configuration parameters and print informative |
| 32 | * messages about anything out of the ordinary. If you like #ifdef, you |
| 33 | * will love this function. |
| 34 | */ |
| 35 | static void __init rcu_bootup_announce_oddness(void) |
| 36 | { |
| 37 | #ifdef CONFIG_RCU_TRACE |
| 38 | printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n"); |
| 39 | #endif |
| 40 | #if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32) |
| 41 | printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n", |
| 42 | CONFIG_RCU_FANOUT); |
| 43 | #endif |
| 44 | #ifdef CONFIG_RCU_FANOUT_EXACT |
| 45 | printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n"); |
| 46 | #endif |
| 47 | #ifdef CONFIG_RCU_FAST_NO_HZ |
| 48 | printk(KERN_INFO |
| 49 | "\tRCU dyntick-idle grace-period acceleration is enabled.\n"); |
| 50 | #endif |
| 51 | #ifdef CONFIG_PROVE_RCU |
| 52 | printk(KERN_INFO "\tRCU lockdep checking is enabled.\n"); |
| 53 | #endif |
| 54 | #ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE |
| 55 | printk(KERN_INFO "\tRCU torture testing starts during boot.\n"); |
| 56 | #endif |
Paul E. McKenney | 81a294c | 2010-08-30 09:52:50 -0700 | [diff] [blame] | 57 | #if defined(CONFIG_TREE_PREEMPT_RCU) && !defined(CONFIG_RCU_CPU_STALL_VERBOSE) |
Paul E. McKenney | 26845c2 | 2010-04-13 14:19:23 -0700 | [diff] [blame] | 58 | printk(KERN_INFO "\tVerbose stalled-CPUs detection is disabled.\n"); |
| 59 | #endif |
| 60 | #if NUM_RCU_LVL_4 != 0 |
| 61 | printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n"); |
| 62 | #endif |
| 63 | } |
| 64 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 66 | |
| 67 | struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); |
| 68 | DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data); |
| 69 | |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 70 | static int rcu_preempted_readers_exp(struct rcu_node *rnp); |
| 71 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Tell them what RCU they are running. |
| 74 | */ |
Paul E. McKenney | 0e0fc1c | 2009-11-11 11:28:06 -0800 | [diff] [blame] | 75 | static void __init rcu_bootup_announce(void) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 76 | { |
Paul E. McKenney | 26845c2 | 2010-04-13 14:19:23 -0700 | [diff] [blame] | 77 | printk(KERN_INFO "Preemptable hierarchical RCU implementation.\n"); |
| 78 | rcu_bootup_announce_oddness(); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Return the number of RCU-preempt batches processed thus far |
| 83 | * for debug and statistics. |
| 84 | */ |
| 85 | long rcu_batches_completed_preempt(void) |
| 86 | { |
| 87 | return rcu_preempt_state.completed; |
| 88 | } |
| 89 | EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt); |
| 90 | |
| 91 | /* |
| 92 | * Return the number of RCU batches processed thus far for debug & stats. |
| 93 | */ |
| 94 | long rcu_batches_completed(void) |
| 95 | { |
| 96 | return rcu_batches_completed_preempt(); |
| 97 | } |
| 98 | EXPORT_SYMBOL_GPL(rcu_batches_completed); |
| 99 | |
| 100 | /* |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 101 | * Force a quiescent state for preemptible RCU. |
| 102 | */ |
| 103 | void rcu_force_quiescent_state(void) |
| 104 | { |
| 105 | force_quiescent_state(&rcu_preempt_state, 0); |
| 106 | } |
| 107 | EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); |
| 108 | |
| 109 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 110 | * Record a preemptable-RCU quiescent state for the specified CPU. Note |
| 111 | * that this just means that the task currently running on the CPU is |
| 112 | * not in a quiescent state. There might be any number of tasks blocked |
| 113 | * while in an RCU read-side critical section. |
Paul E. McKenney | 25502a6 | 2010-04-01 17:37:01 -0700 | [diff] [blame] | 114 | * |
| 115 | * Unlike the other rcu_*_qs() functions, callers to this function |
| 116 | * must disable irqs in order to protect the assignment to |
| 117 | * ->rcu_read_unlock_special. |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 118 | */ |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 119 | static void rcu_preempt_qs(int cpu) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 120 | { |
| 121 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); |
Paul E. McKenney | 25502a6 | 2010-04-01 17:37:01 -0700 | [diff] [blame] | 122 | |
Paul E. McKenney | c64ac3c | 2009-11-10 13:37:22 -0800 | [diff] [blame] | 123 | rdp->passed_quiesc_completed = rdp->gpnum - 1; |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 124 | barrier(); |
| 125 | rdp->passed_quiesc = 1; |
Paul E. McKenney | 25502a6 | 2010-04-01 17:37:01 -0700 | [diff] [blame] | 126 | current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 130 | * We have entered the scheduler, and the current task might soon be |
| 131 | * context-switched away from. If this task is in an RCU read-side |
| 132 | * critical section, we will no longer be able to rely on the CPU to |
| 133 | * record that fact, so we enqueue the task on the appropriate entry |
| 134 | * of the blocked_tasks[] array. The task will dequeue itself when |
| 135 | * it exits the outermost enclosing RCU read-side critical section. |
| 136 | * Therefore, the current grace period cannot be permitted to complete |
| 137 | * until the blocked_tasks[] entry indexed by the low-order bit of |
| 138 | * rnp->gpnum empties. |
| 139 | * |
| 140 | * Caller must disable preemption. |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 141 | */ |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 142 | static void rcu_preempt_note_context_switch(int cpu) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 143 | { |
| 144 | struct task_struct *t = current; |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 145 | unsigned long flags; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 146 | int phase; |
| 147 | struct rcu_data *rdp; |
| 148 | struct rcu_node *rnp; |
| 149 | |
| 150 | if (t->rcu_read_lock_nesting && |
| 151 | (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { |
| 152 | |
| 153 | /* Possibly blocking in an RCU read-side critical section. */ |
Lai Jiangshan | 394f99a | 2010-06-28 16:25:04 +0800 | [diff] [blame] | 154 | rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 155 | rnp = rdp->mynode; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 156 | raw_spin_lock_irqsave(&rnp->lock, flags); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 157 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; |
Paul E. McKenney | 8684896 | 2009-08-27 15:00:12 -0700 | [diff] [blame] | 158 | t->rcu_blocked_node = rnp; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * If this CPU has already checked in, then this task |
| 162 | * will hold up the next grace period rather than the |
| 163 | * current grace period. Queue the task accordingly. |
| 164 | * If the task is queued for the current grace period |
| 165 | * (i.e., this CPU has not yet passed through a quiescent |
| 166 | * state for the current grace period), then as long |
| 167 | * as that task remains queued, the current grace period |
| 168 | * cannot end. |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 169 | * |
| 170 | * But first, note that the current CPU must still be |
| 171 | * on line! |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 172 | */ |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 173 | WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0); |
Paul E. McKenney | e7d8842 | 2009-09-18 09:50:18 -0700 | [diff] [blame] | 174 | WARN_ON_ONCE(!list_empty(&t->rcu_node_entry)); |
| 175 | phase = (rnp->gpnum + !(rnp->qsmask & rdp->grpmask)) & 0x1; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 176 | list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]); |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 177 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Either we were not in an RCU read-side critical section to |
| 182 | * begin with, or we have now recorded that critical section |
| 183 | * globally. Either way, we can now note a quiescent state |
| 184 | * for this CPU. Again, if we were in an RCU read-side critical |
| 185 | * section, and if that critical section was blocking the current |
| 186 | * grace period, then the fact that the task has been enqueued |
| 187 | * means that we continue to block the current grace period. |
| 188 | */ |
Paul E. McKenney | e7d8842 | 2009-09-18 09:50:18 -0700 | [diff] [blame] | 189 | local_irq_save(flags); |
Paul E. McKenney | 25502a6 | 2010-04-01 17:37:01 -0700 | [diff] [blame] | 190 | rcu_preempt_qs(cpu); |
Paul E. McKenney | e7d8842 | 2009-09-18 09:50:18 -0700 | [diff] [blame] | 191 | local_irq_restore(flags); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * Tree-preemptable RCU implementation for rcu_read_lock(). |
| 196 | * Just increment ->rcu_read_lock_nesting, shared state will be updated |
| 197 | * if we block. |
| 198 | */ |
| 199 | void __rcu_read_lock(void) |
| 200 | { |
Paul E. McKenney | 80dcf60 | 2010-08-19 16:57:45 -0700 | [diff] [blame] | 201 | current->rcu_read_lock_nesting++; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 202 | barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */ |
| 203 | } |
| 204 | EXPORT_SYMBOL_GPL(__rcu_read_lock); |
| 205 | |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 206 | /* |
| 207 | * Check for preempted RCU readers blocking the current grace period |
| 208 | * for the specified rcu_node structure. If the caller needs a reliable |
| 209 | * answer, it must hold the rcu_node's ->lock. |
| 210 | */ |
| 211 | static int rcu_preempted_readers(struct rcu_node *rnp) |
| 212 | { |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 213 | int phase = rnp->gpnum & 0x1; |
| 214 | |
| 215 | return !list_empty(&rnp->blocked_tasks[phase]) || |
| 216 | !list_empty(&rnp->blocked_tasks[phase + 2]); |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 219 | /* |
| 220 | * Record a quiescent state for all tasks that were previously queued |
| 221 | * on the specified rcu_node structure and that were blocking the current |
| 222 | * RCU grace period. The caller must hold the specified rnp->lock with |
| 223 | * irqs disabled, and this lock is released upon return, but irqs remain |
| 224 | * disabled. |
| 225 | */ |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 226 | static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags) |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 227 | __releases(rnp->lock) |
| 228 | { |
| 229 | unsigned long mask; |
| 230 | struct rcu_node *rnp_p; |
| 231 | |
| 232 | if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) { |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 233 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 234 | return; /* Still need more quiescent states! */ |
| 235 | } |
| 236 | |
| 237 | rnp_p = rnp->parent; |
| 238 | if (rnp_p == NULL) { |
| 239 | /* |
| 240 | * Either there is only one rcu_node in the tree, |
| 241 | * or tasks were kicked up to root rcu_node due to |
| 242 | * CPUs going offline. |
| 243 | */ |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 244 | rcu_report_qs_rsp(&rcu_preempt_state, flags); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | |
| 248 | /* Report up the rest of the hierarchy. */ |
| 249 | mask = rnp->grpmask; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 250 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 251 | raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */ |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 252 | rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Handle special cases during rcu_read_unlock(), such as needing to |
| 257 | * notify RCU core processing or task having blocked during the RCU |
| 258 | * read-side critical section. |
| 259 | */ |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 260 | static void rcu_read_unlock_special(struct task_struct *t) |
| 261 | { |
| 262 | int empty; |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 263 | int empty_exp; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 264 | unsigned long flags; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 265 | struct rcu_node *rnp; |
| 266 | int special; |
| 267 | |
| 268 | /* NMI handlers cannot block and cannot safely manipulate state. */ |
| 269 | if (in_nmi()) |
| 270 | return; |
| 271 | |
| 272 | local_irq_save(flags); |
| 273 | |
| 274 | /* |
| 275 | * If RCU core is waiting for this CPU to exit critical section, |
| 276 | * let it know that we have done so. |
| 277 | */ |
| 278 | special = t->rcu_read_unlock_special; |
| 279 | if (special & RCU_READ_UNLOCK_NEED_QS) { |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 280 | rcu_preempt_qs(smp_processor_id()); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* Hardware IRQ handlers cannot block. */ |
| 284 | if (in_irq()) { |
| 285 | local_irq_restore(flags); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | /* Clean up if blocked during RCU read-side critical section. */ |
| 290 | if (special & RCU_READ_UNLOCK_BLOCKED) { |
| 291 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED; |
| 292 | |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 293 | /* |
| 294 | * Remove this task from the list it blocked on. The |
| 295 | * task can migrate while we acquire the lock, but at |
| 296 | * most one time. So at most two passes through loop. |
| 297 | */ |
| 298 | for (;;) { |
Paul E. McKenney | 8684896 | 2009-08-27 15:00:12 -0700 | [diff] [blame] | 299 | rnp = t->rcu_blocked_node; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 300 | raw_spin_lock(&rnp->lock); /* irqs already disabled. */ |
Paul E. McKenney | 8684896 | 2009-08-27 15:00:12 -0700 | [diff] [blame] | 301 | if (rnp == t->rcu_blocked_node) |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 302 | break; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 303 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 304 | } |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 305 | empty = !rcu_preempted_readers(rnp); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 306 | empty_exp = !rcu_preempted_readers_exp(rnp); |
| 307 | smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */ |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 308 | list_del_init(&t->rcu_node_entry); |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 309 | t->rcu_blocked_node = NULL; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * If this was the last task on the current list, and if |
| 313 | * we aren't waiting on any CPUs, report the quiescent state. |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 314 | * Note that rcu_report_unblock_qs_rnp() releases rnp->lock. |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 315 | */ |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 316 | if (empty) |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 317 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 318 | else |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 319 | rcu_report_unblock_qs_rnp(rnp, flags); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 320 | |
| 321 | /* |
| 322 | * If this was the last task on the expedited lists, |
| 323 | * then we need to report up the rcu_node hierarchy. |
| 324 | */ |
| 325 | if (!empty_exp && !rcu_preempted_readers_exp(rnp)) |
| 326 | rcu_report_exp_rnp(&rcu_preempt_state, rnp); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 327 | } else { |
| 328 | local_irq_restore(flags); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 329 | } |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Tree-preemptable RCU implementation for rcu_read_unlock(). |
| 334 | * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost |
| 335 | * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then |
| 336 | * invoke rcu_read_unlock_special() to clean up after a context switch |
| 337 | * in an RCU read-side critical section and other special cases. |
| 338 | */ |
| 339 | void __rcu_read_unlock(void) |
| 340 | { |
| 341 | struct task_struct *t = current; |
| 342 | |
| 343 | barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */ |
Paul E. McKenney | 80dcf60 | 2010-08-19 16:57:45 -0700 | [diff] [blame] | 344 | --t->rcu_read_lock_nesting; |
| 345 | barrier(); /* decrement before load of ->rcu_read_unlock_special */ |
| 346 | if (t->rcu_read_lock_nesting == 0 && |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 347 | unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) |
| 348 | rcu_read_unlock_special(t); |
Paul E. McKenney | cba8244 | 2010-01-04 16:04:01 -0800 | [diff] [blame] | 349 | #ifdef CONFIG_PROVE_LOCKING |
| 350 | WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0); |
| 351 | #endif /* #ifdef CONFIG_PROVE_LOCKING */ |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 352 | } |
| 353 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); |
| 354 | |
Paul E. McKenney | 1ed509a | 2010-02-22 17:05:05 -0800 | [diff] [blame] | 355 | #ifdef CONFIG_RCU_CPU_STALL_VERBOSE |
| 356 | |
| 357 | /* |
| 358 | * Dump detailed information for all tasks blocking the current RCU |
| 359 | * grace period on the specified rcu_node structure. |
| 360 | */ |
| 361 | static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp) |
| 362 | { |
| 363 | unsigned long flags; |
| 364 | struct list_head *lp; |
| 365 | int phase; |
| 366 | struct task_struct *t; |
| 367 | |
| 368 | if (rcu_preempted_readers(rnp)) { |
| 369 | raw_spin_lock_irqsave(&rnp->lock, flags); |
| 370 | phase = rnp->gpnum & 0x1; |
| 371 | lp = &rnp->blocked_tasks[phase]; |
| 372 | list_for_each_entry(t, lp, rcu_node_entry) |
| 373 | sched_show_task(t); |
| 374 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Dump detailed information for all tasks blocking the current RCU |
| 380 | * grace period. |
| 381 | */ |
| 382 | static void rcu_print_detail_task_stall(struct rcu_state *rsp) |
| 383 | { |
| 384 | struct rcu_node *rnp = rcu_get_root(rsp); |
| 385 | |
| 386 | rcu_print_detail_task_stall_rnp(rnp); |
| 387 | rcu_for_each_leaf_node(rsp, rnp) |
| 388 | rcu_print_detail_task_stall_rnp(rnp); |
| 389 | } |
| 390 | |
| 391 | #else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */ |
| 392 | |
| 393 | static void rcu_print_detail_task_stall(struct rcu_state *rsp) |
| 394 | { |
| 395 | } |
| 396 | |
| 397 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */ |
| 398 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 399 | /* |
| 400 | * Scan the current list of tasks blocked within RCU read-side critical |
| 401 | * sections, printing out the tid of each. |
| 402 | */ |
| 403 | static void rcu_print_task_stall(struct rcu_node *rnp) |
| 404 | { |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 405 | struct list_head *lp; |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 406 | int phase; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 407 | struct task_struct *t; |
| 408 | |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 409 | if (rcu_preempted_readers(rnp)) { |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 410 | phase = rnp->gpnum & 0x1; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 411 | lp = &rnp->blocked_tasks[phase]; |
| 412 | list_for_each_entry(t, lp, rcu_node_entry) |
| 413 | printk(" P%d", t->pid); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Paul E. McKenney | 53d84e0 | 2010-08-10 14:28:53 -0700 | [diff] [blame] | 417 | /* |
| 418 | * Suppress preemptible RCU's CPU stall warnings by pushing the |
| 419 | * time of the next stall-warning message comfortably far into the |
| 420 | * future. |
| 421 | */ |
| 422 | static void rcu_preempt_stall_reset(void) |
| 423 | { |
| 424 | rcu_preempt_state.jiffies_stall = jiffies + ULONG_MAX / 2; |
| 425 | } |
| 426 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 427 | /* |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 428 | * Check that the list of blocked tasks for the newly completed grace |
| 429 | * period is in fact empty. It is a serious bug to complete a grace |
| 430 | * period that still has RCU readers blocked! This function must be |
| 431 | * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock |
| 432 | * must be held by the caller. |
| 433 | */ |
| 434 | static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) |
| 435 | { |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 436 | WARN_ON_ONCE(rcu_preempted_readers(rnp)); |
Paul E. McKenney | 28ecd58 | 2009-09-18 09:50:17 -0700 | [diff] [blame] | 437 | WARN_ON_ONCE(rnp->qsmask); |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Paul E. McKenney | 33f7614 | 2009-08-24 09:42:01 -0700 | [diff] [blame] | 440 | #ifdef CONFIG_HOTPLUG_CPU |
| 441 | |
| 442 | /* |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 443 | * Handle tasklist migration for case in which all CPUs covered by the |
| 444 | * specified rcu_node have gone offline. Move them up to the root |
| 445 | * rcu_node. The reason for not just moving them to the immediate |
| 446 | * parent is to remove the need for rcu_read_unlock_special() to |
| 447 | * make more than two attempts to acquire the target rcu_node's lock. |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 448 | * Returns true if there were tasks blocking the current RCU grace |
| 449 | * period. |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 450 | * |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 451 | * Returns 1 if there was previously a task blocking the current grace |
| 452 | * period on the specified rcu_node structure. |
| 453 | * |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 454 | * The caller must hold rnp->lock with irqs disabled. |
| 455 | */ |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 456 | static int rcu_preempt_offline_tasks(struct rcu_state *rsp, |
| 457 | struct rcu_node *rnp, |
| 458 | struct rcu_data *rdp) |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 459 | { |
| 460 | int i; |
| 461 | struct list_head *lp; |
| 462 | struct list_head *lp_root; |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 463 | int retval = 0; |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 464 | struct rcu_node *rnp_root = rcu_get_root(rsp); |
| 465 | struct task_struct *tp; |
| 466 | |
Paul E. McKenney | 8684896 | 2009-08-27 15:00:12 -0700 | [diff] [blame] | 467 | if (rnp == rnp_root) { |
| 468 | WARN_ONCE(1, "Last CPU thought to be offlined?"); |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 469 | return 0; /* Shouldn't happen: at least one CPU online. */ |
Paul E. McKenney | 8684896 | 2009-08-27 15:00:12 -0700 | [diff] [blame] | 470 | } |
Paul E. McKenney | 28ecd58 | 2009-09-18 09:50:17 -0700 | [diff] [blame] | 471 | WARN_ON_ONCE(rnp != rdp->mynode && |
| 472 | (!list_empty(&rnp->blocked_tasks[0]) || |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 473 | !list_empty(&rnp->blocked_tasks[1]) || |
| 474 | !list_empty(&rnp->blocked_tasks[2]) || |
| 475 | !list_empty(&rnp->blocked_tasks[3]))); |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 476 | |
| 477 | /* |
| 478 | * Move tasks up to root rcu_node. Rely on the fact that the |
| 479 | * root rcu_node can be at most one ahead of the rest of the |
| 480 | * rcu_nodes in terms of gp_num value. This fact allows us to |
| 481 | * move the blocked_tasks[] array directly, element by element. |
| 482 | */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 483 | if (rcu_preempted_readers(rnp)) |
| 484 | retval |= RCU_OFL_TASKS_NORM_GP; |
| 485 | if (rcu_preempted_readers_exp(rnp)) |
| 486 | retval |= RCU_OFL_TASKS_EXP_GP; |
| 487 | for (i = 0; i < 4; i++) { |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 488 | lp = &rnp->blocked_tasks[i]; |
| 489 | lp_root = &rnp_root->blocked_tasks[i]; |
| 490 | while (!list_empty(lp)) { |
| 491 | tp = list_entry(lp->next, typeof(*tp), rcu_node_entry); |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 492 | raw_spin_lock(&rnp_root->lock); /* irqs already disabled */ |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 493 | list_del(&tp->rcu_node_entry); |
| 494 | tp->rcu_blocked_node = rnp_root; |
| 495 | list_add(&tp->rcu_node_entry, lp_root); |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 496 | raw_spin_unlock(&rnp_root->lock); /* irqs remain disabled */ |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 499 | return retval; |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /* |
Paul E. McKenney | 33f7614 | 2009-08-24 09:42:01 -0700 | [diff] [blame] | 503 | * Do CPU-offline processing for preemptable RCU. |
| 504 | */ |
| 505 | static void rcu_preempt_offline_cpu(int cpu) |
| 506 | { |
| 507 | __rcu_offline_cpu(cpu, &rcu_preempt_state); |
| 508 | } |
| 509 | |
| 510 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ |
| 511 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 512 | /* |
| 513 | * Check for a quiescent state from the current CPU. When a task blocks, |
| 514 | * the task is recorded in the corresponding CPU's rcu_node structure, |
| 515 | * which is checked elsewhere. |
| 516 | * |
| 517 | * Caller must disable hard irqs. |
| 518 | */ |
| 519 | static void rcu_preempt_check_callbacks(int cpu) |
| 520 | { |
| 521 | struct task_struct *t = current; |
| 522 | |
| 523 | if (t->rcu_read_lock_nesting == 0) { |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 524 | rcu_preempt_qs(cpu); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 525 | return; |
| 526 | } |
Paul E. McKenney | a71fca5 | 2009-09-18 10:28:19 -0700 | [diff] [blame] | 527 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 528 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* |
| 532 | * Process callbacks for preemptable RCU. |
| 533 | */ |
| 534 | static void rcu_preempt_process_callbacks(void) |
| 535 | { |
| 536 | __rcu_process_callbacks(&rcu_preempt_state, |
| 537 | &__get_cpu_var(rcu_preempt_data)); |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Queue a preemptable-RCU callback for invocation after a grace period. |
| 542 | */ |
| 543 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
| 544 | { |
| 545 | __call_rcu(head, func, &rcu_preempt_state); |
| 546 | } |
| 547 | EXPORT_SYMBOL_GPL(call_rcu); |
| 548 | |
Paul E. McKenney | 6ebb237 | 2009-11-22 08:53:50 -0800 | [diff] [blame] | 549 | /** |
| 550 | * synchronize_rcu - wait until a grace period has elapsed. |
| 551 | * |
| 552 | * Control will return to the caller some time after a full grace |
| 553 | * period has elapsed, in other words after all currently executing RCU |
Paul E. McKenney | 77d8485 | 2010-07-08 17:38:59 -0700 | [diff] [blame] | 554 | * read-side critical sections have completed. Note, however, that |
| 555 | * upon return from synchronize_rcu(), the caller might well be executing |
| 556 | * concurrently with new RCU read-side critical sections that began while |
| 557 | * synchronize_rcu() was waiting. RCU read-side critical sections are |
| 558 | * delimited by rcu_read_lock() and rcu_read_unlock(), and may be nested. |
Paul E. McKenney | 6ebb237 | 2009-11-22 08:53:50 -0800 | [diff] [blame] | 559 | */ |
| 560 | void synchronize_rcu(void) |
| 561 | { |
| 562 | struct rcu_synchronize rcu; |
| 563 | |
| 564 | if (!rcu_scheduler_active) |
| 565 | return; |
| 566 | |
Paul E. McKenney | 72d5a9f | 2010-05-10 17:12:17 -0700 | [diff] [blame] | 567 | init_rcu_head_on_stack(&rcu.head); |
Paul E. McKenney | 6ebb237 | 2009-11-22 08:53:50 -0800 | [diff] [blame] | 568 | init_completion(&rcu.completion); |
| 569 | /* Will wake me after RCU finished. */ |
| 570 | call_rcu(&rcu.head, wakeme_after_rcu); |
| 571 | /* Wait for it. */ |
| 572 | wait_for_completion(&rcu.completion); |
Paul E. McKenney | 72d5a9f | 2010-05-10 17:12:17 -0700 | [diff] [blame] | 573 | destroy_rcu_head_on_stack(&rcu.head); |
Paul E. McKenney | 6ebb237 | 2009-11-22 08:53:50 -0800 | [diff] [blame] | 574 | } |
| 575 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
| 576 | |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 577 | static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq); |
| 578 | static long sync_rcu_preempt_exp_count; |
| 579 | static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex); |
| 580 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 581 | /* |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 582 | * Return non-zero if there are any tasks in RCU read-side critical |
| 583 | * sections blocking the current preemptible-RCU expedited grace period. |
| 584 | * If there is no preemptible-RCU expedited grace period currently in |
| 585 | * progress, returns zero unconditionally. |
| 586 | */ |
| 587 | static int rcu_preempted_readers_exp(struct rcu_node *rnp) |
| 588 | { |
| 589 | return !list_empty(&rnp->blocked_tasks[2]) || |
| 590 | !list_empty(&rnp->blocked_tasks[3]); |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * return non-zero if there is no RCU expedited grace period in progress |
| 595 | * for the specified rcu_node structure, in other words, if all CPUs and |
| 596 | * tasks covered by the specified rcu_node structure have done their bit |
| 597 | * for the current expedited grace period. Works only for preemptible |
| 598 | * RCU -- other RCU implementation use other means. |
| 599 | * |
| 600 | * Caller must hold sync_rcu_preempt_exp_mutex. |
| 601 | */ |
| 602 | static int sync_rcu_preempt_exp_done(struct rcu_node *rnp) |
| 603 | { |
| 604 | return !rcu_preempted_readers_exp(rnp) && |
| 605 | ACCESS_ONCE(rnp->expmask) == 0; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Report the exit from RCU read-side critical section for the last task |
| 610 | * that queued itself during or before the current expedited preemptible-RCU |
| 611 | * grace period. This event is reported either to the rcu_node structure on |
| 612 | * which the task was queued or to one of that rcu_node structure's ancestors, |
| 613 | * recursively up the tree. (Calm down, calm down, we do the recursion |
| 614 | * iteratively!) |
| 615 | * |
| 616 | * Caller must hold sync_rcu_preempt_exp_mutex. |
| 617 | */ |
| 618 | static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) |
| 619 | { |
| 620 | unsigned long flags; |
| 621 | unsigned long mask; |
| 622 | |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 623 | raw_spin_lock_irqsave(&rnp->lock, flags); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 624 | for (;;) { |
| 625 | if (!sync_rcu_preempt_exp_done(rnp)) |
| 626 | break; |
| 627 | if (rnp->parent == NULL) { |
| 628 | wake_up(&sync_rcu_preempt_exp_wq); |
| 629 | break; |
| 630 | } |
| 631 | mask = rnp->grpmask; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 632 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 633 | rnp = rnp->parent; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 634 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 635 | rnp->expmask &= ~mask; |
| 636 | } |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 637 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /* |
| 641 | * Snapshot the tasks blocking the newly started preemptible-RCU expedited |
| 642 | * grace period for the specified rcu_node structure. If there are no such |
| 643 | * tasks, report it up the rcu_node hierarchy. |
| 644 | * |
| 645 | * Caller must hold sync_rcu_preempt_exp_mutex and rsp->onofflock. |
| 646 | */ |
| 647 | static void |
| 648 | sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp) |
| 649 | { |
| 650 | int must_wait; |
| 651 | |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 652 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 653 | list_splice_init(&rnp->blocked_tasks[0], &rnp->blocked_tasks[2]); |
| 654 | list_splice_init(&rnp->blocked_tasks[1], &rnp->blocked_tasks[3]); |
| 655 | must_wait = rcu_preempted_readers_exp(rnp); |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 656 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 657 | if (!must_wait) |
| 658 | rcu_report_exp_rnp(rsp, rnp); |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * Wait for an rcu-preempt grace period, but expedite it. The basic idea |
| 663 | * is to invoke synchronize_sched_expedited() to push all the tasks to |
| 664 | * the ->blocked_tasks[] lists, move all entries from the first set of |
| 665 | * ->blocked_tasks[] lists to the second set, and finally wait for this |
| 666 | * second set to drain. |
Paul E. McKenney | 019129d | 2009-10-14 10:15:56 -0700 | [diff] [blame] | 667 | */ |
| 668 | void synchronize_rcu_expedited(void) |
| 669 | { |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 670 | unsigned long flags; |
| 671 | struct rcu_node *rnp; |
| 672 | struct rcu_state *rsp = &rcu_preempt_state; |
| 673 | long snap; |
| 674 | int trycount = 0; |
| 675 | |
| 676 | smp_mb(); /* Caller's modifications seen first by other CPUs. */ |
| 677 | snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1; |
| 678 | smp_mb(); /* Above access cannot bleed into critical section. */ |
| 679 | |
| 680 | /* |
| 681 | * Acquire lock, falling back to synchronize_rcu() if too many |
| 682 | * lock-acquisition failures. Of course, if someone does the |
| 683 | * expedited grace period for us, just leave. |
| 684 | */ |
| 685 | while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) { |
| 686 | if (trycount++ < 10) |
| 687 | udelay(trycount * num_online_cpus()); |
| 688 | else { |
| 689 | synchronize_rcu(); |
| 690 | return; |
| 691 | } |
| 692 | if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0) |
| 693 | goto mb_ret; /* Others did our work for us. */ |
| 694 | } |
| 695 | if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0) |
| 696 | goto unlock_mb_ret; /* Others did our work for us. */ |
| 697 | |
| 698 | /* force all RCU readers onto blocked_tasks[]. */ |
| 699 | synchronize_sched_expedited(); |
| 700 | |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 701 | raw_spin_lock_irqsave(&rsp->onofflock, flags); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 702 | |
| 703 | /* Initialize ->expmask for all non-leaf rcu_node structures. */ |
| 704 | rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) { |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 705 | raw_spin_lock(&rnp->lock); /* irqs already disabled. */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 706 | rnp->expmask = rnp->qsmaskinit; |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 707 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* Snapshot current state of ->blocked_tasks[] lists. */ |
| 711 | rcu_for_each_leaf_node(rsp, rnp) |
| 712 | sync_rcu_preempt_exp_init(rsp, rnp); |
| 713 | if (NUM_RCU_NODES > 1) |
| 714 | sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp)); |
| 715 | |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 716 | raw_spin_unlock_irqrestore(&rsp->onofflock, flags); |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 717 | |
| 718 | /* Wait for snapshotted ->blocked_tasks[] lists to drain. */ |
| 719 | rnp = rcu_get_root(rsp); |
| 720 | wait_event(sync_rcu_preempt_exp_wq, |
| 721 | sync_rcu_preempt_exp_done(rnp)); |
| 722 | |
| 723 | /* Clean up and exit. */ |
| 724 | smp_mb(); /* ensure expedited GP seen before counter increment. */ |
| 725 | ACCESS_ONCE(sync_rcu_preempt_exp_count)++; |
| 726 | unlock_mb_ret: |
| 727 | mutex_unlock(&sync_rcu_preempt_exp_mutex); |
| 728 | mb_ret: |
| 729 | smp_mb(); /* ensure subsequent action seen after grace period. */ |
Paul E. McKenney | 019129d | 2009-10-14 10:15:56 -0700 | [diff] [blame] | 730 | } |
| 731 | EXPORT_SYMBOL_GPL(synchronize_rcu_expedited); |
| 732 | |
| 733 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 734 | * Check to see if there is any immediate preemptable-RCU-related work |
| 735 | * to be done. |
| 736 | */ |
| 737 | static int rcu_preempt_pending(int cpu) |
| 738 | { |
| 739 | return __rcu_pending(&rcu_preempt_state, |
| 740 | &per_cpu(rcu_preempt_data, cpu)); |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | * Does preemptable RCU need the CPU to stay out of dynticks mode? |
| 745 | */ |
| 746 | static int rcu_preempt_needs_cpu(int cpu) |
| 747 | { |
| 748 | return !!per_cpu(rcu_preempt_data, cpu).nxtlist; |
| 749 | } |
| 750 | |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 751 | /** |
| 752 | * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete. |
| 753 | */ |
| 754 | void rcu_barrier(void) |
| 755 | { |
| 756 | _rcu_barrier(&rcu_preempt_state, call_rcu); |
| 757 | } |
| 758 | EXPORT_SYMBOL_GPL(rcu_barrier); |
| 759 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 760 | /* |
| 761 | * Initialize preemptable RCU's per-CPU data. |
| 762 | */ |
| 763 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) |
| 764 | { |
| 765 | rcu_init_percpu_data(cpu, &rcu_preempt_state, 1); |
| 766 | } |
| 767 | |
| 768 | /* |
Paul E. McKenney | 2d999e0 | 2010-10-20 12:06:18 -0700 | [diff] [blame] | 769 | * Move preemptable RCU's callbacks from dying CPU to other online CPU. |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 770 | */ |
Lai Jiangshan | 29494be | 2010-10-20 14:13:06 +0800 | [diff] [blame] | 771 | static void rcu_preempt_send_cbs_to_online(void) |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 772 | { |
Lai Jiangshan | 29494be | 2010-10-20 14:13:06 +0800 | [diff] [blame] | 773 | rcu_send_cbs_to_online(&rcu_preempt_state); |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 777 | * Initialize preemptable RCU's state structures. |
| 778 | */ |
| 779 | static void __init __rcu_init_preempt(void) |
| 780 | { |
Lai Jiangshan | 394f99a | 2010-06-28 16:25:04 +0800 | [diff] [blame] | 781 | rcu_init_one(&rcu_preempt_state, &rcu_preempt_data); |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 785 | * Check for a task exiting while in a preemptable-RCU read-side |
| 786 | * critical section, clean up if so. No need to issue warnings, |
| 787 | * as debug_check_no_locks_held() already does this if lockdep |
| 788 | * is enabled. |
| 789 | */ |
| 790 | void exit_rcu(void) |
| 791 | { |
| 792 | struct task_struct *t = current; |
| 793 | |
| 794 | if (t->rcu_read_lock_nesting == 0) |
| 795 | return; |
| 796 | t->rcu_read_lock_nesting = 1; |
| 797 | rcu_read_unlock(); |
| 798 | } |
| 799 | |
| 800 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ |
| 801 | |
| 802 | /* |
| 803 | * Tell them what RCU they are running. |
| 804 | */ |
Paul E. McKenney | 0e0fc1c | 2009-11-11 11:28:06 -0800 | [diff] [blame] | 805 | static void __init rcu_bootup_announce(void) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 806 | { |
| 807 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); |
Paul E. McKenney | 26845c2 | 2010-04-13 14:19:23 -0700 | [diff] [blame] | 808 | rcu_bootup_announce_oddness(); |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /* |
| 812 | * Return the number of RCU batches processed thus far for debug & stats. |
| 813 | */ |
| 814 | long rcu_batches_completed(void) |
| 815 | { |
| 816 | return rcu_batches_completed_sched(); |
| 817 | } |
| 818 | EXPORT_SYMBOL_GPL(rcu_batches_completed); |
| 819 | |
| 820 | /* |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 821 | * Force a quiescent state for RCU, which, because there is no preemptible |
| 822 | * RCU, becomes the same as rcu-sched. |
| 823 | */ |
| 824 | void rcu_force_quiescent_state(void) |
| 825 | { |
| 826 | rcu_sched_force_quiescent_state(); |
| 827 | } |
| 828 | EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); |
| 829 | |
| 830 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 831 | * Because preemptable RCU does not exist, we never have to check for |
| 832 | * CPUs being in quiescent states. |
| 833 | */ |
Paul E. McKenney | c3422be | 2009-09-13 09:15:10 -0700 | [diff] [blame] | 834 | static void rcu_preempt_note_context_switch(int cpu) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 835 | { |
| 836 | } |
| 837 | |
Paul E. McKenney | fc2219d | 2009-09-23 09:50:41 -0700 | [diff] [blame] | 838 | /* |
| 839 | * Because preemptable RCU does not exist, there are never any preempted |
| 840 | * RCU readers. |
| 841 | */ |
| 842 | static int rcu_preempted_readers(struct rcu_node *rnp) |
| 843 | { |
| 844 | return 0; |
| 845 | } |
| 846 | |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 847 | #ifdef CONFIG_HOTPLUG_CPU |
| 848 | |
| 849 | /* Because preemptible RCU does not exist, no quieting of tasks. */ |
Paul E. McKenney | d3f6bad | 2009-12-02 12:10:13 -0800 | [diff] [blame] | 850 | static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags) |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 851 | { |
Paul E. McKenney | 1304afb | 2010-02-22 17:05:02 -0800 | [diff] [blame] | 852 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
Paul E. McKenney | b668c9c | 2009-11-22 08:53:48 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ |
| 856 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 857 | /* |
| 858 | * Because preemptable RCU does not exist, we never have to check for |
| 859 | * tasks blocked within RCU read-side critical sections. |
| 860 | */ |
Paul E. McKenney | 1ed509a | 2010-02-22 17:05:05 -0800 | [diff] [blame] | 861 | static void rcu_print_detail_task_stall(struct rcu_state *rsp) |
| 862 | { |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * Because preemptable RCU does not exist, we never have to check for |
| 867 | * tasks blocked within RCU read-side critical sections. |
| 868 | */ |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 869 | static void rcu_print_task_stall(struct rcu_node *rnp) |
| 870 | { |
| 871 | } |
| 872 | |
Paul E. McKenney | 53d84e0 | 2010-08-10 14:28:53 -0700 | [diff] [blame] | 873 | /* |
| 874 | * Because preemptible RCU does not exist, there is no need to suppress |
| 875 | * its CPU stall warnings. |
| 876 | */ |
| 877 | static void rcu_preempt_stall_reset(void) |
| 878 | { |
| 879 | } |
| 880 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 881 | /* |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 882 | * Because there is no preemptable RCU, there can be no readers blocked, |
Paul E. McKenney | 49e2912 | 2009-09-18 09:50:19 -0700 | [diff] [blame] | 883 | * so there is no need to check for blocked tasks. So check only for |
| 884 | * bogus qsmask values. |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 885 | */ |
| 886 | static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) |
| 887 | { |
Paul E. McKenney | 49e2912 | 2009-09-18 09:50:19 -0700 | [diff] [blame] | 888 | WARN_ON_ONCE(rnp->qsmask); |
Paul E. McKenney | b0e165c | 2009-09-13 09:15:09 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Paul E. McKenney | 33f7614 | 2009-08-24 09:42:01 -0700 | [diff] [blame] | 891 | #ifdef CONFIG_HOTPLUG_CPU |
| 892 | |
| 893 | /* |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 894 | * Because preemptable RCU does not exist, it never needs to migrate |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 895 | * tasks that were blocked within RCU read-side critical sections, and |
| 896 | * such non-existent tasks cannot possibly have been blocking the current |
| 897 | * grace period. |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 898 | */ |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 899 | static int rcu_preempt_offline_tasks(struct rcu_state *rsp, |
| 900 | struct rcu_node *rnp, |
| 901 | struct rcu_data *rdp) |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 902 | { |
Paul E. McKenney | 237c80c | 2009-10-15 09:26:14 -0700 | [diff] [blame] | 903 | return 0; |
Paul E. McKenney | dd5d19b | 2009-08-27 14:58:16 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /* |
Paul E. McKenney | 33f7614 | 2009-08-24 09:42:01 -0700 | [diff] [blame] | 907 | * Because preemptable RCU does not exist, it never needs CPU-offline |
| 908 | * processing. |
| 909 | */ |
| 910 | static void rcu_preempt_offline_cpu(int cpu) |
| 911 | { |
| 912 | } |
| 913 | |
| 914 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ |
| 915 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 916 | /* |
| 917 | * Because preemptable RCU does not exist, it never has any callbacks |
| 918 | * to check. |
| 919 | */ |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 920 | static void rcu_preempt_check_callbacks(int cpu) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 921 | { |
| 922 | } |
| 923 | |
| 924 | /* |
| 925 | * Because preemptable RCU does not exist, it never has any callbacks |
| 926 | * to process. |
| 927 | */ |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 928 | static void rcu_preempt_process_callbacks(void) |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 929 | { |
| 930 | } |
| 931 | |
| 932 | /* |
Paul E. McKenney | 019129d | 2009-10-14 10:15:56 -0700 | [diff] [blame] | 933 | * Wait for an rcu-preempt grace period, but make it happen quickly. |
| 934 | * But because preemptable RCU does not exist, map to rcu-sched. |
| 935 | */ |
| 936 | void synchronize_rcu_expedited(void) |
| 937 | { |
| 938 | synchronize_sched_expedited(); |
| 939 | } |
| 940 | EXPORT_SYMBOL_GPL(synchronize_rcu_expedited); |
| 941 | |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 942 | #ifdef CONFIG_HOTPLUG_CPU |
| 943 | |
| 944 | /* |
| 945 | * Because preemptable RCU does not exist, there is never any need to |
| 946 | * report on tasks preempted in RCU read-side critical sections during |
| 947 | * expedited RCU grace periods. |
| 948 | */ |
| 949 | static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) |
| 950 | { |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ |
| 955 | |
Paul E. McKenney | 019129d | 2009-10-14 10:15:56 -0700 | [diff] [blame] | 956 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 957 | * Because preemptable RCU does not exist, it never has any work to do. |
| 958 | */ |
| 959 | static int rcu_preempt_pending(int cpu) |
| 960 | { |
| 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | * Because preemptable RCU does not exist, it never needs any CPU. |
| 966 | */ |
| 967 | static int rcu_preempt_needs_cpu(int cpu) |
| 968 | { |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | /* |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 973 | * Because preemptable RCU does not exist, rcu_barrier() is just |
| 974 | * another name for rcu_barrier_sched(). |
| 975 | */ |
| 976 | void rcu_barrier(void) |
| 977 | { |
| 978 | rcu_barrier_sched(); |
| 979 | } |
| 980 | EXPORT_SYMBOL_GPL(rcu_barrier); |
| 981 | |
| 982 | /* |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 983 | * Because preemptable RCU does not exist, there is no per-CPU |
| 984 | * data to initialize. |
| 985 | */ |
| 986 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) |
| 987 | { |
| 988 | } |
| 989 | |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 990 | /* |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 991 | * Because there is no preemptable RCU, there are no callbacks to move. |
| 992 | */ |
Lai Jiangshan | 29494be | 2010-10-20 14:13:06 +0800 | [diff] [blame] | 993 | static void rcu_preempt_send_cbs_to_online(void) |
Paul E. McKenney | e74f4c4 | 2009-10-06 21:48:17 -0700 | [diff] [blame] | 994 | { |
| 995 | } |
| 996 | |
| 997 | /* |
Paul E. McKenney | 1eba8f8 | 2009-09-23 09:50:42 -0700 | [diff] [blame] | 998 | * Because preemptable RCU does not exist, it need not be initialized. |
| 999 | */ |
| 1000 | static void __init __rcu_init_preempt(void) |
| 1001 | { |
| 1002 | } |
| 1003 | |
Paul E. McKenney | f41d911 | 2009-08-22 13:56:52 -0700 | [diff] [blame] | 1004 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1005 | |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1006 | #ifndef CONFIG_SMP |
| 1007 | |
| 1008 | void synchronize_sched_expedited(void) |
| 1009 | { |
| 1010 | cond_resched(); |
| 1011 | } |
| 1012 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
| 1013 | |
| 1014 | #else /* #ifndef CONFIG_SMP */ |
| 1015 | |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1016 | static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0); |
| 1017 | static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0); |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1018 | |
| 1019 | static int synchronize_sched_expedited_cpu_stop(void *data) |
| 1020 | { |
| 1021 | /* |
| 1022 | * There must be a full memory barrier on each affected CPU |
| 1023 | * between the time that try_stop_cpus() is called and the |
| 1024 | * time that it returns. |
| 1025 | * |
| 1026 | * In the current initial implementation of cpu_stop, the |
| 1027 | * above condition is already met when the control reaches |
| 1028 | * this point and the following smp_mb() is not strictly |
| 1029 | * necessary. Do smp_mb() anyway for documentation and |
| 1030 | * robustness against future implementation changes. |
| 1031 | */ |
| 1032 | smp_mb(); /* See above comment block. */ |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" |
| 1038 | * approach to force grace period to end quickly. This consumes |
| 1039 | * significant time on all CPUs, and is thus not recommended for |
| 1040 | * any sort of common-case code. |
| 1041 | * |
| 1042 | * Note that it is illegal to call this function while holding any |
| 1043 | * lock that is acquired by a CPU-hotplug notifier. Failing to |
| 1044 | * observe this restriction will result in deadlock. |
Paul E. McKenney | db3a892 | 2010-10-25 07:39:22 -0700 | [diff] [blame] | 1045 | * |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1046 | * This implementation can be thought of as an application of ticket |
| 1047 | * locking to RCU, with sync_sched_expedited_started and |
| 1048 | * sync_sched_expedited_done taking on the roles of the halves |
| 1049 | * of the ticket-lock word. Each task atomically increments |
| 1050 | * sync_sched_expedited_started upon entry, snapshotting the old value, |
| 1051 | * then attempts to stop all the CPUs. If this succeeds, then each |
| 1052 | * CPU will have executed a context switch, resulting in an RCU-sched |
| 1053 | * grace period. We are then done, so we use atomic_cmpxchg() to |
| 1054 | * update sync_sched_expedited_done to match our snapshot -- but |
| 1055 | * only if someone else has not already advanced past our snapshot. |
| 1056 | * |
| 1057 | * On the other hand, if try_stop_cpus() fails, we check the value |
| 1058 | * of sync_sched_expedited_done. If it has advanced past our |
| 1059 | * initial snapshot, then someone else must have forced a grace period |
| 1060 | * some time after we took our snapshot. In this case, our work is |
| 1061 | * done for us, and we can simply return. Otherwise, we try again, |
| 1062 | * but keep our initial snapshot for purposes of checking for someone |
| 1063 | * doing our work for us. |
| 1064 | * |
| 1065 | * If we fail too many times in a row, we fall back to synchronize_sched(). |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1066 | */ |
| 1067 | void synchronize_sched_expedited(void) |
| 1068 | { |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1069 | int firstsnap, s, snap, trycount = 0; |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1070 | |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1071 | /* Note that atomic_inc_return() implies full memory barrier. */ |
| 1072 | firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started); |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1073 | get_online_cpus(); |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1074 | |
| 1075 | /* |
| 1076 | * Each pass through the following loop attempts to force a |
| 1077 | * context switch on each CPU. |
| 1078 | */ |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1079 | while (try_stop_cpus(cpu_online_mask, |
| 1080 | synchronize_sched_expedited_cpu_stop, |
| 1081 | NULL) == -EAGAIN) { |
| 1082 | put_online_cpus(); |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1083 | |
| 1084 | /* No joy, try again later. Or just synchronize_sched(). */ |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1085 | if (trycount++ < 10) |
| 1086 | udelay(trycount * num_online_cpus()); |
| 1087 | else { |
| 1088 | synchronize_sched(); |
| 1089 | return; |
| 1090 | } |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1091 | |
| 1092 | /* Check to see if someone else did our work for us. */ |
| 1093 | s = atomic_read(&sync_sched_expedited_done); |
| 1094 | if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) { |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1095 | smp_mb(); /* ensure test happens before caller kfree */ |
| 1096 | return; |
| 1097 | } |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * Refetching sync_sched_expedited_started allows later |
| 1101 | * callers to piggyback on our grace period. We subtract |
| 1102 | * 1 to get the same token that the last incrementer got. |
| 1103 | * We retry after they started, so our grace period works |
| 1104 | * for them, and they started after our first try, so their |
| 1105 | * grace period works for us. |
| 1106 | */ |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1107 | get_online_cpus(); |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1108 | snap = atomic_read(&sync_sched_expedited_started) - 1; |
| 1109 | smp_mb(); /* ensure read is before try_stop_cpus(). */ |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1110 | } |
Tejun Heo | e27fc96 | 2010-11-22 21:36:11 -0800 | [diff] [blame] | 1111 | |
| 1112 | /* |
| 1113 | * Everyone up to our most recent fetch is covered by our grace |
| 1114 | * period. Update the counter, but only if our work is still |
| 1115 | * relevant -- which it won't be if someone who started later |
| 1116 | * than we did beat us to the punch. |
| 1117 | */ |
| 1118 | do { |
| 1119 | s = atomic_read(&sync_sched_expedited_done); |
| 1120 | if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) { |
| 1121 | smp_mb(); /* ensure test happens before caller kfree */ |
| 1122 | break; |
| 1123 | } |
| 1124 | } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s); |
| 1125 | |
Lai Jiangshan | 7b27d54 | 2010-10-21 11:29:05 +0800 | [diff] [blame] | 1126 | put_online_cpus(); |
| 1127 | } |
| 1128 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
| 1129 | |
| 1130 | #endif /* #else #ifndef CONFIG_SMP */ |
| 1131 | |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1132 | #if !defined(CONFIG_RCU_FAST_NO_HZ) |
| 1133 | |
| 1134 | /* |
| 1135 | * Check to see if any future RCU-related work will need to be done |
| 1136 | * by the current CPU, even if none need be done immediately, returning |
| 1137 | * 1 if so. This function is part of the RCU implementation; it is -not- |
| 1138 | * an exported member of the RCU API. |
| 1139 | * |
| 1140 | * Because we have preemptible RCU, just check whether this CPU needs |
| 1141 | * any flavor of RCU. Do not chew up lots of CPU cycles with preemption |
| 1142 | * disabled in a most-likely vain attempt to cause RCU not to need this CPU. |
| 1143 | */ |
| 1144 | int rcu_needs_cpu(int cpu) |
| 1145 | { |
| 1146 | return rcu_needs_cpu_quick_check(cpu); |
| 1147 | } |
| 1148 | |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1149 | /* |
| 1150 | * Check to see if we need to continue a callback-flush operations to |
| 1151 | * allow the last CPU to enter dyntick-idle mode. But fast dyntick-idle |
| 1152 | * entry is not configured, so we never do need to. |
| 1153 | */ |
| 1154 | static void rcu_needs_cpu_flush(void) |
| 1155 | { |
| 1156 | } |
| 1157 | |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1158 | #else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */ |
| 1159 | |
| 1160 | #define RCU_NEEDS_CPU_FLUSHES 5 |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1161 | static DEFINE_PER_CPU(int, rcu_dyntick_drain); |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1162 | static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff); |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * Check to see if any future RCU-related work will need to be done |
| 1166 | * by the current CPU, even if none need be done immediately, returning |
| 1167 | * 1 if so. This function is part of the RCU implementation; it is -not- |
| 1168 | * an exported member of the RCU API. |
| 1169 | * |
| 1170 | * Because we are not supporting preemptible RCU, attempt to accelerate |
| 1171 | * any current grace periods so that RCU no longer needs this CPU, but |
| 1172 | * only if all other CPUs are already in dynticks-idle mode. This will |
| 1173 | * allow the CPU cores to be powered down immediately, as opposed to after |
| 1174 | * waiting many milliseconds for grace periods to elapse. |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1175 | * |
| 1176 | * Because it is not legal to invoke rcu_process_callbacks() with irqs |
| 1177 | * disabled, we do one pass of force_quiescent_state(), then do a |
| 1178 | * raise_softirq() to cause rcu_process_callbacks() to be invoked later. |
| 1179 | * The per-cpu rcu_dyntick_drain variable controls the sequencing. |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1180 | */ |
| 1181 | int rcu_needs_cpu(int cpu) |
| 1182 | { |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1183 | int c = 0; |
Paul E. McKenney | 77e38ed | 2010-04-25 21:04:29 -0700 | [diff] [blame] | 1184 | int snap; |
| 1185 | int snap_nmi; |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1186 | int thatcpu; |
| 1187 | |
Paul E. McKenney | 622ea68 | 2010-02-27 14:53:07 -0800 | [diff] [blame] | 1188 | /* Check for being in the holdoff period. */ |
| 1189 | if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies) |
| 1190 | return rcu_needs_cpu_quick_check(cpu); |
| 1191 | |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1192 | /* Don't bother unless we are the last non-dyntick-idle CPU. */ |
Paul E. McKenney | 77e38ed | 2010-04-25 21:04:29 -0700 | [diff] [blame] | 1193 | for_each_online_cpu(thatcpu) { |
| 1194 | if (thatcpu == cpu) |
| 1195 | continue; |
Paul E. McKenney | d822ed1 | 2010-05-08 19:58:22 -0700 | [diff] [blame] | 1196 | snap = per_cpu(rcu_dynticks, thatcpu).dynticks; |
| 1197 | snap_nmi = per_cpu(rcu_dynticks, thatcpu).dynticks_nmi; |
Paul E. McKenney | 77e38ed | 2010-04-25 21:04:29 -0700 | [diff] [blame] | 1198 | smp_mb(); /* Order sampling of snap with end of grace period. */ |
| 1199 | if (((snap & 0x1) != 0) || ((snap_nmi & 0x1) != 0)) { |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1200 | per_cpu(rcu_dyntick_drain, cpu) = 0; |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1201 | per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1; |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1202 | return rcu_needs_cpu_quick_check(cpu); |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1203 | } |
Paul E. McKenney | 77e38ed | 2010-04-25 21:04:29 -0700 | [diff] [blame] | 1204 | } |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1205 | |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1206 | /* Check and update the rcu_dyntick_drain sequencing. */ |
| 1207 | if (per_cpu(rcu_dyntick_drain, cpu) <= 0) { |
| 1208 | /* First time through, initialize the counter. */ |
| 1209 | per_cpu(rcu_dyntick_drain, cpu) = RCU_NEEDS_CPU_FLUSHES; |
| 1210 | } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) { |
| 1211 | /* We have hit the limit, so time to give up. */ |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1212 | per_cpu(rcu_dyntick_holdoff, cpu) = jiffies; |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1213 | return rcu_needs_cpu_quick_check(cpu); |
| 1214 | } |
| 1215 | |
| 1216 | /* Do one step pushing remaining RCU callbacks through. */ |
| 1217 | if (per_cpu(rcu_sched_data, cpu).nxtlist) { |
| 1218 | rcu_sched_qs(cpu); |
| 1219 | force_quiescent_state(&rcu_sched_state, 0); |
| 1220 | c = c || per_cpu(rcu_sched_data, cpu).nxtlist; |
| 1221 | } |
| 1222 | if (per_cpu(rcu_bh_data, cpu).nxtlist) { |
| 1223 | rcu_bh_qs(cpu); |
| 1224 | force_quiescent_state(&rcu_bh_state, 0); |
| 1225 | c = c || per_cpu(rcu_bh_data, cpu).nxtlist; |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* If RCU callbacks are still pending, RCU still needs this CPU. */ |
Paul E. McKenney | 622ea68 | 2010-02-27 14:53:07 -0800 | [diff] [blame] | 1229 | if (c) |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1230 | raise_softirq(RCU_SOFTIRQ); |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1231 | return c; |
| 1232 | } |
| 1233 | |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1234 | /* |
| 1235 | * Check to see if we need to continue a callback-flush operations to |
| 1236 | * allow the last CPU to enter dyntick-idle mode. |
| 1237 | */ |
| 1238 | static void rcu_needs_cpu_flush(void) |
| 1239 | { |
| 1240 | int cpu = smp_processor_id(); |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1241 | unsigned long flags; |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1242 | |
| 1243 | if (per_cpu(rcu_dyntick_drain, cpu) <= 0) |
| 1244 | return; |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1245 | local_irq_save(flags); |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1246 | (void)rcu_needs_cpu(cpu); |
Paul E. McKenney | 71da813 | 2010-02-26 16:38:58 -0800 | [diff] [blame] | 1247 | local_irq_restore(flags); |
Paul E. McKenney | a47cd88 | 2010-02-26 16:38:56 -0800 | [diff] [blame] | 1248 | } |
| 1249 | |
Paul E. McKenney | 8bd93a2 | 2010-02-22 17:04:59 -0800 | [diff] [blame] | 1250 | #endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */ |