Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Read-Copy Update definitions shared among RCU implementations. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Paul E. McKenney | 87de1cf | 2013-12-03 10:02:52 -0800 | [diff] [blame] | 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 17 | * |
| 18 | * Copyright IBM Corporation, 2011 |
| 19 | * |
| 20 | * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> |
| 21 | */ |
| 22 | |
| 23 | #ifndef __LINUX_RCU_H |
| 24 | #define __LINUX_RCU_H |
| 25 | |
Paul Gortmaker | 5cb5c6e | 2014-02-19 14:33:27 -0500 | [diff] [blame] | 26 | #include <trace/events/rcu.h> |
Paul E. McKenney | e99033c | 2011-06-21 00:13:44 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_RCU_TRACE |
| 28 | #define RCU_TRACE(stmt) stmt |
| 29 | #else /* #ifdef CONFIG_RCU_TRACE */ |
| 30 | #define RCU_TRACE(stmt) |
| 31 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ |
| 32 | |
Paul E. McKenney | 51a1fd3 | 2017-10-03 14:43:40 -0700 | [diff] [blame] | 33 | /* Offset to allow for unmatched rcu_irq_{enter,exit}(). */ |
Paul E. McKenney | 84585aa | 2017-10-04 15:55:16 -0700 | [diff] [blame] | 34 | #define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) |
Paul E. McKenney | 6136d6e | 2017-10-03 08:28:04 -0700 | [diff] [blame] | 35 | |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Grace-period counter management. |
| 39 | */ |
| 40 | |
Paul E. McKenney | f1ec57a | 2017-03-21 10:35:57 -0700 | [diff] [blame] | 41 | #define RCU_SEQ_CTR_SHIFT 2 |
Paul E. McKenney | 031aeee | 2017-03-21 07:28:14 -0700 | [diff] [blame] | 42 | #define RCU_SEQ_STATE_MASK ((1 << RCU_SEQ_CTR_SHIFT) - 1) |
| 43 | |
| 44 | /* |
| 45 | * Return the counter portion of a sequence number previously returned |
| 46 | * by rcu_seq_snap() or rcu_seq_current(). |
| 47 | */ |
| 48 | static inline unsigned long rcu_seq_ctr(unsigned long s) |
| 49 | { |
| 50 | return s >> RCU_SEQ_CTR_SHIFT; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Return the state portion of a sequence number previously returned |
| 55 | * by rcu_seq_snap() or rcu_seq_current(). |
| 56 | */ |
| 57 | static inline int rcu_seq_state(unsigned long s) |
| 58 | { |
| 59 | return s & RCU_SEQ_STATE_MASK; |
| 60 | } |
| 61 | |
Paul E. McKenney | 80a7956 | 2017-03-22 15:26:18 -0700 | [diff] [blame] | 62 | /* |
| 63 | * Set the state portion of the pointed-to sequence number. |
| 64 | * The caller is responsible for preventing conflicting updates. |
| 65 | */ |
| 66 | static inline void rcu_seq_set_state(unsigned long *sp, int newstate) |
| 67 | { |
| 68 | WARN_ON_ONCE(newstate & ~RCU_SEQ_STATE_MASK); |
| 69 | WRITE_ONCE(*sp, (*sp & ~RCU_SEQ_STATE_MASK) + newstate); |
| 70 | } |
| 71 | |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 72 | /* Adjust sequence number for start of update-side operation. */ |
| 73 | static inline void rcu_seq_start(unsigned long *sp) |
| 74 | { |
| 75 | WRITE_ONCE(*sp, *sp + 1); |
| 76 | smp_mb(); /* Ensure update-side operation after counter increment. */ |
Paul E. McKenney | 031aeee | 2017-03-21 07:28:14 -0700 | [diff] [blame] | 77 | WARN_ON_ONCE(rcu_seq_state(*sp) != 1); |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Paul E. McKenney | 9a41420 | 2018-01-31 19:23:24 -0800 | [diff] [blame] | 80 | /* Compute the end-of-grace-period value for the specified sequence number. */ |
| 81 | static inline unsigned long rcu_seq_endval(unsigned long *sp) |
| 82 | { |
| 83 | return (*sp | RCU_SEQ_STATE_MASK) + 1; |
| 84 | } |
| 85 | |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 86 | /* Adjust sequence number for end of update-side operation. */ |
| 87 | static inline void rcu_seq_end(unsigned long *sp) |
| 88 | { |
| 89 | smp_mb(); /* Ensure update-side operation before counter increment. */ |
Paul E. McKenney | 031aeee | 2017-03-21 07:28:14 -0700 | [diff] [blame] | 90 | WARN_ON_ONCE(!rcu_seq_state(*sp)); |
Paul E. McKenney | 9a41420 | 2018-01-31 19:23:24 -0800 | [diff] [blame] | 91 | WRITE_ONCE(*sp, rcu_seq_endval(sp)); |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* Take a snapshot of the update side's sequence number. */ |
| 95 | static inline unsigned long rcu_seq_snap(unsigned long *sp) |
| 96 | { |
| 97 | unsigned long s; |
| 98 | |
Paul E. McKenney | 031aeee | 2017-03-21 07:28:14 -0700 | [diff] [blame] | 99 | s = (READ_ONCE(*sp) + 2 * RCU_SEQ_STATE_MASK + 1) & ~RCU_SEQ_STATE_MASK; |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 100 | smp_mb(); /* Above access must not bleed into critical section. */ |
| 101 | return s; |
| 102 | } |
| 103 | |
Paul E. McKenney | 8660b7d | 2017-03-13 16:48:18 -0700 | [diff] [blame] | 104 | /* Return the current value the update side's sequence number, no ordering. */ |
| 105 | static inline unsigned long rcu_seq_current(unsigned long *sp) |
| 106 | { |
| 107 | return READ_ONCE(*sp); |
| 108 | } |
| 109 | |
Paul E. McKenney | 2e8c28c | 2017-02-20 14:57:17 -0800 | [diff] [blame] | 110 | /* |
| 111 | * Given a snapshot from rcu_seq_snap(), determine whether or not a |
| 112 | * full update-side operation has occurred. |
| 113 | */ |
| 114 | static inline bool rcu_seq_done(unsigned long *sp, unsigned long s) |
| 115 | { |
| 116 | return ULONG_CMP_GE(READ_ONCE(*sp), s); |
| 117 | } |
| 118 | |
Paul E. McKenney | 4145fa7 | 2011-10-31 15:01:54 -0700 | [diff] [blame] | 119 | /* |
Paul E. McKenney | 67e14c1 | 2018-04-27 16:01:46 -0700 | [diff] [blame] | 120 | * Has a grace period completed since the time the old gp_seq was collected? |
| 121 | */ |
| 122 | static inline bool rcu_seq_completed_gp(unsigned long old, unsigned long new) |
| 123 | { |
| 124 | return ULONG_CMP_LT(old, new & ~RCU_SEQ_STATE_MASK); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Has a grace period started since the time the old gp_seq was collected? |
| 129 | */ |
| 130 | static inline bool rcu_seq_new_gp(unsigned long old, unsigned long new) |
| 131 | { |
| 132 | return ULONG_CMP_LT((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK, |
| 133 | new); |
| 134 | } |
| 135 | |
| 136 | /* |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 137 | * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally |
| 138 | * by call_rcu() and rcu callback execution, and are therefore not part of the |
| 139 | * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors. |
| 140 | */ |
| 141 | |
| 142 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD |
| 143 | # define STATE_RCU_HEAD_READY 0 |
| 144 | # define STATE_RCU_HEAD_QUEUED 1 |
| 145 | |
| 146 | extern struct debug_obj_descr rcuhead_debug_descr; |
| 147 | |
Paul E. McKenney | ae15018 | 2013-04-23 13:20:57 -0700 | [diff] [blame] | 148 | static inline int debug_rcu_head_queue(struct rcu_head *head) |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 149 | { |
Paul E. McKenney | ae15018 | 2013-04-23 13:20:57 -0700 | [diff] [blame] | 150 | int r1; |
| 151 | |
| 152 | r1 = debug_object_activate(head, &rcuhead_debug_descr); |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 153 | debug_object_active_state(head, &rcuhead_debug_descr, |
| 154 | STATE_RCU_HEAD_READY, |
| 155 | STATE_RCU_HEAD_QUEUED); |
Paul E. McKenney | ae15018 | 2013-04-23 13:20:57 -0700 | [diff] [blame] | 156 | return r1; |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static inline void debug_rcu_head_unqueue(struct rcu_head *head) |
| 160 | { |
| 161 | debug_object_active_state(head, &rcuhead_debug_descr, |
| 162 | STATE_RCU_HEAD_QUEUED, |
| 163 | STATE_RCU_HEAD_READY); |
| 164 | debug_object_deactivate(head, &rcuhead_debug_descr); |
| 165 | } |
| 166 | #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
Paul E. McKenney | ae15018 | 2013-04-23 13:20:57 -0700 | [diff] [blame] | 167 | static inline int debug_rcu_head_queue(struct rcu_head *head) |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 168 | { |
Paul E. McKenney | ae15018 | 2013-04-23 13:20:57 -0700 | [diff] [blame] | 169 | return 0; |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static inline void debug_rcu_head_unqueue(struct rcu_head *head) |
| 173 | { |
| 174 | } |
| 175 | #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
| 176 | |
Teodora Baluta | bd73a7f | 2013-11-11 17:11:24 +0200 | [diff] [blame] | 177 | void kfree(const void *); |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 178 | |
Paul E. McKenney | 406e3e5 | 2014-06-23 13:48:28 -0700 | [diff] [blame] | 179 | /* |
| 180 | * Reclaim the specified callback, either by invoking it (non-lazy case) |
| 181 | * or freeing it directly (lazy case). Return true if lazy, false otherwise. |
| 182 | */ |
Steven Rostedt (Red Hat) | e66c33d | 2013-07-12 16:50:28 -0400 | [diff] [blame] | 183 | static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 184 | { |
| 185 | unsigned long offset = (unsigned long)head->func; |
| 186 | |
Paul E. McKenney | 24ef659 | 2013-10-28 09:22:24 -0700 | [diff] [blame] | 187 | rcu_lock_acquire(&rcu_callback_map); |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 188 | if (__is_kfree_rcu_offset(offset)) { |
Paul E. McKenney | dffd06a | 2017-01-23 11:55:43 -0800 | [diff] [blame] | 189 | RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);) |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 190 | kfree((void *)head - offset); |
Paul E. McKenney | 24ef659 | 2013-10-28 09:22:24 -0700 | [diff] [blame] | 191 | rcu_lock_release(&rcu_callback_map); |
Paul E. McKenney | 406e3e5 | 2014-06-23 13:48:28 -0700 | [diff] [blame] | 192 | return true; |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 193 | } else { |
Paul E. McKenney | dffd06a | 2017-01-23 11:55:43 -0800 | [diff] [blame] | 194 | RCU_TRACE(trace_rcu_invoke_callback(rn, head);) |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 195 | head->func(head); |
Paul E. McKenney | 24ef659 | 2013-10-28 09:22:24 -0700 | [diff] [blame] | 196 | rcu_lock_release(&rcu_callback_map); |
Paul E. McKenney | 406e3e5 | 2014-06-23 13:48:28 -0700 | [diff] [blame] | 197 | return false; |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Paul E. McKenney | 6bfc09e | 2012-10-19 12:49:17 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_RCU_STALL_COMMON |
| 202 | |
| 203 | extern int rcu_cpu_stall_suppress; |
| 204 | int rcu_jiffies_till_stall_check(void); |
| 205 | |
Paul E. McKenney | f22ce09 | 2017-09-01 14:40:54 -0700 | [diff] [blame] | 206 | #define rcu_ftrace_dump_stall_suppress() \ |
| 207 | do { \ |
| 208 | if (!rcu_cpu_stall_suppress) \ |
| 209 | rcu_cpu_stall_suppress = 3; \ |
| 210 | } while (0) |
| 211 | |
| 212 | #define rcu_ftrace_dump_stall_unsuppress() \ |
| 213 | do { \ |
| 214 | if (rcu_cpu_stall_suppress == 3) \ |
| 215 | rcu_cpu_stall_suppress = 0; \ |
| 216 | } while (0) |
| 217 | |
| 218 | #else /* #endif #ifdef CONFIG_RCU_STALL_COMMON */ |
| 219 | #define rcu_ftrace_dump_stall_suppress() |
| 220 | #define rcu_ftrace_dump_stall_unsuppress() |
Paul E. McKenney | 6bfc09e | 2012-10-19 12:49:17 -0700 | [diff] [blame] | 221 | #endif /* #ifdef CONFIG_RCU_STALL_COMMON */ |
| 222 | |
Paul E. McKenney | 0d75292 | 2013-08-17 18:08:37 -0700 | [diff] [blame] | 223 | /* |
| 224 | * Strings used in tracepoints need to be exported via the |
| 225 | * tracing system such that tools like perf and trace-cmd can |
| 226 | * translate the string address pointers to actual text. |
| 227 | */ |
| 228 | #define TPS(x) tracepoint_string(x) |
| 229 | |
Paul E. McKenney | b8989b7 | 2017-05-03 12:28:59 -0700 | [diff] [blame] | 230 | /* |
| 231 | * Dump the ftrace buffer, but only one time per callsite per boot. |
| 232 | */ |
| 233 | #define rcu_ftrace_dump(oops_dump_mode) \ |
| 234 | do { \ |
| 235 | static atomic_t ___rfd_beenhere = ATOMIC_INIT(0); \ |
| 236 | \ |
| 237 | if (!atomic_read(&___rfd_beenhere) && \ |
Paul E. McKenney | 83b6ca1 | 2017-08-31 16:47:08 -0700 | [diff] [blame] | 238 | !atomic_xchg(&___rfd_beenhere, 1)) { \ |
| 239 | tracing_off(); \ |
Paul E. McKenney | f22ce09 | 2017-09-01 14:40:54 -0700 | [diff] [blame] | 240 | rcu_ftrace_dump_stall_suppress(); \ |
Paul E. McKenney | b8989b7 | 2017-05-03 12:28:59 -0700 | [diff] [blame] | 241 | ftrace_dump(oops_dump_mode); \ |
Paul E. McKenney | f22ce09 | 2017-09-01 14:40:54 -0700 | [diff] [blame] | 242 | rcu_ftrace_dump_stall_unsuppress(); \ |
Paul E. McKenney | 83b6ca1 | 2017-08-31 16:47:08 -0700 | [diff] [blame] | 243 | } \ |
Paul E. McKenney | b8989b7 | 2017-05-03 12:28:59 -0700 | [diff] [blame] | 244 | } while (0) |
| 245 | |
Pranith Kumar | aa23c6fbc | 2014-09-19 11:32:29 -0400 | [diff] [blame] | 246 | void rcu_early_boot_tests(void); |
Paul E. McKenney | 52d7e48 | 2017-01-10 02:28:26 -0800 | [diff] [blame] | 247 | void rcu_test_sync_prims(void); |
Pranith Kumar | aa23c6fbc | 2014-09-19 11:32:29 -0400 | [diff] [blame] | 248 | |
Lai Jiangshan | 5f6130f | 2014-12-09 17:53:34 +0800 | [diff] [blame] | 249 | /* |
| 250 | * This function really isn't for public consumption, but RCU is special in |
| 251 | * that context switches can allow the state machine to make progress. |
| 252 | */ |
| 253 | extern void resched_cpu(int cpu); |
| 254 | |
Paul E. McKenney | 2b34c43 | 2017-03-14 14:29:53 -0700 | [diff] [blame] | 255 | #if defined(SRCU) || !defined(TINY_RCU) |
| 256 | |
| 257 | #include <linux/rcu_node_tree.h> |
| 258 | |
| 259 | extern int rcu_num_lvls; |
Paul E. McKenney | e95d68d | 2017-03-15 13:11:11 -0700 | [diff] [blame] | 260 | extern int num_rcu_lvl[]; |
Paul E. McKenney | 2b34c43 | 2017-03-14 14:29:53 -0700 | [diff] [blame] | 261 | extern int rcu_num_nodes; |
| 262 | static bool rcu_fanout_exact; |
| 263 | static int rcu_fanout_leaf; |
| 264 | |
| 265 | /* |
| 266 | * Compute the per-level fanout, either using the exact fanout specified |
| 267 | * or balancing the tree, depending on the rcu_fanout_exact boot parameter. |
| 268 | */ |
| 269 | static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt) |
| 270 | { |
| 271 | int i; |
| 272 | |
| 273 | if (rcu_fanout_exact) { |
| 274 | levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf; |
| 275 | for (i = rcu_num_lvls - 2; i >= 0; i--) |
| 276 | levelspread[i] = RCU_FANOUT; |
| 277 | } else { |
| 278 | int ccur; |
| 279 | int cprv; |
| 280 | |
| 281 | cprv = nr_cpu_ids; |
| 282 | for (i = rcu_num_lvls - 1; i >= 0; i--) { |
| 283 | ccur = levelcnt[i]; |
| 284 | levelspread[i] = (cprv + ccur - 1) / ccur; |
| 285 | cprv = ccur; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
Paul E. McKenney | 5b4c11d | 2018-04-13 17:11:44 -0700 | [diff] [blame] | 290 | /* Returns first leaf rcu_node of the specified RCU flavor. */ |
| 291 | #define rcu_first_leaf_node(rsp) ((rsp)->level[rcu_num_lvls - 1]) |
| 292 | |
| 293 | /* Is this rcu_node a leaf? */ |
| 294 | #define rcu_is_leaf_node(rnp) ((rnp)->level == rcu_num_lvls - 1) |
| 295 | |
Paul E. McKenney | 5257514 | 2018-04-24 11:03:39 -0700 | [diff] [blame] | 296 | /* Is this rcu_node the last leaf? */ |
| 297 | #define rcu_is_last_leaf_node(rsp, rnp) ((rnp) == &(rsp)->node[rcu_num_nodes - 1]) |
| 298 | |
Paul E. McKenney | efbe451 | 2017-03-15 13:07:53 -0700 | [diff] [blame] | 299 | /* |
| 300 | * Do a full breadth-first scan of the rcu_node structures for the |
| 301 | * specified rcu_state structure. |
| 302 | */ |
| 303 | #define rcu_for_each_node_breadth_first(rsp, rnp) \ |
| 304 | for ((rnp) = &(rsp)->node[0]; \ |
| 305 | (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) |
| 306 | |
| 307 | /* |
| 308 | * Do a breadth-first scan of the non-leaf rcu_node structures for the |
| 309 | * specified rcu_state structure. Note that if there is a singleton |
| 310 | * rcu_node tree with but one rcu_node structure, this loop is a no-op. |
| 311 | */ |
| 312 | #define rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) \ |
Paul E. McKenney | 5b4c11d | 2018-04-13 17:11:44 -0700 | [diff] [blame] | 313 | for ((rnp) = &(rsp)->node[0]; !rcu_is_leaf_node(rsp, rnp); (rnp)++) |
Paul E. McKenney | efbe451 | 2017-03-15 13:07:53 -0700 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * Scan the leaves of the rcu_node hierarchy for the specified rcu_state |
| 317 | * structure. Note that if there is a singleton rcu_node tree with but |
| 318 | * one rcu_node structure, this loop -will- visit the rcu_node structure. |
| 319 | * It is still a leaf node, even if it is also the root node. |
| 320 | */ |
| 321 | #define rcu_for_each_leaf_node(rsp, rnp) \ |
Paul E. McKenney | 5b4c11d | 2018-04-13 17:11:44 -0700 | [diff] [blame] | 322 | for ((rnp) = rcu_first_leaf_node(rsp); \ |
Paul E. McKenney | efbe451 | 2017-03-15 13:07:53 -0700 | [diff] [blame] | 323 | (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) |
| 324 | |
| 325 | /* |
| 326 | * Iterate over all possible CPUs in a leaf RCU node. |
| 327 | */ |
| 328 | #define for_each_leaf_node_possible_cpu(rnp, cpu) \ |
Paul E. McKenney | 65963d2 | 2018-01-31 20:24:15 -0800 | [diff] [blame] | 329 | for ((cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \ |
| 330 | (cpu) <= rnp->grphi; \ |
| 331 | (cpu) = cpumask_next((cpu), cpu_possible_mask)) |
| 332 | |
| 333 | /* |
| 334 | * Iterate over all CPUs in a leaf RCU node's specified mask. |
| 335 | */ |
| 336 | #define rcu_find_next_bit(rnp, cpu, mask) \ |
| 337 | ((rnp)->grplo + find_next_bit(&(mask), BITS_PER_LONG, (cpu))) |
| 338 | #define for_each_leaf_node_cpu_mask(rnp, cpu, mask) \ |
| 339 | for ((cpu) = rcu_find_next_bit((rnp), 0, (mask)); \ |
| 340 | (cpu) <= rnp->grphi; \ |
| 341 | (cpu) = rcu_find_next_bit((rnp), (cpu) + 1 - (rnp->grplo), (mask))) |
Paul E. McKenney | efbe451 | 2017-03-15 13:07:53 -0700 | [diff] [blame] | 342 | |
Paul E. McKenney | 83d40bd | 2017-05-09 13:28:51 -0700 | [diff] [blame] | 343 | /* |
| 344 | * Wrappers for the rcu_node::lock acquire and release. |
| 345 | * |
| 346 | * Because the rcu_nodes form a tree, the tree traversal locking will observe |
| 347 | * different lock values, this in turn means that an UNLOCK of one level |
| 348 | * followed by a LOCK of another level does not imply a full memory barrier; |
| 349 | * and most importantly transitivity is lost. |
| 350 | * |
| 351 | * In order to restore full ordering between tree levels, augment the regular |
| 352 | * lock acquire functions with smp_mb__after_unlock_lock(). |
| 353 | * |
| 354 | * As ->lock of struct rcu_node is a __private field, therefore one should use |
| 355 | * these wrappers rather than directly call raw_spin_{lock,unlock}* on ->lock. |
| 356 | */ |
| 357 | #define raw_spin_lock_rcu_node(p) \ |
| 358 | do { \ |
| 359 | raw_spin_lock(&ACCESS_PRIVATE(p, lock)); \ |
| 360 | smp_mb__after_unlock_lock(); \ |
| 361 | } while (0) |
| 362 | |
| 363 | #define raw_spin_unlock_rcu_node(p) raw_spin_unlock(&ACCESS_PRIVATE(p, lock)) |
| 364 | |
| 365 | #define raw_spin_lock_irq_rcu_node(p) \ |
| 366 | do { \ |
| 367 | raw_spin_lock_irq(&ACCESS_PRIVATE(p, lock)); \ |
| 368 | smp_mb__after_unlock_lock(); \ |
| 369 | } while (0) |
| 370 | |
| 371 | #define raw_spin_unlock_irq_rcu_node(p) \ |
| 372 | raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock)) |
| 373 | |
Paul E. McKenney | 4e4bea7 | 2017-05-11 15:33:23 -0700 | [diff] [blame] | 374 | #define raw_spin_lock_irqsave_rcu_node(p, flags) \ |
Paul E. McKenney | 83d40bd | 2017-05-09 13:28:51 -0700 | [diff] [blame] | 375 | do { \ |
Paul E. McKenney | 4e4bea7 | 2017-05-11 15:33:23 -0700 | [diff] [blame] | 376 | raw_spin_lock_irqsave(&ACCESS_PRIVATE(p, lock), flags); \ |
Paul E. McKenney | 83d40bd | 2017-05-09 13:28:51 -0700 | [diff] [blame] | 377 | smp_mb__after_unlock_lock(); \ |
| 378 | } while (0) |
| 379 | |
Paul E. McKenney | 4e4bea7 | 2017-05-11 15:33:23 -0700 | [diff] [blame] | 380 | #define raw_spin_unlock_irqrestore_rcu_node(p, flags) \ |
Matthew Wilcox | a32e01e | 2018-01-17 06:24:30 -0800 | [diff] [blame] | 381 | raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags) |
Paul E. McKenney | 83d40bd | 2017-05-09 13:28:51 -0700 | [diff] [blame] | 382 | |
| 383 | #define raw_spin_trylock_rcu_node(p) \ |
| 384 | ({ \ |
| 385 | bool ___locked = raw_spin_trylock(&ACCESS_PRIVATE(p, lock)); \ |
| 386 | \ |
| 387 | if (___locked) \ |
| 388 | smp_mb__after_unlock_lock(); \ |
| 389 | ___locked; \ |
| 390 | }) |
| 391 | |
Matthew Wilcox | a32e01e | 2018-01-17 06:24:30 -0800 | [diff] [blame] | 392 | #define raw_lockdep_assert_held_rcu_node(p) \ |
| 393 | lockdep_assert_held(&ACCESS_PRIVATE(p, lock)) |
| 394 | |
Paul E. McKenney | 2b34c43 | 2017-03-14 14:29:53 -0700 | [diff] [blame] | 395 | #endif /* #if defined(SRCU) || !defined(TINY_RCU) */ |
| 396 | |
Paul E. McKenney | 25c3632 | 2017-05-03 09:51:55 -0700 | [diff] [blame] | 397 | #ifdef CONFIG_TINY_RCU |
| 398 | /* Tiny RCU doesn't expedite, as its purpose in life is instead to be tiny. */ |
Paul E. McKenney | 7414fac | 2017-06-12 16:44:19 -0700 | [diff] [blame] | 399 | static inline bool rcu_gp_is_normal(void) { return true; } |
| 400 | static inline bool rcu_gp_is_expedited(void) { return false; } |
| 401 | static inline void rcu_expedite_gp(void) { } |
| 402 | static inline void rcu_unexpedite_gp(void) { } |
Paul E. McKenney | bfbd767 | 2018-01-11 12:58:53 -0800 | [diff] [blame] | 403 | static inline void rcu_request_urgent_qs_task(struct task_struct *t) { } |
Paul E. McKenney | 25c3632 | 2017-05-03 09:51:55 -0700 | [diff] [blame] | 404 | #else /* #ifdef CONFIG_TINY_RCU */ |
| 405 | bool rcu_gp_is_normal(void); /* Internal RCU use. */ |
| 406 | bool rcu_gp_is_expedited(void); /* Internal RCU use. */ |
| 407 | void rcu_expedite_gp(void); |
| 408 | void rcu_unexpedite_gp(void); |
| 409 | void rcupdate_announce_bootup_oddness(void); |
Paul E. McKenney | bfbd767 | 2018-01-11 12:58:53 -0800 | [diff] [blame] | 410 | void rcu_request_urgent_qs_task(struct task_struct *t); |
Paul E. McKenney | 25c3632 | 2017-05-03 09:51:55 -0700 | [diff] [blame] | 411 | #endif /* #else #ifdef CONFIG_TINY_RCU */ |
| 412 | |
Paul E. McKenney | 8211824 | 2017-05-03 11:13:24 -0700 | [diff] [blame] | 413 | #define RCU_SCHEDULER_INACTIVE 0 |
| 414 | #define RCU_SCHEDULER_INIT 1 |
| 415 | #define RCU_SCHEDULER_RUNNING 2 |
| 416 | |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 417 | enum rcutorture_type { |
| 418 | RCU_FLAVOR, |
| 419 | RCU_BH_FLAVOR, |
| 420 | RCU_SCHED_FLAVOR, |
| 421 | RCU_TASKS_FLAVOR, |
| 422 | SRCU_FLAVOR, |
| 423 | INVALID_RCU_FLAVOR |
| 424 | }; |
| 425 | |
| 426 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) |
| 427 | void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 428 | unsigned long *gp_seq); |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 429 | void rcutorture_record_test_transition(void); |
| 430 | void rcutorture_record_progress(unsigned long vernum); |
| 431 | void do_trace_rcu_torture_read(const char *rcutorturename, |
| 432 | struct rcu_head *rhp, |
| 433 | unsigned long secs, |
| 434 | unsigned long c_old, |
| 435 | unsigned long c); |
| 436 | #else |
| 437 | static inline void rcutorture_get_gp_data(enum rcutorture_type test_type, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 438 | int *flags, unsigned long *gp_seq) |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 439 | { |
| 440 | *flags = 0; |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 441 | *gp_seq = 0; |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 442 | } |
Paul E. McKenney | 7414fac | 2017-06-12 16:44:19 -0700 | [diff] [blame] | 443 | static inline void rcutorture_record_test_transition(void) { } |
| 444 | static inline void rcutorture_record_progress(unsigned long vernum) { } |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 445 | #ifdef CONFIG_RCU_TRACE |
| 446 | void do_trace_rcu_torture_read(const char *rcutorturename, |
| 447 | struct rcu_head *rhp, |
| 448 | unsigned long secs, |
| 449 | unsigned long c_old, |
| 450 | unsigned long c); |
| 451 | #else |
| 452 | #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \ |
| 453 | do { } while (0) |
| 454 | #endif |
| 455 | #endif |
| 456 | |
| 457 | #ifdef CONFIG_TINY_SRCU |
| 458 | |
| 459 | static inline void srcutorture_get_gp_data(enum rcutorture_type test_type, |
| 460 | struct srcu_struct *sp, int *flags, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 461 | unsigned long *gp_seq) |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 462 | { |
| 463 | if (test_type != SRCU_FLAVOR) |
| 464 | return; |
| 465 | *flags = 0; |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 466 | *gp_seq = sp->srcu_idx; |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | #elif defined(CONFIG_TREE_SRCU) |
| 470 | |
| 471 | void srcutorture_get_gp_data(enum rcutorture_type test_type, |
| 472 | struct srcu_struct *sp, int *flags, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 473 | unsigned long *gp_seq); |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 474 | |
Paul E. McKenney | cad7b38 | 2017-05-03 10:22:57 -0700 | [diff] [blame] | 475 | #endif |
| 476 | |
Paul E. McKenney | e3c8d51 | 2017-05-03 13:37:16 -0700 | [diff] [blame] | 477 | #ifdef CONFIG_TINY_RCU |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 478 | static inline unsigned long rcu_get_gp_seq(void) { return 0; } |
| 479 | static inline unsigned long rcu_bh_get_gp_seq(void) { return 0; } |
| 480 | static inline unsigned long rcu_sched_get_gp_seq(void) { return 0; } |
Paul E. McKenney | 7414fac | 2017-06-12 16:44:19 -0700 | [diff] [blame] | 481 | static inline unsigned long rcu_exp_batches_completed(void) { return 0; } |
| 482 | static inline unsigned long rcu_exp_batches_completed_sched(void) { return 0; } |
| 483 | static inline unsigned long |
| 484 | srcu_batches_completed(struct srcu_struct *sp) { return 0; } |
| 485 | static inline void rcu_force_quiescent_state(void) { } |
| 486 | static inline void rcu_bh_force_quiescent_state(void) { } |
| 487 | static inline void rcu_sched_force_quiescent_state(void) { } |
| 488 | static inline void show_rcu_gp_kthreads(void) { } |
Paul E. McKenney | e3c8d51 | 2017-05-03 13:37:16 -0700 | [diff] [blame] | 489 | #else /* #ifdef CONFIG_TINY_RCU */ |
| 490 | extern unsigned long rcutorture_testseq; |
| 491 | extern unsigned long rcutorture_vernum; |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 492 | unsigned long rcu_get_gp_seq(void); |
| 493 | unsigned long rcu_bh_get_gp_seq(void); |
| 494 | unsigned long rcu_sched_get_gp_seq(void); |
Paul E. McKenney | e3c8d51 | 2017-05-03 13:37:16 -0700 | [diff] [blame] | 495 | unsigned long rcu_exp_batches_completed(void); |
| 496 | unsigned long rcu_exp_batches_completed_sched(void); |
Paul E. McKenney | 5a0465e | 2017-05-04 11:31:04 -0700 | [diff] [blame] | 497 | unsigned long srcu_batches_completed(struct srcu_struct *sp); |
Paul E. McKenney | e3c8d51 | 2017-05-03 13:37:16 -0700 | [diff] [blame] | 498 | void show_rcu_gp_kthreads(void); |
| 499 | void rcu_force_quiescent_state(void); |
| 500 | void rcu_bh_force_quiescent_state(void); |
| 501 | void rcu_sched_force_quiescent_state(void); |
Paul E. McKenney | ad7c946 | 2018-01-08 14:35:52 -0800 | [diff] [blame] | 502 | extern struct workqueue_struct *rcu_gp_wq; |
Paul E. McKenney | 25f3d7e | 2018-02-01 22:05:38 -0800 | [diff] [blame] | 503 | extern struct workqueue_struct *rcu_par_gp_wq; |
Paul E. McKenney | e3c8d51 | 2017-05-03 13:37:16 -0700 | [diff] [blame] | 504 | #endif /* #else #ifdef CONFIG_TINY_RCU */ |
| 505 | |
Paul E. McKenney | 44c65ff | 2017-05-15 16:26:34 -0700 | [diff] [blame] | 506 | #ifdef CONFIG_RCU_NOCB_CPU |
Paul E. McKenney | 3d54f79 | 2017-05-03 12:25:50 -0700 | [diff] [blame] | 507 | bool rcu_is_nocb_cpu(int cpu); |
| 508 | #else |
| 509 | static inline bool rcu_is_nocb_cpu(int cpu) { return false; } |
| 510 | #endif |
| 511 | |
Paul E. McKenney | 29c00b4 | 2011-06-17 15:53:19 -0700 | [diff] [blame] | 512 | #endif /* __LINUX_RCU_H */ |