rcu_segcblist.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * RCU segmented callback lists, internal-to-rcu header file
  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, you can access it online at
  16. * http://www.gnu.org/licenses/gpl-2.0.html.
  17. *
  18. * Copyright IBM Corporation, 2017
  19. *
  20. * Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  21. */
  22. #include <linux/rcu_segcblist.h>
  23. /*
  24. * Account for the fact that a previously dequeued callback turned out
  25. * to be marked as lazy.
  26. */
  27. static inline void rcu_cblist_dequeued_lazy(struct rcu_cblist *rclp)
  28. {
  29. rclp->len_lazy--;
  30. }
  31. /*
  32. * Interim function to return rcu_cblist head pointer. Longer term, the
  33. * rcu_cblist will be used more pervasively, removing the need for this
  34. * function.
  35. */
  36. static inline struct rcu_head *rcu_cblist_head(struct rcu_cblist *rclp)
  37. {
  38. return rclp->head;
  39. }
  40. /*
  41. * Interim function to return rcu_cblist head pointer. Longer term, the
  42. * rcu_cblist will be used more pervasively, removing the need for this
  43. * function.
  44. */
  45. static inline struct rcu_head **rcu_cblist_tail(struct rcu_cblist *rclp)
  46. {
  47. WARN_ON_ONCE(!rclp->head);
  48. return rclp->tail;
  49. }
  50. void rcu_cblist_init(struct rcu_cblist *rclp);
  51. long rcu_cblist_count_cbs(struct rcu_cblist *rclp, long lim);
  52. struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp);
  53. /*
  54. * Is the specified rcu_segcblist structure empty?
  55. *
  56. * But careful! The fact that the ->head field is NULL does not
  57. * necessarily imply that there are no callbacks associated with
  58. * this structure. When callbacks are being invoked, they are
  59. * removed as a group. If callback invocation must be preempted,
  60. * the remaining callbacks will be added back to the list. Either
  61. * way, the counts are updated later.
  62. *
  63. * So it is often the case that rcu_segcblist_n_cbs() should be used
  64. * instead.
  65. */
  66. static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp)
  67. {
  68. return !rsclp->head;
  69. }
  70. /* Return number of callbacks in segmented callback list. */
  71. static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)
  72. {
  73. return READ_ONCE(rsclp->len);
  74. }
  75. /* Return number of lazy callbacks in segmented callback list. */
  76. static inline long rcu_segcblist_n_lazy_cbs(struct rcu_segcblist *rsclp)
  77. {
  78. return rsclp->len_lazy;
  79. }
  80. /* Return number of lazy callbacks in segmented callback list. */
  81. static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp)
  82. {
  83. return rsclp->len - rsclp->len_lazy;
  84. }
  85. /*
  86. * Is the specified rcu_segcblist enabled, for example, not corresponding
  87. * to an offline or callback-offloaded CPU?
  88. */
  89. static inline bool rcu_segcblist_is_enabled(struct rcu_segcblist *rsclp)
  90. {
  91. return !!rsclp->tails[RCU_NEXT_TAIL];
  92. }
  93. /*
  94. * Are all segments following the specified segment of the specified
  95. * rcu_segcblist structure empty of callbacks? (The specified
  96. * segment might well contain callbacks.)
  97. */
  98. static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg)
  99. {
  100. return !*rsclp->tails[seg];
  101. }
  102. /*
  103. * Interim function to return rcu_segcblist head pointer. Longer term, the
  104. * rcu_segcblist will be used more pervasively, removing the need for this
  105. * function.
  106. */
  107. static inline struct rcu_head *rcu_segcblist_head(struct rcu_segcblist *rsclp)
  108. {
  109. return rsclp->head;
  110. }
  111. /*
  112. * Interim function to return rcu_segcblist head pointer. Longer term, the
  113. * rcu_segcblist will be used more pervasively, removing the need for this
  114. * function.
  115. */
  116. static inline struct rcu_head **rcu_segcblist_tail(struct rcu_segcblist *rsclp)
  117. {
  118. WARN_ON_ONCE(rcu_segcblist_empty(rsclp));
  119. return rsclp->tails[RCU_NEXT_TAIL];
  120. }
  121. void rcu_segcblist_init(struct rcu_segcblist *rsclp);
  122. void rcu_segcblist_disable(struct rcu_segcblist *rsclp);
  123. bool rcu_segcblist_segempty(struct rcu_segcblist *rsclp, int seg);
  124. bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp);
  125. bool rcu_segcblist_pend_cbs(struct rcu_segcblist *rsclp);
  126. struct rcu_head *rcu_segcblist_dequeue(struct rcu_segcblist *rsclp);
  127. void rcu_segcblist_dequeued_lazy(struct rcu_segcblist *rsclp);
  128. struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp);
  129. struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
  130. bool rcu_segcblist_new_cbs(struct rcu_segcblist *rsclp);
  131. void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
  132. struct rcu_head *rhp, bool lazy);
  133. bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
  134. struct rcu_head *rhp, bool lazy);
  135. void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
  136. struct rcu_cblist *rclp);
  137. void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
  138. struct rcu_cblist *rclp);
  139. void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp,
  140. struct rcu_cblist *rclp);
  141. void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
  142. struct rcu_cblist *rclp);
  143. void rcu_segcblist_insert_done_cbs(struct rcu_segcblist *rsclp,
  144. struct rcu_cblist *rclp);
  145. void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp,
  146. struct rcu_cblist *rclp);
  147. void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq);
  148. bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq);
  149. bool rcu_segcblist_future_gp_needed(struct rcu_segcblist *rsclp,
  150. unsigned long seq);