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