blob: 51f1fb21f1712e1098585d70e3afb8b3e6dfcbdc [file] [log] [blame]
Paul E. McKenney29c00b42011-06-17 15:53:19 -07001/*
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. McKenney87de1cf2013-12-03 10:02:52 -080015 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
Paul E. McKenney29c00b42011-06-17 15:53:19 -070017 *
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 Gortmaker5cb5c6e2014-02-19 14:33:27 -050026#include <trace/events/rcu.h>
Paul E. McKenneye99033c2011-06-21 00:13:44 -070027#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. McKenneyc2d80892018-11-28 12:47:23 -080033/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */
Paul E. McKenney84585aa2017-10-04 15:55:16 -070034#define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1)
Paul E. McKenney6136d6e2017-10-03 08:28:04 -070035
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -080036
37/*
38 * Grace-period counter management.
39 */
40
Paul E. McKenneyf1ec57a2017-03-21 10:35:57 -070041#define RCU_SEQ_CTR_SHIFT 2
Paul E. McKenney031aeee2017-03-21 07:28:14 -070042#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 */
48static 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 */
57static inline int rcu_seq_state(unsigned long s)
58{
59 return s & RCU_SEQ_STATE_MASK;
60}
61
Paul E. McKenney80a79562017-03-22 15:26:18 -070062/*
63 * Set the state portion of the pointed-to sequence number.
64 * The caller is responsible for preventing conflicting updates.
65 */
66static 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. McKenney2e8c28c2017-02-20 14:57:17 -080072/* Adjust sequence number for start of update-side operation. */
73static 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. McKenney031aeee2017-03-21 07:28:14 -070077 WARN_ON_ONCE(rcu_seq_state(*sp) != 1);
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -080078}
79
Paul E. McKenney9a414202018-01-31 19:23:24 -080080/* Compute the end-of-grace-period value for the specified sequence number. */
81static inline unsigned long rcu_seq_endval(unsigned long *sp)
82{
83 return (*sp | RCU_SEQ_STATE_MASK) + 1;
84}
85
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -080086/* Adjust sequence number for end of update-side operation. */
87static inline void rcu_seq_end(unsigned long *sp)
88{
89 smp_mb(); /* Ensure update-side operation before counter increment. */
Paul E. McKenney031aeee2017-03-21 07:28:14 -070090 WARN_ON_ONCE(!rcu_seq_state(*sp));
Paul E. McKenney9a414202018-01-31 19:23:24 -080091 WRITE_ONCE(*sp, rcu_seq_endval(sp));
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -080092}
93
Joel Fernandes (Google)0d805a72018-05-22 23:38:13 -070094/*
95 * rcu_seq_snap - Take a snapshot of the update side's sequence number.
96 *
97 * This function returns the earliest value of the grace-period sequence number
98 * that will indicate that a full grace period has elapsed since the current
99 * time. Once the grace-period sequence number has reached this value, it will
100 * be safe to invoke all callbacks that have been registered prior to the
101 * current time. This value is the current grace-period number plus two to the
102 * power of the number of low-order bits reserved for state, then rounded up to
103 * the next value in which the state bits are all zero.
104 */
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -0800105static inline unsigned long rcu_seq_snap(unsigned long *sp)
106{
107 unsigned long s;
108
Paul E. McKenney031aeee2017-03-21 07:28:14 -0700109 s = (READ_ONCE(*sp) + 2 * RCU_SEQ_STATE_MASK + 1) & ~RCU_SEQ_STATE_MASK;
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -0800110 smp_mb(); /* Above access must not bleed into critical section. */
111 return s;
112}
113
Paul E. McKenney8660b7d2017-03-13 16:48:18 -0700114/* Return the current value the update side's sequence number, no ordering. */
115static inline unsigned long rcu_seq_current(unsigned long *sp)
116{
117 return READ_ONCE(*sp);
118}
119
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -0800120/*
Paul E. McKenney2e3e5e52018-05-15 11:53:41 -0700121 * Given a snapshot from rcu_seq_snap(), determine whether or not the
122 * corresponding update-side operation has started.
123 */
124static inline bool rcu_seq_started(unsigned long *sp, unsigned long s)
125{
126 return ULONG_CMP_LT((s - 1) & ~RCU_SEQ_STATE_MASK, READ_ONCE(*sp));
127}
128
129/*
Paul E. McKenney2e8c28c2017-02-20 14:57:17 -0800130 * Given a snapshot from rcu_seq_snap(), determine whether or not a
131 * full update-side operation has occurred.
132 */
133static inline bool rcu_seq_done(unsigned long *sp, unsigned long s)
134{
135 return ULONG_CMP_GE(READ_ONCE(*sp), s);
136}
137
Paul E. McKenney4145fa72011-10-31 15:01:54 -0700138/*
Paul E. McKenney67e14c12018-04-27 16:01:46 -0700139 * Has a grace period completed since the time the old gp_seq was collected?
140 */
141static inline bool rcu_seq_completed_gp(unsigned long old, unsigned long new)
142{
143 return ULONG_CMP_LT(old, new & ~RCU_SEQ_STATE_MASK);
144}
145
146/*
147 * Has a grace period started since the time the old gp_seq was collected?
148 */
149static inline bool rcu_seq_new_gp(unsigned long old, unsigned long new)
150{
151 return ULONG_CMP_LT((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK,
152 new);
153}
154
155/*
Paul E. McKenneyd72193122018-05-15 15:24:41 -0700156 * Roughly how many full grace periods have elapsed between the collection
157 * of the two specified grace periods?
158 */
159static inline unsigned long rcu_seq_diff(unsigned long new, unsigned long old)
160{
Paul E. McKenney2ee5aca2018-06-09 01:22:20 -0700161 unsigned long rnd_diff;
162
163 if (old == new)
164 return 0;
165 /*
166 * Compute the number of grace periods (still shifted up), plus
167 * one if either of new and old is not an exact grace period.
168 */
169 rnd_diff = (new & ~RCU_SEQ_STATE_MASK) -
170 ((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK) +
171 ((new & RCU_SEQ_STATE_MASK) || (old & RCU_SEQ_STATE_MASK));
172 if (ULONG_CMP_GE(RCU_SEQ_STATE_MASK, rnd_diff))
173 return 1; /* Definitely no grace period has elapsed. */
174 return ((rnd_diff - RCU_SEQ_STATE_MASK - 1) >> RCU_SEQ_CTR_SHIFT) + 2;
Paul E. McKenneyd72193122018-05-15 15:24:41 -0700175}
176
177/*
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700178 * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
Paul E. McKenney7f87c032018-07-07 18:12:26 -0700179 * by call_rcu() and rcu callback execution, and are therefore not part
180 * of the RCU API. These are in rcupdate.h because they are used by all
181 * RCU implementations.
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700182 */
183
184#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
185# define STATE_RCU_HEAD_READY 0
186# define STATE_RCU_HEAD_QUEUED 1
187
188extern struct debug_obj_descr rcuhead_debug_descr;
189
Paul E. McKenneyae150182013-04-23 13:20:57 -0700190static inline int debug_rcu_head_queue(struct rcu_head *head)
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700191{
Paul E. McKenneyae150182013-04-23 13:20:57 -0700192 int r1;
193
194 r1 = debug_object_activate(head, &rcuhead_debug_descr);
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700195 debug_object_active_state(head, &rcuhead_debug_descr,
196 STATE_RCU_HEAD_READY,
197 STATE_RCU_HEAD_QUEUED);
Paul E. McKenneyae150182013-04-23 13:20:57 -0700198 return r1;
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700199}
200
201static inline void debug_rcu_head_unqueue(struct rcu_head *head)
202{
203 debug_object_active_state(head, &rcuhead_debug_descr,
204 STATE_RCU_HEAD_QUEUED,
205 STATE_RCU_HEAD_READY);
206 debug_object_deactivate(head, &rcuhead_debug_descr);
207}
208#else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
Paul E. McKenneyae150182013-04-23 13:20:57 -0700209static inline int debug_rcu_head_queue(struct rcu_head *head)
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700210{
Paul E. McKenneyae150182013-04-23 13:20:57 -0700211 return 0;
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700212}
213
214static inline void debug_rcu_head_unqueue(struct rcu_head *head)
215{
216}
217#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
218
Teodora Balutabd73a7f2013-11-11 17:11:24 +0200219void kfree(const void *);
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700220
Paul E. McKenney406e3e52014-06-23 13:48:28 -0700221/*
222 * Reclaim the specified callback, either by invoking it (non-lazy case)
223 * or freeing it directly (lazy case). Return true if lazy, false otherwise.
224 */
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400225static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700226{
Paul E. McKenney74de6962018-07-24 15:28:09 -0700227 rcu_callback_t f;
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700228 unsigned long offset = (unsigned long)head->func;
229
Paul E. McKenney24ef6592013-10-28 09:22:24 -0700230 rcu_lock_acquire(&rcu_callback_map);
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700231 if (__is_kfree_rcu_offset(offset)) {
Paul E. McKenneydffd06a2017-01-23 11:55:43 -0800232 RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);)
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700233 kfree((void *)head - offset);
Paul E. McKenney24ef6592013-10-28 09:22:24 -0700234 rcu_lock_release(&rcu_callback_map);
Paul E. McKenney406e3e52014-06-23 13:48:28 -0700235 return true;
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700236 } else {
Paul E. McKenneydffd06a2017-01-23 11:55:43 -0800237 RCU_TRACE(trace_rcu_invoke_callback(rn, head);)
Paul E. McKenney74de6962018-07-24 15:28:09 -0700238 f = head->func;
239 WRITE_ONCE(head->func, (rcu_callback_t)0L);
240 f(head);
Paul E. McKenney24ef6592013-10-28 09:22:24 -0700241 rcu_lock_release(&rcu_callback_map);
Paul E. McKenney406e3e52014-06-23 13:48:28 -0700242 return false;
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700243 }
244}
245
Paul E. McKenney6bfc09e2012-10-19 12:49:17 -0700246#ifdef CONFIG_RCU_STALL_COMMON
247
248extern int rcu_cpu_stall_suppress;
249int rcu_jiffies_till_stall_check(void);
250
Paul E. McKenneyf22ce092017-09-01 14:40:54 -0700251#define rcu_ftrace_dump_stall_suppress() \
252do { \
253 if (!rcu_cpu_stall_suppress) \
254 rcu_cpu_stall_suppress = 3; \
255} while (0)
256
257#define rcu_ftrace_dump_stall_unsuppress() \
258do { \
259 if (rcu_cpu_stall_suppress == 3) \
260 rcu_cpu_stall_suppress = 0; \
261} while (0)
262
263#else /* #endif #ifdef CONFIG_RCU_STALL_COMMON */
264#define rcu_ftrace_dump_stall_suppress()
265#define rcu_ftrace_dump_stall_unsuppress()
Paul E. McKenney6bfc09e2012-10-19 12:49:17 -0700266#endif /* #ifdef CONFIG_RCU_STALL_COMMON */
267
Paul E. McKenney0d752922013-08-17 18:08:37 -0700268/*
269 * Strings used in tracepoints need to be exported via the
270 * tracing system such that tools like perf and trace-cmd can
271 * translate the string address pointers to actual text.
272 */
273#define TPS(x) tracepoint_string(x)
274
Paul E. McKenneyb8989b72017-05-03 12:28:59 -0700275/*
276 * Dump the ftrace buffer, but only one time per callsite per boot.
277 */
278#define rcu_ftrace_dump(oops_dump_mode) \
279do { \
280 static atomic_t ___rfd_beenhere = ATOMIC_INIT(0); \
281 \
282 if (!atomic_read(&___rfd_beenhere) && \
Paul E. McKenney83b6ca12017-08-31 16:47:08 -0700283 !atomic_xchg(&___rfd_beenhere, 1)) { \
284 tracing_off(); \
Paul E. McKenneyf22ce092017-09-01 14:40:54 -0700285 rcu_ftrace_dump_stall_suppress(); \
Paul E. McKenneyb8989b72017-05-03 12:28:59 -0700286 ftrace_dump(oops_dump_mode); \
Paul E. McKenneyf22ce092017-09-01 14:40:54 -0700287 rcu_ftrace_dump_stall_unsuppress(); \
Paul E. McKenney83b6ca12017-08-31 16:47:08 -0700288 } \
Paul E. McKenneyb8989b72017-05-03 12:28:59 -0700289} while (0)
290
Pranith Kumaraa23c6fbc2014-09-19 11:32:29 -0400291void rcu_early_boot_tests(void);
Paul E. McKenney52d7e482017-01-10 02:28:26 -0800292void rcu_test_sync_prims(void);
Pranith Kumaraa23c6fbc2014-09-19 11:32:29 -0400293
Lai Jiangshan5f6130f2014-12-09 17:53:34 +0800294/*
295 * This function really isn't for public consumption, but RCU is special in
296 * that context switches can allow the state machine to make progress.
297 */
298extern void resched_cpu(int cpu);
299
Paul E. McKenney2b34c432017-03-14 14:29:53 -0700300#if defined(SRCU) || !defined(TINY_RCU)
301
302#include <linux/rcu_node_tree.h>
303
304extern int rcu_num_lvls;
Paul E. McKenneye95d68d2017-03-15 13:11:11 -0700305extern int num_rcu_lvl[];
Paul E. McKenney2b34c432017-03-14 14:29:53 -0700306extern int rcu_num_nodes;
307static bool rcu_fanout_exact;
308static int rcu_fanout_leaf;
309
310/*
311 * Compute the per-level fanout, either using the exact fanout specified
312 * or balancing the tree, depending on the rcu_fanout_exact boot parameter.
313 */
314static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt)
315{
316 int i;
317
318 if (rcu_fanout_exact) {
319 levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
320 for (i = rcu_num_lvls - 2; i >= 0; i--)
321 levelspread[i] = RCU_FANOUT;
322 } else {
323 int ccur;
324 int cprv;
325
326 cprv = nr_cpu_ids;
327 for (i = rcu_num_lvls - 1; i >= 0; i--) {
328 ccur = levelcnt[i];
329 levelspread[i] = (cprv + ccur - 1) / ccur;
330 cprv = ccur;
331 }
332 }
333}
334
Paul E. McKenney7f87c032018-07-07 18:12:26 -0700335/* Returns a pointer to the first leaf rcu_node structure. */
Paul E. McKenneyaedf4ba2018-07-04 14:33:59 -0700336#define rcu_first_leaf_node() (rcu_state.level[rcu_num_lvls - 1])
Paul E. McKenney5b4c11d2018-04-13 17:11:44 -0700337
338/* Is this rcu_node a leaf? */
339#define rcu_is_leaf_node(rnp) ((rnp)->level == rcu_num_lvls - 1)
340
Paul E. McKenney52575142018-04-24 11:03:39 -0700341/* Is this rcu_node the last leaf? */
Paul E. McKenneyaedf4ba2018-07-04 14:33:59 -0700342#define rcu_is_last_leaf_node(rnp) ((rnp) == &rcu_state.node[rcu_num_nodes - 1])
Paul E. McKenney52575142018-04-24 11:03:39 -0700343
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700344/*
Paul E. McKenneyaedf4ba2018-07-04 14:33:59 -0700345 * Do a full breadth-first scan of the {s,}rcu_node structures for the
Paul E. McKenney7f87c032018-07-07 18:12:26 -0700346 * specified state structure (for SRCU) or the only rcu_state structure
347 * (for RCU).
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700348 */
Paul E. McKenneyaedf4ba2018-07-04 14:33:59 -0700349#define srcu_for_each_node_breadth_first(sp, rnp) \
350 for ((rnp) = &(sp)->node[0]; \
351 (rnp) < &(sp)->node[rcu_num_nodes]; (rnp)++)
352#define rcu_for_each_node_breadth_first(rnp) \
353 srcu_for_each_node_breadth_first(&rcu_state, rnp)
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700354
355/*
Paul E. McKenney7f87c032018-07-07 18:12:26 -0700356 * Scan the leaves of the rcu_node hierarchy for the rcu_state structure.
357 * Note that if there is a singleton rcu_node tree with but one rcu_node
358 * structure, this loop -will- visit the rcu_node structure. It is still
359 * a leaf node, even if it is also the root node.
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700360 */
Paul E. McKenneyaedf4ba2018-07-04 14:33:59 -0700361#define rcu_for_each_leaf_node(rnp) \
362 for ((rnp) = rcu_first_leaf_node(); \
363 (rnp) < &rcu_state.node[rcu_num_nodes]; (rnp)++)
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700364
365/*
366 * Iterate over all possible CPUs in a leaf RCU node.
367 */
368#define for_each_leaf_node_possible_cpu(rnp, cpu) \
Paul E. McKenney65963d22018-01-31 20:24:15 -0800369 for ((cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \
370 (cpu) <= rnp->grphi; \
371 (cpu) = cpumask_next((cpu), cpu_possible_mask))
372
373/*
374 * Iterate over all CPUs in a leaf RCU node's specified mask.
375 */
376#define rcu_find_next_bit(rnp, cpu, mask) \
377 ((rnp)->grplo + find_next_bit(&(mask), BITS_PER_LONG, (cpu)))
378#define for_each_leaf_node_cpu_mask(rnp, cpu, mask) \
379 for ((cpu) = rcu_find_next_bit((rnp), 0, (mask)); \
380 (cpu) <= rnp->grphi; \
381 (cpu) = rcu_find_next_bit((rnp), (cpu) + 1 - (rnp->grplo), (mask)))
Paul E. McKenneyefbe4512017-03-15 13:07:53 -0700382
Paul E. McKenney83d40bd2017-05-09 13:28:51 -0700383/*
384 * Wrappers for the rcu_node::lock acquire and release.
385 *
386 * Because the rcu_nodes form a tree, the tree traversal locking will observe
387 * different lock values, this in turn means that an UNLOCK of one level
388 * followed by a LOCK of another level does not imply a full memory barrier;
389 * and most importantly transitivity is lost.
390 *
391 * In order to restore full ordering between tree levels, augment the regular
392 * lock acquire functions with smp_mb__after_unlock_lock().
393 *
394 * As ->lock of struct rcu_node is a __private field, therefore one should use
395 * these wrappers rather than directly call raw_spin_{lock,unlock}* on ->lock.
396 */
397#define raw_spin_lock_rcu_node(p) \
398do { \
399 raw_spin_lock(&ACCESS_PRIVATE(p, lock)); \
400 smp_mb__after_unlock_lock(); \
401} while (0)
402
403#define raw_spin_unlock_rcu_node(p) raw_spin_unlock(&ACCESS_PRIVATE(p, lock))
404
405#define raw_spin_lock_irq_rcu_node(p) \
406do { \
407 raw_spin_lock_irq(&ACCESS_PRIVATE(p, lock)); \
408 smp_mb__after_unlock_lock(); \
409} while (0)
410
411#define raw_spin_unlock_irq_rcu_node(p) \
412 raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock))
413
Paul E. McKenney4e4bea72017-05-11 15:33:23 -0700414#define raw_spin_lock_irqsave_rcu_node(p, flags) \
Paul E. McKenney83d40bd2017-05-09 13:28:51 -0700415do { \
Paul E. McKenney4e4bea72017-05-11 15:33:23 -0700416 raw_spin_lock_irqsave(&ACCESS_PRIVATE(p, lock), flags); \
Paul E. McKenney83d40bd2017-05-09 13:28:51 -0700417 smp_mb__after_unlock_lock(); \
418} while (0)
419
Paul E. McKenney4e4bea72017-05-11 15:33:23 -0700420#define raw_spin_unlock_irqrestore_rcu_node(p, flags) \
Matthew Wilcoxa32e01e2018-01-17 06:24:30 -0800421 raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags)
Paul E. McKenney83d40bd2017-05-09 13:28:51 -0700422
423#define raw_spin_trylock_rcu_node(p) \
424({ \
425 bool ___locked = raw_spin_trylock(&ACCESS_PRIVATE(p, lock)); \
426 \
427 if (___locked) \
428 smp_mb__after_unlock_lock(); \
429 ___locked; \
430})
431
Matthew Wilcoxa32e01e2018-01-17 06:24:30 -0800432#define raw_lockdep_assert_held_rcu_node(p) \
433 lockdep_assert_held(&ACCESS_PRIVATE(p, lock))
434
Paul E. McKenney2b34c432017-03-14 14:29:53 -0700435#endif /* #if defined(SRCU) || !defined(TINY_RCU) */
436
Paul E. McKenneye0fcba92018-08-14 08:45:54 -0700437#ifdef CONFIG_SRCU
438void srcu_init(void);
439#else /* #ifdef CONFIG_SRCU */
440static inline void srcu_init(void) { }
441#endif /* #else #ifdef CONFIG_SRCU */
442
Paul E. McKenney25c36322017-05-03 09:51:55 -0700443#ifdef CONFIG_TINY_RCU
444/* Tiny RCU doesn't expedite, as its purpose in life is instead to be tiny. */
Paul E. McKenney7414fac2017-06-12 16:44:19 -0700445static inline bool rcu_gp_is_normal(void) { return true; }
446static inline bool rcu_gp_is_expedited(void) { return false; }
447static inline void rcu_expedite_gp(void) { }
448static inline void rcu_unexpedite_gp(void) { }
Paul E. McKenneybfbd7672018-01-11 12:58:53 -0800449static inline void rcu_request_urgent_qs_task(struct task_struct *t) { }
Paul E. McKenney25c36322017-05-03 09:51:55 -0700450#else /* #ifdef CONFIG_TINY_RCU */
451bool rcu_gp_is_normal(void); /* Internal RCU use. */
452bool rcu_gp_is_expedited(void); /* Internal RCU use. */
453void rcu_expedite_gp(void);
454void rcu_unexpedite_gp(void);
455void rcupdate_announce_bootup_oddness(void);
Paul E. McKenneybfbd7672018-01-11 12:58:53 -0800456void rcu_request_urgent_qs_task(struct task_struct *t);
Paul E. McKenney25c36322017-05-03 09:51:55 -0700457#endif /* #else #ifdef CONFIG_TINY_RCU */
458
Paul E. McKenney82118242017-05-03 11:13:24 -0700459#define RCU_SCHEDULER_INACTIVE 0
460#define RCU_SCHEDULER_INIT 1
461#define RCU_SCHEDULER_RUNNING 2
462
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700463enum rcutorture_type {
464 RCU_FLAVOR,
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700465 RCU_TASKS_FLAVOR,
466 SRCU_FLAVOR,
467 INVALID_RCU_FLAVOR
468};
469
470#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
471void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700472 unsigned long *gp_seq);
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700473void rcutorture_record_progress(unsigned long vernum);
474void do_trace_rcu_torture_read(const char *rcutorturename,
475 struct rcu_head *rhp,
476 unsigned long secs,
477 unsigned long c_old,
478 unsigned long c);
479#else
480static inline void rcutorture_get_gp_data(enum rcutorture_type test_type,
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700481 int *flags, unsigned long *gp_seq)
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700482{
483 *flags = 0;
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700484 *gp_seq = 0;
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700485}
Paul E. McKenney7414fac2017-06-12 16:44:19 -0700486static inline void rcutorture_record_progress(unsigned long vernum) { }
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700487#ifdef CONFIG_RCU_TRACE
488void do_trace_rcu_torture_read(const char *rcutorturename,
489 struct rcu_head *rhp,
490 unsigned long secs,
491 unsigned long c_old,
492 unsigned long c);
493#else
494#define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \
495 do { } while (0)
496#endif
497#endif
498
499#ifdef CONFIG_TINY_SRCU
500
501static inline void srcutorture_get_gp_data(enum rcutorture_type test_type,
502 struct srcu_struct *sp, int *flags,
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700503 unsigned long *gp_seq)
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700504{
505 if (test_type != SRCU_FLAVOR)
506 return;
507 *flags = 0;
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700508 *gp_seq = sp->srcu_idx;
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700509}
510
511#elif defined(CONFIG_TREE_SRCU)
512
513void srcutorture_get_gp_data(enum rcutorture_type test_type,
514 struct srcu_struct *sp, int *flags,
Paul E. McKenneyaebc8262018-05-01 06:42:51 -0700515 unsigned long *gp_seq);
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700516
Paul E. McKenneycad7b382017-05-03 10:22:57 -0700517#endif
518
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700519#ifdef CONFIG_TINY_RCU
Paul E. McKenney17ef2fe2018-04-27 11:39:34 -0700520static inline unsigned long rcu_get_gp_seq(void) { return 0; }
Paul E. McKenney7414fac2017-06-12 16:44:19 -0700521static inline unsigned long rcu_exp_batches_completed(void) { return 0; }
Paul E. McKenney7414fac2017-06-12 16:44:19 -0700522static inline unsigned long
523srcu_batches_completed(struct srcu_struct *sp) { return 0; }
524static inline void rcu_force_quiescent_state(void) { }
Paul E. McKenney7414fac2017-06-12 16:44:19 -0700525static inline void show_rcu_gp_kthreads(void) { }
Joel Fernandes (Google)4babd852018-06-19 15:14:18 -0700526static inline int rcu_get_gp_kthreads_prio(void) { return 0; }
Paul E. McKenneye0aff972018-10-01 17:40:54 -0700527static inline void rcu_fwd_progress_check(unsigned long j) { }
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700528#else /* #ifdef CONFIG_TINY_RCU */
Paul E. McKenney17ef2fe2018-04-27 11:39:34 -0700529unsigned long rcu_get_gp_seq(void);
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700530unsigned long rcu_exp_batches_completed(void);
Paul E. McKenney5a0465e2017-05-04 11:31:04 -0700531unsigned long srcu_batches_completed(struct srcu_struct *sp);
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700532void show_rcu_gp_kthreads(void);
Joel Fernandes (Google)4babd852018-06-19 15:14:18 -0700533int rcu_get_gp_kthreads_prio(void);
Paul E. McKenneye0aff972018-10-01 17:40:54 -0700534void rcu_fwd_progress_check(unsigned long j);
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700535void rcu_force_quiescent_state(void);
Paul E. McKenneyad7c9462018-01-08 14:35:52 -0800536extern struct workqueue_struct *rcu_gp_wq;
Paul E. McKenney25f3d7e2018-02-01 22:05:38 -0800537extern struct workqueue_struct *rcu_par_gp_wq;
Paul E. McKenneye3c8d512017-05-03 13:37:16 -0700538#endif /* #else #ifdef CONFIG_TINY_RCU */
539
Paul E. McKenney44c65ff2017-05-15 16:26:34 -0700540#ifdef CONFIG_RCU_NOCB_CPU
Paul E. McKenney3d54f792017-05-03 12:25:50 -0700541bool rcu_is_nocb_cpu(int cpu);
Paul E. McKenney5ab7ab82018-09-21 18:08:09 -0700542void rcu_bind_current_to_nocb(void);
Paul E. McKenney3d54f792017-05-03 12:25:50 -0700543#else
544static inline bool rcu_is_nocb_cpu(int cpu) { return false; }
Paul E. McKenney5ab7ab82018-09-21 18:08:09 -0700545static inline void rcu_bind_current_to_nocb(void) { }
Paul E. McKenney3d54f792017-05-03 12:25:50 -0700546#endif
547
Paul E. McKenney29c00b42011-06-17 15:53:19 -0700548#endif /* __LINUX_RCU_H */