Skip to content

Commit 65cfe35

Browse files
committed
rcu: Define RCU-bh update API in terms of RCU
Now that the main RCU API knows about softirq disabling and softirq's quiescent states, the RCU-bh update code can be dispensed with. This commit therefore removes the RCU-bh update-side implementation and defines RCU-bh's update-side API in terms of that of either RCU-preempt or RCU-sched, depending on the setting of the CONFIG_PREEMPT Kconfig option. In kernels built with CONFIG_RCU_NOCB_CPU=y this has the knock-on effect of reducing by one the number of rcuo kthreads per CPU. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent ba1c64c commit 65cfe35

7 files changed

Lines changed: 48 additions & 194 deletions

File tree

‎include/linux/rcupdate.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func);
5555
#define call_rcu call_rcu_sched
5656
#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
5757

58-
void call_rcu_bh(struct rcu_head *head, rcu_callback_t func);
5958
void call_rcu_sched(struct rcu_head *head, rcu_callback_t func);
6059
void synchronize_sched(void);
6160
void rcu_barrier_tasks(void);
6261

62+
static inline void call_rcu_bh(struct rcu_head *head, rcu_callback_t func)
63+
{
64+
call_rcu(head, func);
65+
}
66+
6367
#ifdef CONFIG_PREEMPT_RCU
6468

6569
void __rcu_read_lock(void);
@@ -104,7 +108,6 @@ static inline int rcu_preempt_depth(void)
104108
void rcu_init(void);
105109
extern int rcu_scheduler_active __read_mostly;
106110
void rcu_sched_qs(void);
107-
void rcu_bh_qs(void);
108111
void rcu_check_callbacks(int user);
109112
void rcu_report_dead(unsigned int cpu);
110113
void rcutree_migrate_callbacks(int cpu);
@@ -326,8 +329,7 @@ static inline void rcu_preempt_sleep_check(void) { }
326329
* and rcu_assign_pointer(). Some of these could be folded into their
327330
* callers, but they are left separate in order to ease introduction of
328331
* multiple flavors of pointers to match the multiple flavors of RCU
329-
* (e.g., __rcu_bh, * __rcu_sched, and __srcu), should this make sense in
330-
* the future.
332+
* (e.g., __rcu_sched, and __srcu), should this make sense in the future.
331333
*/
332334

333335
#ifdef __CHECKER__

‎include/linux/rcutiny.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,23 @@ static inline void cond_synchronize_sched(unsigned long oldstate)
5656
might_sleep();
5757
}
5858

59-
extern void rcu_barrier_bh(void);
60-
extern void rcu_barrier_sched(void);
61-
6259
static inline void synchronize_rcu_expedited(void)
6360
{
6461
synchronize_sched(); /* Only one CPU, so pretty fast anyway!!! */
6562
}
6663

64+
extern void rcu_barrier_sched(void);
65+
6766
static inline void rcu_barrier(void)
6867
{
6968
rcu_barrier_sched(); /* Only one CPU, so only one list of callbacks! */
7069
}
7170

71+
static inline void rcu_barrier_bh(void)
72+
{
73+
rcu_barrier();
74+
}
75+
7276
static inline void synchronize_rcu_bh(void)
7377
{
7478
synchronize_sched();

‎include/linux/rcutree.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ static inline void rcu_virt_note_context_switch(int cpu)
4545
rcu_note_context_switch(false);
4646
}
4747

48-
void synchronize_rcu_bh(void);
48+
static inline void synchronize_rcu_bh(void)
49+
{
50+
synchronize_rcu();
51+
}
52+
4953
void synchronize_sched_expedited(void);
5054
void synchronize_rcu_expedited(void);
5155

@@ -69,7 +73,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func);
6973
*/
7074
static inline void synchronize_rcu_bh_expedited(void)
7175
{
72-
synchronize_sched_expedited();
76+
synchronize_rcu_expedited();
7377
}
7478

7579
void rcu_barrier(void);

