rcupdate.h 23 KB

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