Loading...
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * RCU segmented callback lists, internal-to-rcu header file
4 *
5 * Copyright IBM Corporation, 2017
6 *
7 * Authors: Paul E. McKenney <paulmck@linux.ibm.com>
8 */
9
10#include <linux/rcu_segcblist.h>
11
12/* Return number of callbacks in the specified callback list. */
13static inline long rcu_cblist_n_cbs(struct rcu_cblist *rclp)
14{
15 return READ_ONCE(rclp->len);
16}
17
18/* Return number of callbacks in segmented callback list by summing seglen. */
19long rcu_segcblist_n_segment_cbs(struct rcu_segcblist *rsclp);
20
21void rcu_cblist_init(struct rcu_cblist *rclp);
22void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp);
23void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp,
24 struct rcu_cblist *srclp,
25 struct rcu_head *rhp);
26struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp);
27
28/*
29 * Is the specified rcu_segcblist structure empty?
30 *
31 * But careful! The fact that the ->head field is NULL does not
32 * necessarily imply that there are no callbacks associated with
33 * this structure. When callbacks are being invoked, they are
34 * removed as a group. If callback invocation must be preempted,
35 * the remaining callbacks will be added back to the list. Either
36 * way, the counts are updated later.
37 *
38 * So it is often the case that rcu_segcblist_n_cbs() should be used
39 * instead.
40 */
41static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp)
42{
43 return !READ_ONCE(rsclp->head);
44}
45
46/* Return number of callbacks in segmented callback list. */
47static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)
48{
49#ifdef CONFIG_RCU_NOCB_CPU
50 return atomic_long_read(&rsclp->len);
51#else
52 return READ_ONCE(rsclp->len);
53#endif
54}
55
56static inline void rcu_segcblist_set_flags(struct rcu_segcblist *rsclp,
57 int flags)
58{
59 WRITE_ONCE(rsclp->flags, rsclp->flags | flags);
60}
61
62static inline void rcu_segcblist_clear_flags(struct rcu_segcblist *rsclp,
63 int flags)
64{
65 WRITE_ONCE(rsclp->flags, rsclp->flags & ~flags);
66}
67
68static inline bool rcu_segcblist_test_flags(struct rcu_segcblist *rsclp,
69 int flags)
70{
71 return READ_ONCE(rsclp->flags) & flags;
72}
73
74/*
75 * Is the specified rcu_segcblist enabled, for example, not corresponding
76 * to an offline CPU?
77 */
78static inline bool rcu_segcblist_is_enabled(struct rcu_segcblist *rsclp)
79{
80 return rcu_segcblist_test_flags(rsclp, SEGCBLIST_ENABLED);
81}
82
83/*
84 * Is the specified rcu_segcblist NOCB offloaded (or in the middle of the
85 * [de]offloading process)?
86 */
87static inline bool rcu_segcblist_is_offloaded(struct rcu_segcblist *rsclp)
88{
89 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU) &&
90 rcu_segcblist_test_flags(rsclp, SEGCBLIST_LOCKING))
91 return true;
92
93 return false;
94}
95
96static inline bool rcu_segcblist_completely_offloaded(struct rcu_segcblist *rsclp)
97{
98 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU) &&
99 !rcu_segcblist_test_flags(rsclp, SEGCBLIST_RCU_CORE))
100 return true;
101
102 return false;
103}
104
105/*
106 * Are all segments following the specified segment of the specified
107 * rcu_segcblist structure empty of callbacks? (The specified
108 * segment might well contain callbacks.)
109 */
110static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg)
111{
112 return !READ_ONCE(*READ_ONCE(rsclp->tails[seg]));
113}
114
115/*
116 * Is the specified segment of the specified rcu_segcblist structure
117 * empty of callbacks?
118 */
119static inline bool rcu_segcblist_segempty(struct rcu_segcblist *rsclp, int seg)
120{
121 if (seg == RCU_DONE_TAIL)
122 return &rsclp->head == rsclp->tails[RCU_DONE_TAIL];
123 return rsclp->tails[seg - 1] == rsclp->tails[seg];
124}
125
126void rcu_segcblist_inc_len(struct rcu_segcblist *rsclp);
127void rcu_segcblist_add_len(struct rcu_segcblist *rsclp, long v);
128void rcu_segcblist_init(struct rcu_segcblist *rsclp);
129void rcu_segcblist_disable(struct rcu_segcblist *rsclp);
130void rcu_segcblist_offload(struct rcu_segcblist *rsclp, bool offload);
131bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp);
132bool rcu_segcblist_pend_cbs(struct rcu_segcblist *rsclp);
133struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp);
134struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
135bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp);
136void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
137 struct rcu_head *rhp);
138bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
139 struct rcu_head *rhp);
140void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
141 struct rcu_cblist *rclp);
142void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp,
143 struct rcu_cblist *rclp);
144void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
145 struct rcu_cblist *rclp);
146void rcu_segcblist_insert_done_cbs(struct rcu_segcblist *rsclp,
147 struct rcu_cblist *rclp);
148void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp,
149 struct rcu_cblist *rclp);
150void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq);
151bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq);
152void rcu_segcblist_merge(struct rcu_segcblist *dst_rsclp,
153 struct rcu_segcblist *src_rsclp);
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
23#include <linux/rcu_segcblist.h>
24
25/*
26 * Account for the fact that a previously dequeued callback turned out
27 * to be marked as lazy.
28 */
29static inline void rcu_cblist_dequeued_lazy(struct rcu_cblist *rclp)
30{
31 rclp->len_lazy--;
32}
33
34void rcu_cblist_init(struct rcu_cblist *rclp);
35struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp);
36
37/*
38 * Is the specified rcu_segcblist structure empty?
39 *
40 * But careful! The fact that the ->head field is NULL does not
41 * necessarily imply that there are no callbacks associated with
42 * this structure. When callbacks are being invoked, they are
43 * removed as a group. If callback invocation must be preempted,
44 * the remaining callbacks will be added back to the list. Either
45 * way, the counts are updated later.
46 *
47 * So it is often the case that rcu_segcblist_n_cbs() should be used
48 * instead.
49 */
50static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp)
51{
52 return !rsclp->head;
53}
54
55/* Return number of callbacks in segmented callback list. */
56static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)
57{
58 return READ_ONCE(rsclp->len);
59}
60
61/* Return number of lazy callbacks in segmented callback list. */
62static inline long rcu_segcblist_n_lazy_cbs(struct rcu_segcblist *rsclp)
63{
64 return rsclp->len_lazy;
65}
66
67/* Return number of lazy callbacks in segmented callback list. */
68static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp)
69{
70 return rsclp->len - rsclp->len_lazy;
71}
72
73/*
74 * Is the specified rcu_segcblist enabled, for example, not corresponding
75 * to an offline or callback-offloaded CPU?
76 */
77static inline bool rcu_segcblist_is_enabled(struct rcu_segcblist *rsclp)
78{
79 return !!rsclp->tails[RCU_NEXT_TAIL];
80}
81
82/*
83 * Are all segments following the specified segment of the specified
84 * rcu_segcblist structure empty of callbacks? (The specified
85 * segment might well contain callbacks.)
86 */
87static inline bool rcu_segcblist_restempty(struct rcu_segcblist *rsclp, int seg)
88{
89 return !*rsclp->tails[seg];
90}
91
92/*
93 * Interim function to return rcu_segcblist head pointer. Longer term, the
94 * rcu_segcblist will be used more pervasively, removing the need for this
95 * function.
96 */
97static inline struct rcu_head *rcu_segcblist_head(struct rcu_segcblist *rsclp)
98{
99 return rsclp->head;
100}
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 */
107static inline struct rcu_head **rcu_segcblist_tail(struct rcu_segcblist *rsclp)
108{
109 WARN_ON_ONCE(rcu_segcblist_empty(rsclp));
110 return rsclp->tails[RCU_NEXT_TAIL];
111}
112
113void rcu_segcblist_init(struct rcu_segcblist *rsclp);
114void rcu_segcblist_disable(struct rcu_segcblist *rsclp);
115bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp);
116bool rcu_segcblist_pend_cbs(struct rcu_segcblist *rsclp);
117struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp);
118struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
119void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
120 struct rcu_head *rhp, bool lazy);
121bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
122 struct rcu_head *rhp, bool lazy);
123void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
124 struct rcu_cblist *rclp);
125void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
126 struct rcu_cblist *rclp);
127void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp,
128 struct rcu_cblist *rclp);
129void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
130 struct rcu_cblist *rclp);
131void rcu_segcblist_insert_done_cbs(struct rcu_segcblist *rsclp,
132 struct rcu_cblist *rclp);
133void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp,
134 struct rcu_cblist *rclp);
135void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq);
136bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq);
137bool rcu_segcblist_future_gp_needed(struct rcu_segcblist *rsclp,
138 unsigned long seq);
139void rcu_segcblist_merge(struct rcu_segcblist *dst_rsclp,
140 struct rcu_segcblist *src_rsclp);