]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a71fca58 | 2 | * Read-Copy Update mechanism for mutual exclusion |
1da177e4 LT |
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 | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | * | |
01c1c660 | 18 | * Copyright IBM Corporation, 2001 |
1da177e4 LT |
19 | * |
20 | * Author: Dipankar Sarma <dipankar@in.ibm.com> | |
a71fca58 | 21 | * |
595182bc | 22 | * Based on the original work by Paul McKenney <paulmck@us.ibm.com> |
1da177e4 LT |
23 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. |
24 | * Papers: | |
25 | * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf | |
26 | * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001) | |
27 | * | |
28 | * For detailed explanation of Read-Copy Update mechanism see - | |
a71fca58 | 29 | * http://lse.sourceforge.net/locking/rcupdate.html |
1da177e4 LT |
30 | * |
31 | */ | |
32 | ||
33 | #ifndef __LINUX_RCUPDATE_H | |
34 | #define __LINUX_RCUPDATE_H | |
35 | ||
1da177e4 LT |
36 | #include <linux/cache.h> |
37 | #include <linux/spinlock.h> | |
38 | #include <linux/threads.h> | |
1da177e4 LT |
39 | #include <linux/cpumask.h> |
40 | #include <linux/seqlock.h> | |
851a67b8 | 41 | #include <linux/lockdep.h> |
4446a36f | 42 | #include <linux/completion.h> |
551d55a9 | 43 | #include <linux/debugobjects.h> |
1da177e4 | 44 | |
e5ab6772 DY |
45 | #ifdef CONFIG_RCU_TORTURE_TEST |
46 | extern int rcutorture_runnable; /* for sysctl */ | |
47 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ | |
48 | ||
1da177e4 LT |
49 | /** |
50 | * struct rcu_head - callback structure for use with RCU | |
51 | * @next: next update requests in a list | |
52 | * @func: actual update function to call after the grace period. | |
53 | */ | |
54 | struct rcu_head { | |
55 | struct rcu_head *next; | |
56 | void (*func)(struct rcu_head *head); | |
57 | }; | |
58 | ||
03b042bf | 59 | /* Exported common interfaces */ |
03b042bf PM |
60 | extern void rcu_barrier(void); |
61 | extern void rcu_barrier_bh(void); | |
62 | extern void rcu_barrier_sched(void); | |
63 | extern void synchronize_sched_expedited(void); | |
64 | extern int sched_expedited_torture_stats(char *page); | |
65 | ||
66 | /* Internal to kernel */ | |
67 | extern void rcu_init(void); | |
a6826048 | 68 | |
f41d911f | 69 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) |
64db4cff | 70 | #include <linux/rcutree.h> |
2c28e245 | 71 | #elif defined(CONFIG_TINY_RCU) |
9b1d82fa | 72 | #include <linux/rcutiny.h> |
64db4cff PM |
73 | #else |
74 | #error "Unknown RCU implementation specified to kernel configuration" | |
6b3ef48a | 75 | #endif |
01c1c660 | 76 | |
3d76c082 | 77 | #define RCU_HEAD_INIT { .next = NULL, .func = NULL } |
8b6490e5 | 78 | #define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT |
1da177e4 LT |
79 | #define INIT_RCU_HEAD(ptr) do { \ |
80 | (ptr)->next = NULL; (ptr)->func = NULL; \ | |
81 | } while (0) | |
82 | ||
551d55a9 MD |
83 | /* |
84 | * init_rcu_head_on_stack()/destroy_rcu_head_on_stack() are needed for dynamic | |
85 | * initialization and destruction of rcu_head on the stack. rcu_head structures | |
86 | * allocated dynamically in the heap or defined statically don't need any | |
87 | * initialization. | |
88 | */ | |
89 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD | |
90 | extern void init_rcu_head_on_stack(struct rcu_head *head); | |
91 | extern void destroy_rcu_head_on_stack(struct rcu_head *head); | |
92 | #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
4376030a MD |
93 | static inline void init_rcu_head_on_stack(struct rcu_head *head) |
94 | { | |
95 | } | |
96 | ||
97 | static inline void destroy_rcu_head_on_stack(struct rcu_head *head) | |
98 | { | |
99 | } | |
551d55a9 | 100 | #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
4376030a | 101 | |
bc33f24b | 102 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
632ee200 | 103 | |
bc33f24b | 104 | extern struct lockdep_map rcu_lock_map; |
632ee200 PM |
105 | # define rcu_read_acquire() \ |
106 | lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | |
bc33f24b | 107 | # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_) |
632ee200 PM |
108 | |
109 | extern struct lockdep_map rcu_bh_lock_map; | |
110 | # define rcu_read_acquire_bh() \ | |
111 | lock_acquire(&rcu_bh_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | |
112 | # define rcu_read_release_bh() lock_release(&rcu_bh_lock_map, 1, _THIS_IP_) | |
113 | ||
114 | extern struct lockdep_map rcu_sched_lock_map; | |
115 | # define rcu_read_acquire_sched() \ | |
116 | lock_acquire(&rcu_sched_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | |
117 | # define rcu_read_release_sched() \ | |
118 | lock_release(&rcu_sched_lock_map, 1, _THIS_IP_) | |
119 | ||
bc293d62 | 120 | extern int debug_lockdep_rcu_enabled(void); |
54dbf96c | 121 | |
632ee200 PM |
122 | /** |
123 | * rcu_read_lock_held - might we be in RCU read-side critical section? | |
124 | * | |
d20200b5 PM |
125 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU |
126 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, | |
632ee200 PM |
127 | * this assumes we are in an RCU read-side critical section unless it can |
128 | * prove otherwise. | |
54dbf96c | 129 | * |
32c141a0 PM |
130 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot |
131 | * and while lockdep is disabled. | |
632ee200 PM |
132 | */ |
133 | static inline int rcu_read_lock_held(void) | |
134 | { | |
54dbf96c PM |
135 | if (!debug_lockdep_rcu_enabled()) |
136 | return 1; | |
137 | return lock_is_held(&rcu_lock_map); | |
632ee200 PM |
138 | } |
139 | ||
e3818b8d PM |
140 | /* |
141 | * rcu_read_lock_bh_held() is defined out of line to avoid #include-file | |
142 | * hell. | |
632ee200 | 143 | */ |
e3818b8d | 144 | extern int rcu_read_lock_bh_held(void); |
632ee200 PM |
145 | |
146 | /** | |
147 | * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section? | |
148 | * | |
d20200b5 PM |
149 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an |
150 | * RCU-sched read-side critical section. In absence of | |
151 | * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side | |
152 | * critical section unless it can prove otherwise. Note that disabling | |
153 | * of preemption (including disabling irqs) counts as an RCU-sched | |
154 | * read-side critical section. | |
54dbf96c | 155 | * |
32c141a0 PM |
156 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot |
157 | * and while lockdep is disabled. | |
632ee200 | 158 | */ |
e6033e3b | 159 | #ifdef CONFIG_PREEMPT |
632ee200 PM |
160 | static inline int rcu_read_lock_sched_held(void) |
161 | { | |
162 | int lockdep_opinion = 0; | |
163 | ||
54dbf96c PM |
164 | if (!debug_lockdep_rcu_enabled()) |
165 | return 1; | |
632ee200 PM |
166 | if (debug_locks) |
167 | lockdep_opinion = lock_is_held(&rcu_sched_lock_map); | |
0cff810f | 168 | return lockdep_opinion || preempt_count() != 0 || irqs_disabled(); |
632ee200 | 169 | } |
e6033e3b PM |
170 | #else /* #ifdef CONFIG_PREEMPT */ |
171 | static inline int rcu_read_lock_sched_held(void) | |
172 | { | |
173 | return 1; | |
632ee200 | 174 | } |
e6033e3b | 175 | #endif /* #else #ifdef CONFIG_PREEMPT */ |
632ee200 PM |
176 | |
177 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | |
178 | ||
179 | # define rcu_read_acquire() do { } while (0) | |
180 | # define rcu_read_release() do { } while (0) | |
181 | # define rcu_read_acquire_bh() do { } while (0) | |
182 | # define rcu_read_release_bh() do { } while (0) | |
183 | # define rcu_read_acquire_sched() do { } while (0) | |
184 | # define rcu_read_release_sched() do { } while (0) | |
185 | ||
186 | static inline int rcu_read_lock_held(void) | |
187 | { | |
188 | return 1; | |
189 | } | |
190 | ||
191 | static inline int rcu_read_lock_bh_held(void) | |
192 | { | |
193 | return 1; | |
194 | } | |
195 | ||
e6033e3b | 196 | #ifdef CONFIG_PREEMPT |
632ee200 PM |
197 | static inline int rcu_read_lock_sched_held(void) |
198 | { | |
bbad9379 | 199 | return preempt_count() != 0 || irqs_disabled(); |
632ee200 | 200 | } |
e6033e3b PM |
201 | #else /* #ifdef CONFIG_PREEMPT */ |
202 | static inline int rcu_read_lock_sched_held(void) | |
203 | { | |
204 | return 1; | |
632ee200 | 205 | } |
e6033e3b | 206 | #endif /* #else #ifdef CONFIG_PREEMPT */ |
632ee200 PM |
207 | |
208 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | |
209 | ||
210 | #ifdef CONFIG_PROVE_RCU | |
211 | ||
ee84b824 PM |
212 | extern int rcu_my_thread_group_empty(void); |
213 | ||
2b3fc35f LJ |
214 | #define __do_rcu_dereference_check(c) \ |
215 | do { \ | |
216 | static bool __warned; \ | |
217 | if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \ | |
218 | __warned = true; \ | |
219 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | |
220 | } \ | |
221 | } while (0) | |
222 | ||
632ee200 PM |
223 | /** |
224 | * rcu_dereference_check - rcu_dereference with debug checking | |
c08c68dd DH |
225 | * @p: The pointer to read, prior to dereferencing |
226 | * @c: The conditions under which the dereference will take place | |
632ee200 | 227 | * |
c08c68dd DH |
228 | * Do an rcu_dereference(), but check that the conditions under which the |
229 | * dereference will take place are correct. Typically the conditions indicate | |
230 | * the various locking conditions that should be held at that point. The check | |
231 | * should return true if the conditions are satisfied. | |
232 | * | |
233 | * For example: | |
234 | * | |
235 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | |
236 | * lockdep_is_held(&foo->lock)); | |
237 | * | |
238 | * could be used to indicate to lockdep that foo->bar may only be dereferenced | |
239 | * if either the RCU read lock is held, or that the lock required to replace | |
240 | * the bar struct at foo->bar is held. | |
241 | * | |
242 | * Note that the list of conditions may also include indications of when a lock | |
243 | * need not be held, for example during initialisation or destruction of the | |
244 | * target struct: | |
245 | * | |
246 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | |
247 | * lockdep_is_held(&foo->lock) || | |
248 | * atomic_read(&foo->usage) == 0); | |
632ee200 PM |
249 | */ |
250 | #define rcu_dereference_check(p, c) \ | |
251 | ({ \ | |
2b3fc35f | 252 | __do_rcu_dereference_check(c); \ |
c26d34a5 | 253 | rcu_dereference_raw(p); \ |
632ee200 PM |
254 | }) |
255 | ||
b62730ba PM |
256 | /** |
257 | * rcu_dereference_protected - fetch RCU pointer when updates prevented | |
258 | * | |
259 | * Return the value of the specified RCU-protected pointer, but omit | |
260 | * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This | |
261 | * is useful in cases where update-side locks prevent the value of the | |
262 | * pointer from changing. Please note that this primitive does -not- | |
263 | * prevent the compiler from repeating this reference or combining it | |
264 | * with other references, so it should not be used without protection | |
265 | * of appropriate locks. | |
266 | */ | |
267 | #define rcu_dereference_protected(p, c) \ | |
268 | ({ \ | |
2b3fc35f | 269 | __do_rcu_dereference_check(c); \ |
b62730ba PM |
270 | (p); \ |
271 | }) | |
272 | ||
632ee200 PM |
273 | #else /* #ifdef CONFIG_PROVE_RCU */ |
274 | ||
c26d34a5 | 275 | #define rcu_dereference_check(p, c) rcu_dereference_raw(p) |
b62730ba | 276 | #define rcu_dereference_protected(p, c) (p) |
632ee200 PM |
277 | |
278 | #endif /* #else #ifdef CONFIG_PROVE_RCU */ | |
bc33f24b | 279 | |
b62730ba PM |
280 | /** |
281 | * rcu_access_pointer - fetch RCU pointer with no dereferencing | |
282 | * | |
283 | * Return the value of the specified RCU-protected pointer, but omit the | |
284 | * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful | |
285 | * when the value of this pointer is accessed, but the pointer is not | |
286 | * dereferenced, for example, when testing an RCU-protected pointer against | |
287 | * NULL. This may also be used in cases where update-side locks prevent | |
288 | * the value of the pointer from changing, but rcu_dereference_protected() | |
289 | * is a lighter-weight primitive for this use case. | |
290 | */ | |
291 | #define rcu_access_pointer(p) ACCESS_ONCE(p) | |
292 | ||
1da177e4 LT |
293 | /** |
294 | * rcu_read_lock - mark the beginning of an RCU read-side critical section. | |
295 | * | |
9b06e818 | 296 | * When synchronize_rcu() is invoked on one CPU while other CPUs |
1da177e4 | 297 | * are within RCU read-side critical sections, then the |
9b06e818 | 298 | * synchronize_rcu() is guaranteed to block until after all the other |
1da177e4 LT |
299 | * CPUs exit their critical sections. Similarly, if call_rcu() is invoked |
300 | * on one CPU while other CPUs are within RCU read-side critical | |
301 | * sections, invocation of the corresponding RCU callback is deferred | |
302 | * until after the all the other CPUs exit their critical sections. | |
303 | * | |
304 | * Note, however, that RCU callbacks are permitted to run concurrently | |
305 | * with RCU read-side critical sections. One way that this can happen | |
306 | * is via the following sequence of events: (1) CPU 0 enters an RCU | |
307 | * read-side critical section, (2) CPU 1 invokes call_rcu() to register | |
308 | * an RCU callback, (3) CPU 0 exits the RCU read-side critical section, | |
309 | * (4) CPU 2 enters a RCU read-side critical section, (5) the RCU | |
310 | * callback is invoked. This is legal, because the RCU read-side critical | |
311 | * section that was running concurrently with the call_rcu() (and which | |
312 | * therefore might be referencing something that the corresponding RCU | |
313 | * callback would free up) has completed before the corresponding | |
314 | * RCU callback is invoked. | |
315 | * | |
316 | * RCU read-side critical sections may be nested. Any deferred actions | |
317 | * will be deferred until the outermost RCU read-side critical section | |
318 | * completes. | |
319 | * | |
320 | * It is illegal to block while in an RCU read-side critical section. | |
321 | */ | |
bc33f24b PM |
322 | static inline void rcu_read_lock(void) |
323 | { | |
324 | __rcu_read_lock(); | |
325 | __acquire(RCU); | |
326 | rcu_read_acquire(); | |
327 | } | |
1da177e4 | 328 | |
1da177e4 LT |
329 | /* |
330 | * So where is rcu_write_lock()? It does not exist, as there is no | |
331 | * way for writers to lock out RCU readers. This is a feature, not | |
332 | * a bug -- this property is what provides RCU's performance benefits. | |
333 | * Of course, writers must coordinate with each other. The normal | |
334 | * spinlock primitives work well for this, but any other technique may be | |
335 | * used as well. RCU does not care how the writers keep out of each | |
336 | * others' way, as long as they do so. | |
337 | */ | |
3d76c082 PM |
338 | |
339 | /** | |
340 | * rcu_read_unlock - marks the end of an RCU read-side critical section. | |
341 | * | |
342 | * See rcu_read_lock() for more information. | |
343 | */ | |
bc33f24b PM |
344 | static inline void rcu_read_unlock(void) |
345 | { | |
346 | rcu_read_release(); | |
347 | __release(RCU); | |
348 | __rcu_read_unlock(); | |
349 | } | |
1da177e4 LT |
350 | |
351 | /** | |
352 | * rcu_read_lock_bh - mark the beginning of a softirq-only RCU critical section | |
353 | * | |
354 | * This is equivalent of rcu_read_lock(), but to be used when updates | |
355 | * are being done using call_rcu_bh(). Since call_rcu_bh() callbacks | |
356 | * consider completion of a softirq handler to be a quiescent state, | |
357 | * a process in RCU read-side critical section must be protected by | |
358 | * disabling softirqs. Read-side critical sections in interrupt context | |
359 | * can use just rcu_read_lock(). | |
360 | * | |
361 | */ | |
bc33f24b PM |
362 | static inline void rcu_read_lock_bh(void) |
363 | { | |
364 | __rcu_read_lock_bh(); | |
365 | __acquire(RCU_BH); | |
632ee200 | 366 | rcu_read_acquire_bh(); |
bc33f24b | 367 | } |
1da177e4 LT |
368 | |
369 | /* | |
370 | * rcu_read_unlock_bh - marks the end of a softirq-only RCU critical section | |
371 | * | |
372 | * See rcu_read_lock_bh() for more information. | |
373 | */ | |
bc33f24b PM |
374 | static inline void rcu_read_unlock_bh(void) |
375 | { | |
632ee200 | 376 | rcu_read_release_bh(); |
bc33f24b PM |
377 | __release(RCU_BH); |
378 | __rcu_read_unlock_bh(); | |
379 | } | |
1da177e4 | 380 | |
1c50b728 MD |
381 | /** |
382 | * rcu_read_lock_sched - mark the beginning of a RCU-classic critical section | |
383 | * | |
384 | * Should be used with either | |
385 | * - synchronize_sched() | |
386 | * or | |
387 | * - call_rcu_sched() and rcu_barrier_sched() | |
388 | * on the write-side to insure proper synchronization. | |
389 | */ | |
d6714c22 PM |
390 | static inline void rcu_read_lock_sched(void) |
391 | { | |
392 | preempt_disable(); | |
bc33f24b | 393 | __acquire(RCU_SCHED); |
632ee200 | 394 | rcu_read_acquire_sched(); |
d6714c22 | 395 | } |
1eba8f84 PM |
396 | |
397 | /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */ | |
7c614d64 | 398 | static inline notrace void rcu_read_lock_sched_notrace(void) |
d6714c22 PM |
399 | { |
400 | preempt_disable_notrace(); | |
bc33f24b | 401 | __acquire(RCU_SCHED); |
d6714c22 | 402 | } |
1c50b728 MD |
403 | |
404 | /* | |
405 | * rcu_read_unlock_sched - marks the end of a RCU-classic critical section | |
406 | * | |
407 | * See rcu_read_lock_sched for more information. | |
408 | */ | |
d6714c22 PM |
409 | static inline void rcu_read_unlock_sched(void) |
410 | { | |
632ee200 | 411 | rcu_read_release_sched(); |
bc33f24b | 412 | __release(RCU_SCHED); |
d6714c22 PM |
413 | preempt_enable(); |
414 | } | |
1eba8f84 PM |
415 | |
416 | /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */ | |
7c614d64 | 417 | static inline notrace void rcu_read_unlock_sched_notrace(void) |
d6714c22 | 418 | { |
bc33f24b | 419 | __release(RCU_SCHED); |
d6714c22 PM |
420 | preempt_enable_notrace(); |
421 | } | |
1c50b728 MD |
422 | |
423 | ||
1da177e4 | 424 | /** |
c26d34a5 PM |
425 | * rcu_dereference_raw - fetch an RCU-protected pointer |
426 | * | |
427 | * The caller must be within some flavor of RCU read-side critical | |
428 | * section, or must be otherwise preventing the pointer from changing, | |
429 | * for example, by holding an appropriate lock. This pointer may later | |
430 | * be safely dereferenced. It is the caller's responsibility to have | |
431 | * done the right thing, as this primitive does no checking of any kind. | |
1da177e4 LT |
432 | * |
433 | * Inserts memory barriers on architectures that require them | |
434 | * (currently only the Alpha), and, more importantly, documents | |
435 | * exactly which pointers are protected by RCU. | |
436 | */ | |
c26d34a5 | 437 | #define rcu_dereference_raw(p) ({ \ |
97b43032 | 438 | typeof(p) _________p1 = ACCESS_ONCE(p); \ |
1da177e4 LT |
439 | smp_read_barrier_depends(); \ |
440 | (_________p1); \ | |
441 | }) | |
442 | ||
c26d34a5 PM |
443 | /** |
444 | * rcu_dereference - fetch an RCU-protected pointer, checking for RCU | |
445 | * | |
446 | * Makes rcu_dereference_check() do the dirty work. | |
447 | */ | |
448 | #define rcu_dereference(p) \ | |
449 | rcu_dereference_check(p, rcu_read_lock_held()) | |
450 | ||
451 | /** | |
452 | * rcu_dereference_bh - fetch an RCU-protected pointer, checking for RCU-bh | |
453 | * | |
454 | * Makes rcu_dereference_check() do the dirty work. | |
455 | */ | |
456 | #define rcu_dereference_bh(p) \ | |
b3a084b9 | 457 | rcu_dereference_check(p, rcu_read_lock_bh_held() || irqs_disabled()) |
c26d34a5 PM |
458 | |
459 | /** | |
460 | * rcu_dereference_sched - fetch RCU-protected pointer, checking for RCU-sched | |
461 | * | |
462 | * Makes rcu_dereference_check() do the dirty work. | |
463 | */ | |
464 | #define rcu_dereference_sched(p) \ | |
465 | rcu_dereference_check(p, rcu_read_lock_sched_held()) | |
466 | ||
1da177e4 LT |
467 | /** |
468 | * rcu_assign_pointer - assign (publicize) a pointer to a newly | |
469 | * initialized structure that will be dereferenced by RCU read-side | |
470 | * critical sections. Returns the value assigned. | |
471 | * | |
472 | * Inserts memory barriers on architectures that require them | |
473 | * (pretty much all of them other than x86), and also prevents | |
474 | * the compiler from reordering the code that initializes the | |
475 | * structure after the pointer assignment. More importantly, this | |
476 | * call documents which pointers will be dereferenced by RCU read-side | |
477 | * code. | |
478 | */ | |
479 | ||
d99c4f6b PM |
480 | #define rcu_assign_pointer(p, v) \ |
481 | ({ \ | |
482 | if (!__builtin_constant_p(v) || \ | |
483 | ((v) != NULL)) \ | |
484 | smp_wmb(); \ | |
485 | (p) = (v); \ | |
486 | }) | |
1da177e4 | 487 | |
4446a36f PM |
488 | /* Infrastructure to implement the synchronize_() primitives. */ |
489 | ||
490 | struct rcu_synchronize { | |
491 | struct rcu_head head; | |
492 | struct completion completion; | |
493 | }; | |
494 | ||
495 | extern void wakeme_after_rcu(struct rcu_head *head); | |
496 | ||
01c1c660 PM |
497 | /** |
498 | * call_rcu - Queue an RCU callback for invocation after a grace period. | |
499 | * @head: structure to be used for queueing the RCU updates. | |
500 | * @func: actual update function to be invoked after the grace period | |
501 | * | |
502 | * The update function will be invoked some time after a full grace | |
503 | * period elapses, in other words after all currently executing RCU | |
504 | * read-side critical sections have completed. RCU read-side critical | |
505 | * sections are delimited by rcu_read_lock() and rcu_read_unlock(), | |
506 | * and may be nested. | |
507 | */ | |
508 | extern void call_rcu(struct rcu_head *head, | |
509 | void (*func)(struct rcu_head *head)); | |
510 | ||
511 | /** | |
512 | * call_rcu_bh - Queue an RCU for invocation after a quicker grace period. | |
513 | * @head: structure to be used for queueing the RCU updates. | |
514 | * @func: actual update function to be invoked after the grace period | |
515 | * | |
516 | * The update function will be invoked some time after a full grace | |
517 | * period elapses, in other words after all currently executing RCU | |
518 | * read-side critical sections have completed. call_rcu_bh() assumes | |
519 | * that the read-side critical sections end on completion of a softirq | |
520 | * handler. This means that read-side critical sections in process | |
521 | * context must not be interrupted by softirqs. This interface is to be | |
522 | * used when most of the read-side critical sections are in softirq context. | |
523 | * RCU read-side critical sections are delimited by : | |
524 | * - rcu_read_lock() and rcu_read_unlock(), if in interrupt context. | |
525 | * OR | |
526 | * - rcu_read_lock_bh() and rcu_read_unlock_bh(), if in process context. | |
527 | * These may be nested. | |
528 | */ | |
529 | extern void call_rcu_bh(struct rcu_head *head, | |
530 | void (*func)(struct rcu_head *head)); | |
531 | ||
551d55a9 MD |
532 | /* |
533 | * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally | |
534 | * by call_rcu() and rcu callback execution, and are therefore not part of the | |
535 | * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors. | |
536 | */ | |
537 | ||
538 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD | |
539 | # define STATE_RCU_HEAD_READY 0 | |
540 | # define STATE_RCU_HEAD_QUEUED 1 | |
541 | ||
542 | extern struct debug_obj_descr rcuhead_debug_descr; | |
543 | ||
544 | static inline void debug_rcu_head_queue(struct rcu_head *head) | |
545 | { | |
546 | debug_object_activate(head, &rcuhead_debug_descr); | |
547 | debug_object_active_state(head, &rcuhead_debug_descr, | |
548 | STATE_RCU_HEAD_READY, | |
549 | STATE_RCU_HEAD_QUEUED); | |
550 | } | |
551 | ||
552 | static inline void debug_rcu_head_unqueue(struct rcu_head *head) | |
553 | { | |
554 | debug_object_active_state(head, &rcuhead_debug_descr, | |
555 | STATE_RCU_HEAD_QUEUED, | |
556 | STATE_RCU_HEAD_READY); | |
557 | debug_object_deactivate(head, &rcuhead_debug_descr); | |
558 | } | |
559 | #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
560 | static inline void debug_rcu_head_queue(struct rcu_head *head) | |
561 | { | |
562 | } | |
563 | ||
564 | static inline void debug_rcu_head_unqueue(struct rcu_head *head) | |
565 | { | |
566 | } | |
567 | #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
568 | ||
f5155b33 PM |
569 | #ifndef CONFIG_PROVE_RCU |
570 | #define __do_rcu_dereference_check(c) do { } while (0) | |
571 | #endif /* #ifdef CONFIG_PROVE_RCU */ | |
572 | ||
573 | #define __rcu_dereference_index_check(p, c) \ | |
574 | ({ \ | |
575 | typeof(p) _________p1 = ACCESS_ONCE(p); \ | |
576 | __do_rcu_dereference_check(c); \ | |
577 | smp_read_barrier_depends(); \ | |
578 | (_________p1); \ | |
579 | }) | |
580 | ||
581 | /** | |
582 | * rcu_dereference_index_check() - rcu_dereference for indices with debug checking | |
583 | * @p: The pointer to read, prior to dereferencing | |
584 | * @c: The conditions under which the dereference will take place | |
585 | * | |
586 | * Similar to rcu_dereference_check(), but omits the sparse checking. | |
587 | * This allows rcu_dereference_index_check() to be used on integers, | |
588 | * which can then be used as array indices. Attempting to use | |
589 | * rcu_dereference_check() on an integer will give compiler warnings | |
590 | * because the sparse address-space mechanism relies on dereferencing | |
591 | * the RCU-protected pointer. Dereferencing integers is not something | |
592 | * that even gcc will put up with. | |
593 | * | |
594 | * Note that this function does not implicitly check for RCU read-side | |
595 | * critical sections. If this function gains lots of uses, it might | |
596 | * make sense to provide versions for each flavor of RCU, but it does | |
597 | * not make sense as of early 2010. | |
598 | */ | |
599 | #define rcu_dereference_index_check(p, c) \ | |
600 | __rcu_dereference_index_check((p), (c)) | |
601 | ||
1da177e4 | 602 | #endif /* __LINUX_RCUPDATE_H */ |