rcupdate.h 23 KB

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