‎kernel/rcu/tiny.c‎

Lines changed: 21 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -51,64 +51,22 @@ static struct rcu_ctrlblk rcu_sched_ctrlblk = {
5151
.curtail = &rcu_sched_ctrlblk.rcucblist,
5252
};
5353

54-
static struct rcu_ctrlblk rcu_bh_ctrlblk = {
55-
.donetail = &rcu_bh_ctrlblk.rcucblist,
56-
.curtail = &rcu_bh_ctrlblk.rcucblist,
57-
};
58-
59-
void rcu_barrier_bh(void)
60-
{
61-
wait_rcu_gp(call_rcu_bh);
62-
}
63-
EXPORT_SYMBOL(rcu_barrier_bh);
64-
6554
void rcu_barrier_sched(void)
6655
{
6756
wait_rcu_gp(call_rcu_sched);
6857
}
6958
EXPORT_SYMBOL(rcu_barrier_sched);
7059

71-
/*
72-
* Helper function for rcu_sched_qs() and rcu_bh_qs().
73-
* Also irqs are disabled to avoid confusion due to interrupt handlers
74-
* invoking call_rcu().
75-
*/
76-
static int rcu_qsctr_help(struct rcu_ctrlblk *rcp)
77-
{
78-
if (rcp->donetail != rcp->curtail) {
79-
rcp->donetail = rcp->curtail;
80-
return 1;
81-
}
82-
83-
return 0;
84-
}
85-
86-
/*
87-
* Record an rcu quiescent state. And an rcu_bh quiescent state while we
88-
* are at it, given that any rcu quiescent state is also an rcu_bh
89-
* quiescent state. Use "+" instead of "||" to defeat short circuiting.
90-
*/
60+
/* Record an rcu quiescent state. */
9161
void rcu_sched_qs(void)
9262
{
9363
unsigned long flags;
9464

9565
local_irq_save(flags);
96-
if (rcu_qsctr_help(&rcu_sched_ctrlblk) +
97-
rcu_qsctr_help(&rcu_bh_ctrlblk))
98-
raise_softirq(RCU_SOFTIRQ);
99-
local_irq_restore(flags);
100-
}
101-
102-
/*
103-
* Record an rcu_bh quiescent state.
104-
*/
105-
void rcu_bh_qs(void)
106-
{
107-
unsigned long flags;
108-
109-
local_irq_save(flags);
110-
if (rcu_qsctr_help(&rcu_bh_ctrlblk))
66+
if (rcu_sched_ctrlblk.donetail != rcu_sched_ctrlblk.curtail) {
67+
rcu_sched_ctrlblk.donetail = rcu_sched_ctrlblk.curtail;
11168
raise_softirq(RCU_SOFTIRQ);
69+
}
11270
local_irq_restore(flags);
11371
}
11472

@@ -122,32 +80,27 @@ void rcu_check_callbacks(int user)
12280
{
12381
if (user)
12482
rcu_sched_qs();
125-
if (user || !in_softirq())
126-
rcu_bh_qs();
12783
}
12884

129-
/*
130-
* Invoke the RCU callbacks on the specified rcu_ctrlkblk structure
131-
* whose grace period has elapsed.
132-
*/
133-
static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
85+
/* Invoke the RCU callbacks whose grace period has elapsed. */
86+
static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
13487
{
13588
struct rcu_head *next, *list;
13689
unsigned long flags;
13790

13891
/* Move the ready-to-invoke callbacks to a local list. */
13992
local_irq_save(flags);
140-
if (rcp->donetail == &rcp->rcucblist) {
93+
if (rcu_sched_ctrlblk.donetail == &rcu_sched_ctrlblk.rcucblist) {
14194
/* No callbacks ready, so just leave. */
14295
local_irq_restore(flags);
14396
return;
14497
}
145-
list = rcp->rcucblist;
146-
rcp->rcucblist = *rcp->donetail;
147-
*rcp->donetail = NULL;
148-
if (rcp->curtail == rcp->donetail)
149-
rcp->curtail = &rcp->rcucblist;
150-
rcp->donetail = &rcp->rcucblist;
98+
list = rcu_sched_ctrlblk.rcucblist;
99+
rcu_sched_ctrlblk.rcucblist = *rcu_sched_ctrlblk.donetail;
100+
*rcu_sched_ctrlblk.donetail = NULL;
101+
if (rcu_sched_ctrlblk.curtail == rcu_sched_ctrlblk.donetail)
102+
rcu_sched_ctrlblk.curtail = &rcu_sched_ctrlblk.rcucblist;
103+
rcu_sched_ctrlblk.donetail = &rcu_sched_ctrlblk.rcucblist;
151104
local_irq_restore(flags);
152105

153106
/* Invoke the callbacks on the local list. */
@@ -162,19 +115,13 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
162115
}
163116
}
164117

