rcu_segcblist.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. void rcu_cblist_init(struct rcu_cblist *rclp);
  32. struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp);
  33. /*
  34. * Is the specified rcu_segcblist structure empty?
  35. *
  36. * But careful! The fact that the ->head field is NULL does not
  37. * necessarily imply that there are no callbacks associated with
  38. * this structure. When callbacks are being invoked, they are
  39. * removed as a group. If callback invocation must be preempted,
  40. * the remaining callbacks will be added back to the list. Either
  41. * way, the counts are updated later.
  42. *
  43. * So it is often the case that rcu_segcblist_n_cbs() should be used
  44. * instead.
  45. */
  46. static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp)
  47. {
  48. return !rsclp->head;
  49. }
  50. /* Return number of callbacks in segmented callback list. */
  51. static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)
  52. {
  53. return READ_ONCE(rsclp->len);
  54. }
  55. /* Return number of lazy callbacks in segmented callback list. */
  56. static inline long rcu_segcblist_n_lazy_cbs(struct rcu_segcblist *rsclp)
  57. {
  58. return rsclp->len_lazy;
  59. }
  60. /* Return number of lazy callbacks in segmented callback list. */
  61. static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp)
  62. {
  63. return rsclp->len - rsclp->len_lazy;
  64. }
  65. /*
  66. * Is the specified rcu_segcblist enabled, for example, not corresponding
  67. * to an offline or callback-offloaded CPU?
  68. */
  69. static inline bool rcu_segcblist_is_enabled(struct rcu_segcblist *rsclp)
  70. {
  71. return !!rsclp->tails[RCU_NEXT_TAIL];
  72. }
  73. /*
  74. * Are all segments following the specified segment of the specified
  75. * rcu_segcblist structure empty of callbacks? (The specified
  76. * segment might well contain callbacks.)
  77. */
  78. static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg)
  79. {
  80. return !*rsclp->tails[seg];
  81. }
  82. /*
  83. * Interim function to return rcu_segcblist head pointer. Longer term, the
  84. * rcu_segcblist will be used more pervasively, removing the need for this
  85. * function.
  86. */
  87. static inline struct rcu_head *rcu_segcblist_head(struct rcu_segcblist *rsclp)
  88. {
  89. return rsclp->head;
  90. }
  91. /*
  92. * Interim function to return rcu_segcblist head pointer. Longer term, the
  93. * rcu_segcblist will be used more pervasively, removing the need for this
  94. * function.
  95. */
  96. static inline struct rcu_head **rcu_segcblist_tail(struct rcu_segcblist *rsclp)
  97. {
  98. WARN_ON_ONCE(rcu_segcblist_empty(rsclp));
  99. return rsclp->tails[RCU_NEXT_TAIL];
  100. }
  101. void rcu_segcblist_init(struct rcu_segcblist *rsclp);
  102. void rcu_segcblist_disable(struct rcu_segcblist *rsclp);
  103. bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp);
  104. bool rcu_segcblist_pend_cbs(struct rcu_segcblist *rsclp);
  105. struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp);
  106. struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
  107. void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
  108. struct rcu_head *rhp, bool lazy);
  109. bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
  110. struct rcu_head *rhp, bool lazy);
  111. void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
  112. struct rcu_cblist *rclp);
  113. void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
  114. struct rcu_cblist *rclp);
  115. void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp,
  116. struct rcu_cblist *rclp);
  117. void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
  118. struct rcu_cblist *rclp);
  119. void rcu_segcblist_insert_done_cbs(struct rcu_segcblist *rsclp,
  120. struct rcu_cblist *rclp);
  121. void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp,
  122. struct rcu_cblist *rclp);
  123. void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq);
  124. bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq);
  125. bool rcu_segcblist_future_gp_needed(struct rcu_segcblist *rsclp,
  126. unsigned long seq);
  127. void rcu_segcblist_merge(struct rcu_segcblist *dst_rsclp,
  128. struct rcu_segcblist *src_rsclp);