rcutiny.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition.
  4. *
  5. * Copyright IBM Corporation, 2008
  6. *
  7. * Author: Paul E. McKenney <[email protected]>
  8. *
  9. * For detailed explanation of Read-Copy Update mechanism see -
  10. * Documentation/RCU
  11. */
  12. #ifndef __LINUX_TINY_H
  13. #define __LINUX_TINY_H
  14. #include <asm/param.h> /* for HZ */
  15. struct rcu_gp_oldstate {
  16. unsigned long rgos_norm;
  17. };
  18. // Maximum number of rcu_gp_oldstate values corresponding to
  19. // not-yet-completed RCU grace periods.
  20. #define NUM_ACTIVE_RCU_POLL_FULL_OLDSTATE 2
  21. /*
  22. * Are the two oldstate values the same? See the Tree RCU version for
  23. * docbook header.
  24. */
  25. static inline bool same_state_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp1,
  26. struct rcu_gp_oldstate *rgosp2)
  27. {
  28. return rgosp1->rgos_norm == rgosp2->rgos_norm;
  29. }
  30. unsigned long get_state_synchronize_rcu(void);
  31. static inline void get_state_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp)
  32. {
  33. rgosp->rgos_norm = get_state_synchronize_rcu();
  34. }
  35. unsigned long start_poll_synchronize_rcu(void);
  36. static inline void start_poll_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp)
  37. {
  38. rgosp->rgos_norm = start_poll_synchronize_rcu();
  39. }
  40. bool poll_state_synchronize_rcu(unsigned long oldstate);
  41. static inline bool poll_state_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp)
  42. {
  43. return poll_state_synchronize_rcu(rgosp->rgos_norm);
  44. }
  45. static inline void cond_synchronize_rcu(unsigned long oldstate)
  46. {
  47. might_sleep();
  48. }
  49. static inline void cond_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp)
  50. {
  51. cond_synchronize_rcu(rgosp->rgos_norm);
  52. }
  53. static inline unsigned long start_poll_synchronize_rcu_expedited(void)
  54. {
  55. return start_poll_synchronize_rcu();
  56. }
  57. static inline void start_poll_synchronize_rcu_expedited_full(struct rcu_gp_oldstate *rgosp)
  58. {
  59. rgosp->rgos_norm = start_poll_synchronize_rcu_expedited();
  60. }
  61. static inline void cond_synchronize_rcu_expedited(unsigned long oldstate)
  62. {
  63. cond_synchronize_rcu(oldstate);
  64. }
  65. static inline void cond_synchronize_rcu_expedited_full(struct rcu_gp_oldstate *rgosp)
  66. {
  67. cond_synchronize_rcu_expedited(rgosp->rgos_norm);
  68. }
  69. extern void rcu_barrier(void);
  70. static inline void synchronize_rcu_expedited(void)
  71. {
  72. synchronize_rcu();
  73. }
  74. /*
  75. * Add one more declaration of kvfree() here. It is
  76. * not so straight forward to just include <linux/mm.h>
  77. * where it is defined due to getting many compile
  78. * errors caused by that include.
  79. */
  80. extern void kvfree(const void *addr);
  81. static inline void __kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
  82. {
  83. if (head) {
  84. call_rcu(head, func);
  85. return;
  86. }
  87. // kvfree_rcu(one_arg) call.
  88. might_sleep();
  89. synchronize_rcu();
  90. kvfree((void *) func);
  91. }
  92. #ifdef CONFIG_KASAN_GENERIC
  93. void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func);
  94. #else
  95. static inline void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
  96. {
  97. __kvfree_call_rcu(head, func);
  98. }
  99. #endif
  100. void rcu_qs(void);
  101. static inline void rcu_softirq_qs(void)
  102. {
  103. rcu_qs();
  104. }
  105. #define rcu_note_context_switch(preempt) \
  106. do { \
  107. rcu_qs(); \
  108. rcu_tasks_qs(current, (preempt)); \
  109. } while (0)
  110. static inline int rcu_needs_cpu(void)
  111. {
  112. return 0;
  113. }
  114. /*
  115. * Take advantage of the fact that there is only one CPU, which
  116. * allows us to ignore virtualization-based context switches.
  117. */
  118. static inline void rcu_virt_note_context_switch(int cpu) { }
  119. static inline void rcu_cpu_stall_reset(void) { }
  120. static inline int rcu_jiffies_till_stall_check(void) { return 21 * HZ; }
  121. static inline void rcu_irq_exit_check_preempt(void) { }
  122. #define rcu_is_idle_cpu(cpu) \
  123. (is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq())
  124. static inline void exit_rcu(void) { }
  125. static inline bool rcu_preempt_need_deferred_qs(struct task_struct *t)
  126. {
  127. return false;
  128. }
  129. static inline void rcu_preempt_deferred_qs(struct task_struct *t) { }
  130. #ifdef CONFIG_SRCU
  131. void rcu_scheduler_starting(void);
  132. #else /* #ifndef CONFIG_SRCU */
  133. static inline void rcu_scheduler_starting(void) { }
  134. #endif /* #else #ifndef CONFIG_SRCU */
  135. static inline void rcu_end_inkernel_boot(void) { }
  136. static inline bool rcu_inkernel_boot_has_ended(void) { return true; }
  137. static inline bool rcu_is_watching(void) { return true; }
  138. static inline void rcu_momentary_dyntick_idle(void) { }
  139. static inline void kfree_rcu_scheduler_running(void) { }
  140. static inline bool rcu_gp_might_be_stalled(void) { return false; }
  141. /* Avoid RCU read-side critical sections leaking across. */
  142. static inline void rcu_all_qs(void) { barrier(); }
  143. /* RCUtree hotplug events */
  144. #define rcutree_prepare_cpu NULL
  145. #define rcutree_online_cpu NULL
  146. #define rcutree_offline_cpu NULL
  147. #define rcutree_dead_cpu NULL
  148. #define rcutree_dying_cpu NULL
  149. static inline void rcu_cpu_starting(unsigned int cpu) { }
  150. #endif /* __LINUX_RCUTINY_H */