165-
static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
166-
{
167-
__rcu_process_callbacks(&rcu_sched_ctrlblk);
168-
__rcu_process_callbacks(&rcu_bh_ctrlblk);
169-
}
170-
171118
/*
172119
* Wait for a grace period to elapse. But it is illegal to invoke
173120
* synchronize_sched() from within an RCU read-side critical section.
174121
* Therefore, any legal call to synchronize_sched() is a quiescent
175122
* state, and so on a UP system, synchronize_sched() need do nothing.
176-
* Ditto for synchronize_rcu_bh(). (But Lai Jiangshan points out the
177-
* benefits of doing might_sleep() to reduce latency.)
123+
* (But Lai Jiangshan points out the benefits of doing might_sleep()
124+
* to reduce latency.)
178125
*
179126
* Cool, huh? (Due to Josh Triplett.)
180127
*/
@@ -188,11 +135,11 @@ void synchronize_sched(void)
188135
EXPORT_SYMBOL_GPL(synchronize_sched);
189136

190137
/*
191-
* Helper function for call_rcu() and call_rcu_bh().
138+
* Post an RCU callback to be invoked after the end of an RCU-sched grace
139+
* period. But since we have but one CPU, that would be after any
140+
* quiescent state.
192141
*/
193-
static void __call_rcu(struct rcu_head *head,
194-
rcu_callback_t func,
195-
struct rcu_ctrlblk *rcp)
142+
void call_rcu_sched(struct rcu_head *head, rcu_callback_t func)
196143
{
197144
unsigned long flags;
198145

@@ -201,37 +148,17 @@ static void __call_rcu(struct rcu_head *head,
201148
head->next = NULL;
202149

203150
local_irq_save(flags);
204-
*rcp->curtail = head;
205-
rcp->curtail = &head->next;
151+
*rcu_sched_ctrlblk.curtail = head;
152+
rcu_sched_ctrlblk.curtail = &head->next;
206153
local_irq_restore(flags);
207154

208155
if (unlikely(is_idle_task(current))) {
209156
/* force scheduling for rcu_sched_qs() */
210157
resched_cpu(0);
211158
}
212159
}
213-
214-
/*
215-
* Post an RCU callback to be invoked after the end of an RCU-sched grace
216-
* period. But since we have but one CPU, that would be after any
217-
* quiescent state.
218-
*/
219-
void call_rcu_sched(struct rcu_head *head, rcu_callback_t func)
220-
{
221-
__call_rcu(head, func, &rcu_sched_ctrlblk);
222-
}
223160
EXPORT_SYMBOL_GPL(call_rcu_sched);
224161

225-
/*
226-
* Post an RCU bottom-half callback to be invoked after any subsequent
227-
* quiescent state.
228-
*/
229-
void call_rcu_bh(struct rcu_head *head, rcu_callback_t func)
230-
{
231-
__call_rcu(head, func, &rcu_bh_ctrlblk);
232-
}
233-
EXPORT_SYMBOL_GPL(call_rcu_bh);
234-
235162
void __init rcu_init(void)
236163
{
237164
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);

0 commit comments

Comments
 (0)