33 #ifndef __LINUX_RCUPDATE_H
34 #define __LINUX_RCUPDATE_H
36 #include <linux/types.h>
46 #include <linux/compiler.h>
48 #ifdef CONFIG_RCU_TORTURE_TEST
52 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
64 #ifdef CONFIG_RCU_TRACE
68 #define do_trace_rcu_torture_read(rcutorturename, rhp) do { } while (0)
72 #define UINT_CMP_GE(a, b) (UINT_MAX / 2 >= (a) - (b))
73 #define UINT_CMP_LT(a, b) (UINT_MAX / 2 < (a) - (b))
74 #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
75 #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
79 #ifdef CONFIG_PREEMPT_RCU
100 #define call_rcu call_rcu_sched
146 #ifdef CONFIG_PREEMPT_RCU
148 extern void __rcu_read_lock(
void);
149 extern void __rcu_read_unlock(
void);
150 extern void rcu_read_unlock_special(
struct task_struct *
t);
151 void synchronize_rcu(
void);
159 #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
163 static inline void __rcu_read_lock(
void)
168 static inline void __rcu_read_unlock(
void)
173 static inline void synchronize_rcu(
void)
178 static inline int rcu_preempt_depth(
void)
195 #ifdef CONFIG_RCU_USER_QS
196 extern void rcu_user_enter(
void);
197 extern void rcu_user_exit(
void);
198 extern void rcu_user_enter_after_irq(
void);
199 extern void rcu_user_exit_after_irq(
void);
203 static inline void rcu_user_enter(
void) { }
204 static inline void rcu_user_exit(
void) { }
205 static inline void rcu_user_enter_after_irq(
void) { }
206 static inline void rcu_user_exit_after_irq(
void) { }
229 #define RCU_NONIDLE(a) \
232 do { a; } while (0); \
245 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
247 #elif defined(CONFIG_TINY_RCU) || defined(CONFIG_TINY_PREEMPT_RCU)
250 #error "Unknown RCU implementation specified to kernel configuration"
259 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
260 extern void init_rcu_head_on_stack(
struct rcu_head *head);
261 extern void destroy_rcu_head_on_stack(
struct rcu_head *head);
263 static inline void init_rcu_head_on_stack(
struct rcu_head *head)
267 static inline void destroy_rcu_head_on_stack(
struct rcu_head *head)
272 #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SMP)
276 #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PROVE_RCU)
277 bool rcu_lockdep_current_cpu_online(
void);
279 static inline bool rcu_lockdep_current_cpu_online(
void)
285 #ifdef CONFIG_DEBUG_LOCK_ALLOC
297 extern struct lockdep_map rcu_lock_map;
298 extern struct lockdep_map rcu_bh_lock_map;
299 extern struct lockdep_map rcu_sched_lock_map;
300 extern int debug_lockdep_rcu_enabled(
void);
322 static inline int rcu_read_lock_held(
void)
324 if (!debug_lockdep_rcu_enabled())
328 if (!rcu_lockdep_current_cpu_online())
337 extern int rcu_read_lock_bh_held(
void);
370 #ifdef CONFIG_PREEMPT_COUNT
371 static inline int rcu_read_lock_sched_held(
void)
373 int lockdep_opinion = 0;
375 if (!debug_lockdep_rcu_enabled())
379 if (!rcu_lockdep_current_cpu_online())
386 static inline int rcu_read_lock_sched_held(
void)
394 # define rcu_lock_acquire(a) do { } while (0)
395 # define rcu_lock_release(a) do { } while (0)
397 static inline int rcu_read_lock_held(
void)
402 static inline int rcu_read_lock_bh_held(
void)
407 #ifdef CONFIG_PREEMPT_COUNT
408 static inline int rcu_read_lock_sched_held(
void)
413 static inline int rcu_read_lock_sched_held(
void)
421 #ifdef CONFIG_PROVE_RCU
423 extern int rcu_my_thread_group_empty(
void);
430 #define rcu_lockdep_assert(c, s) \
432 static bool __section(.data.unlikely) __warned; \
433 if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
435 lockdep_rcu_suspicious(__FILE__, __LINE__, s); \
439 #if defined(CONFIG_PROVE_RCU) && !defined(CONFIG_PREEMPT_RCU)
440 static inline void rcu_preempt_sleep_check(
void)
443 "Illegal context switch in RCU read-side critical section");
446 static inline void rcu_preempt_sleep_check(
void)
451 #define rcu_sleep_check() \
453 rcu_preempt_sleep_check(); \
454 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map), \
455 "Illegal context switch in RCU-bh" \
456 " read-side critical section"); \
457 rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map), \
458 "Illegal context switch in RCU-sched"\
459 " read-side critical section"); \
464 #define rcu_lockdep_assert(c, s) do { } while (0)
465 #define rcu_sleep_check() do { } while (0)
479 #define rcu_dereference_sparse(p, space) \
480 ((void)(((typeof(*p) space *)p) == p))
482 #define rcu_dereference_sparse(p, space)
485 #define __rcu_access_pointer(p, space) \
487 typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \
488 rcu_dereference_sparse(p, space); \
489 ((typeof(*p) __force __kernel *)(_________p1)); \
491 #define __rcu_dereference_check(p, c, space) \
493 typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \
494 rcu_lockdep_assert(c, "suspicious rcu_dereference_check()" \
496 rcu_dereference_sparse(p, space); \
497 smp_read_barrier_depends(); \
498 ((typeof(*p) __force __kernel *)(_________p1)); \
500 #define __rcu_dereference_protected(p, c, space) \
502 rcu_lockdep_assert(c, "suspicious rcu_dereference_protected()" \
504 rcu_dereference_sparse(p, space); \
505 ((typeof(*p) __force __kernel *)(p)); \
508 #define __rcu_access_index(p, space) \
510 typeof(p) _________p1 = ACCESS_ONCE(p); \
511 rcu_dereference_sparse(p, space); \
514 #define __rcu_dereference_index_check(p, c) \
516 typeof(p) _________p1 = ACCESS_ONCE(p); \
517 rcu_lockdep_assert(c, \
518 "suspicious rcu_dereference_index_check()" \
520 smp_read_barrier_depends(); \
523 #define __rcu_assign_pointer(p, v, space) \
526 (p) = (typeof(*v) __force space *)(v); \
549 #define rcu_access_pointer(p) __rcu_access_pointer((p), __rcu)
584 #define rcu_dereference_check(p, c) \
585 __rcu_dereference_check((p), rcu_read_lock_held() || (c), __rcu)
594 #define rcu_dereference_bh_check(p, c) \
595 __rcu_dereference_check((p), rcu_read_lock_bh_held() || (c), __rcu)
604 #define rcu_dereference_sched_check(p, c) \
605 __rcu_dereference_check((p), rcu_read_lock_sched_held() || (c), \
608 #define rcu_dereference_raw(p) rcu_dereference_check(p, 1)
622 #define rcu_access_index(p) __rcu_access_index((p), __rcu)
642 #define rcu_dereference_index_check(p, c) \
643 __rcu_dereference_index_check((p), (c))
662 #define rcu_dereference_protected(p, c) \
663 __rcu_dereference_protected((p), (c), __rcu)
672 #define rcu_dereference(p) rcu_dereference_check(p, 0)
680 #define rcu_dereference_bh(p) rcu_dereference_bh_check(p, 0)
688 #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
732 static inline void rcu_read_lock(
void)
738 "rcu_read_lock() used illegally while idle");
756 static inline void rcu_read_unlock(
void)
759 "rcu_read_unlock() used illegally while idle");
782 static inline void rcu_read_lock_bh(
void)
788 "rcu_read_lock_bh() used illegally while idle");
796 static inline void rcu_read_unlock_bh(
void)
799 "rcu_read_unlock_bh() used illegally while idle");
818 static inline void rcu_read_lock_sched(
void)
824 "rcu_read_lock_sched() used illegally while idle");
828 static inline notrace void rcu_read_lock_sched_notrace(
void)
839 static inline void rcu_read_unlock_sched(
void)
842 "rcu_read_unlock_sched() used illegally while idle");
849 static inline notrace void rcu_read_unlock_sched_notrace(
void)
878 #define rcu_assign_pointer(p, v) \
879 __rcu_assign_pointer((p), (v), __rcu)
913 #define RCU_INIT_POINTER(p, v) \
915 p = (typeof(*v) __force __rcu *)(v); \
923 #define RCU_POINTER_INITIALIZER(p, v) \
924 .p = (typeof(*v) __force __rcu *)(v)
930 #define __is_kfree_rcu_offset(offset) ((offset) < 4096)
935 #define __kfree_rcu(head, offset) \
937 BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \
938 kfree_call_rcu(head, (void (*)(struct rcu_head *))(unsigned long)(offset)); \
967 #define kfree_rcu(ptr, rcu_head) \
968 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))