Paul E. McKenney | eb7935e | 2019-01-17 10:13:19 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 2 | /* |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 3 | * RCU segmented callback lists, internal-to-rcu header file |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 4 | * |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 5 | * Copyright IBM Corporation, 2017 |
| 6 | * |
Paul E. McKenney | eb7935e | 2019-01-17 10:13:19 -0800 | [diff] [blame] | 7 | * Authors: Paul E. McKenney <paulmck@linux.ibm.com> |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/rcu_segcblist.h> |
| 11 | |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 12 | /* |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 13 | * Account for the fact that a previously dequeued callback turned out |
| 14 | * to be marked as lazy. |
| 15 | */ |
| 16 | static inline void rcu_cblist_dequeued_lazy(struct rcu_cblist *rclp) |
| 17 | { |
| 18 | rclp->len_lazy--; |
| 19 | } |
| 20 | |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 21 | void rcu_cblist_init(struct rcu_cblist *rclp); |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 22 | struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp); |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Is the specified rcu_segcblist structure empty? |
| 26 | * |
| 27 | * But careful! The fact that the ->head field is NULL does not |
| 28 | * necessarily imply that there are no callbacks associated with |
| 29 | * this structure. When callbacks are being invoked, they are |
| 30 | * removed as a group. If callback invocation must be preempted, |
| 31 | * the remaining callbacks will be added back to the list. Either |
| 32 | * way, the counts are updated later. |
| 33 | * |
| 34 | * So it is often the case that rcu_segcblist_n_cbs() should be used |
| 35 | * instead. |
| 36 | */ |
| 37 | static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp) |
| 38 | { |
Paul E. McKenney | e6060b4 | 2019-05-13 15:57:50 -0700 | [diff] [blame] | 39 | return !READ_ONCE(rsclp->head); |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* Return number of callbacks in segmented callback list. */ |
| 43 | static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp) |
| 44 | { |
| 45 | return READ_ONCE(rsclp->len); |
| 46 | } |
| 47 | |
| 48 | /* Return number of lazy callbacks in segmented callback list. */ |
| 49 | static inline long rcu_segcblist_n_lazy_cbs(struct rcu_segcblist *rsclp) |
| 50 | { |
| 51 | return rsclp->len_lazy; |
| 52 | } |
| 53 | |
| 54 | /* Return number of lazy callbacks in segmented callback list. */ |
| 55 | static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp) |
| 56 | { |
| 57 | return rsclp->len - rsclp->len_lazy; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Is the specified rcu_segcblist enabled, for example, not corresponding |
Paul E. McKenney | e83e73f | 2019-05-14 09:50:49 -0700 | [diff] [blame^] | 62 | * to an offline CPU? |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 63 | */ |
| 64 | static inline bool rcu_segcblist_is_enabled(struct rcu_segcblist *rsclp) |
| 65 | { |
Paul E. McKenney | 1bb5f9b | 2019-04-12 12:34:41 -0700 | [diff] [blame] | 66 | return rsclp->enabled; |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Paul E. McKenney | ce5215c | 2019-04-12 15:58:34 -0700 | [diff] [blame] | 69 | /* Is the specified rcu_segcblist offloaded? */ |
| 70 | static inline bool rcu_segcblist_is_offloaded(struct rcu_segcblist *rsclp) |
| 71 | { |
| 72 | return rsclp->offloaded; |
| 73 | } |
| 74 | |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 75 | /* |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 76 | * Are all segments following the specified segment of the specified |
| 77 | * rcu_segcblist structure empty of callbacks? (The specified |
| 78 | * segment might well contain callbacks.) |
| 79 | */ |
| 80 | static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg) |
| 81 | { |
Paul E. McKenney | 76c6927 | 2019-05-13 14:36:11 -0700 | [diff] [blame] | 82 | return !READ_ONCE(*READ_ONCE(rsclp->tails[seg])); |
Ingo Molnar | 45753c5 | 2017-05-02 10:31:18 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 85 | void rcu_segcblist_init(struct rcu_segcblist *rsclp); |
| 86 | void rcu_segcblist_disable(struct rcu_segcblist *rsclp); |
Paul E. McKenney | ce5215c | 2019-04-12 15:58:34 -0700 | [diff] [blame] | 87 | void rcu_segcblist_offload(struct rcu_segcblist *rsclp); |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 88 | bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp); |
| 89 | bool rcu_segcblist_pend_cbs(struct rcu_segcblist *rsclp); |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 90 | struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp); |
| 91 | struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp); |
Paul E. McKenney | 98059b9 | 2017-05-02 06:30:12 -0700 | [diff] [blame] | 92 | void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp, |
| 93 | struct rcu_head *rhp, bool lazy); |
| 94 | bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp, |
| 95 | struct rcu_head *rhp, bool lazy); |
| 96 | void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp, |
| 97 | struct rcu_cblist *rclp); |
| 98 | void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp, |
| 99 | struct rcu_cblist *rclp); |
| 100 | void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp, |
| 101 | struct rcu_cblist *rclp); |
| 102 | void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp, |
| 103 | struct rcu_cblist *rclp); |
| 104 | void rcu_segcblist_insert_done_cbs(struct rcu_segcblist *rsclp, |
| 105 | struct rcu_cblist *rclp); |
| 106 | void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp, |
| 107 | struct rcu_cblist *rclp); |
| 108 | void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq); |
| 109 | bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq); |
Paul E. McKenney | f2dbe4a | 2017-06-27 07:44:06 -0700 | [diff] [blame] | 110 | void rcu_segcblist_merge(struct rcu_segcblist *dst_rsclp, |
| 111 | struct rcu_segcblist *src_rsclp); |