Skip to content

Commit 2c42818

Browse files
committed
rcu: Abstract common code for RCU grace-period-wait primitives
Pull the code that waits for an RCU grace period into a single function, which is then called by synchronize_rcu() and friends in the case of TREE_RCU and TREE_PREEMPT_RCU, and from rcu_barrier() and friends in the case of TINY_RCU and TINY_PREEMPT_RCU. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent f039d1f commit 2c42818

8 files changed

Lines changed: 113 additions & 131 deletions

File tree

‎include/linux/rcupdate.h‎

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,73 @@ static inline void rcutorture_record_progress(unsigned long vernum)
6666
#define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
6767

6868
/* Exported common interfaces */
69+
70+
#ifdef CONFIG_PREEMPT_RCU
71+
72+
/**
73+
* call_rcu() - Queue an RCU callback for invocation after a grace period.
74+
* @head: structure to be used for queueing the RCU updates.
75+
* @func: actual callback function to be invoked after the grace period
76+
*
77+
* The callback function will be invoked some time after a full grace
78+
* period elapses, in other words after all pre-existing RCU read-side
79+
* critical sections have completed. However, the callback function
80+
* might well execute concurrently with RCU read-side critical sections
81+
* that started after call_rcu() was invoked. RCU read-side critical
82+
* sections are delimited by rcu_read_lock() and rcu_read_unlock(),
83+
* and may be nested.
84+
*/
85+
extern void call_rcu(struct rcu_head *head,
86+
void (*func)(struct rcu_head *head));
87+
88+
#else /* #ifdef CONFIG_PREEMPT_RCU */
89+
90+
/* In classic RCU, call_rcu() is just call_rcu_sched(). */
91+
#define call_rcu call_rcu_sched
92+
93+
#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
94+
95+
/**
96+
* call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
97+
* @head: structure to be used for queueing the RCU updates.
98+
* @func: actual callback function to be invoked after the grace period
99+
*
100+
* The callback function will be invoked some time after a full grace
101+
* period elapses, in other words after all currently executing RCU
102+
* read-side critical sections have completed. call_rcu_bh() assumes
103+
* that the read-side critical sections end on completion of a softirq
104+
* handler. This means that read-side critical sections in process
105+
* context must not be interrupted by softirqs. This interface is to be
106+
* used when most of the read-side critical sections are in softirq context.
107+
* RCU read-side critical sections are delimited by :
108+
* - rcu_read_lock() and rcu_read_unlock(), if in interrupt context.
109+
* OR
110+
* - rcu_read_lock_bh() and rcu_read_unlock_bh(), if in process context.
111+
* These may be nested.
112+
*/
113+
extern void call_rcu_bh(struct rcu_head *head,
114+
void (*func)(struct rcu_head *head));
115+
116+
/**
117+
* call_rcu_sched() - Queue an RCU for invocation after sched grace period.
118+
* @head: structure to be used for queueing the RCU updates.
119+
* @func: actual callback function to be invoked after the grace period
120+
*
121+
* The callback function will be invoked some time after a full grace
122+
* period elapses, in other words after all currently executing RCU
123+
* read-side critical sections have completed. call_rcu_sched() assumes
124+
* that the read-side critical sections end on enabling of preemption
125+
* or on voluntary preemption.
126+
* RCU read-side critical sections are delimited by :
127+
* - rcu_read_lock_sched() and rcu_read_unlock_sched(),
128+
* OR
129+
* anything that disables preemption.
130+
* These may be nested.
131+
*/
69132
extern void call_rcu_sched(struct rcu_head *head,
70133
void (*func)(struct rcu_head *rcu));
134+
71135
extern void synchronize_sched(void);
72-
extern void rcu_barrier_bh(void);
73-
extern void rcu_barrier_sched(void);
74136

75137
static inline void __rcu_read_lock_bh(void)
76138
{
@@ -143,6 +205,15 @@ static inline void rcu_exit_nohz(void)
143205

144206
#endif /* #else #ifdef CONFIG_NO_HZ */
145207

208+
/*
209+
* Infrastructure to implement the synchronize_() primitives in
210+
* TREE_RCU and rcu_barrier_() primitives in TINY_RCU.
211+
*/
212+
213+
typedef void call_rcu_func_t(struct rcu_head *head,
214+
void (*func)(struct rcu_head *head));
215+
void wait_rcu_gp(call_rcu_func_t crf);
216+
146217
#if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
147218
#include <linux/rcutree.h>
148219
#elif defined(CONFIG_TINY_RCU) || defined(CONFIG_TINY_PREEMPT_RCU)
@@ -723,61 +794,6 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
723794
#define RCU_INIT_POINTER(p, v) \
724795
p = (typeof(*v) __force __rcu *)(v)
725796

726-
/* Infrastructure to implement the synchronize_() primitives. */
727-
728-
struct rcu_synchronize {
729-
struct rcu_head head;
730-
struct completion completion;
731-
};
732-
733-
extern void wakeme_after_rcu(struct rcu_head *head);
734-
735-
#ifdef CONFIG_PREEMPT_RCU
736-
737-
/**
738-
* call_rcu() - Queue an RCU callback for invocation after a grace period.
739-
* @head: structure to be used for queueing the RCU updates.
740-
* @func: actual callback function to be invoked after the grace period
741-
*
742-
* The callback function will be invoked some time after a full grace
743-
* period elapses, in other words after all pre-existing RCU read-side
744-
* critical sections have completed. However, the callback function
745-
* might well execute concurrently with RCU read-side critical sections
746-
* that started after call_rcu() was invoked. RCU read-side critical
747-
* sections are delimited by rcu_read_lock() and rcu_read_unlock(),
748-
* and may be nested.
749-
*/
750-
extern void call_rcu(struct rcu_head *head,
751-
void (*func)(struct rcu_head *head));
752-
753-
#else /* #ifdef CONFIG_PREEMPT_RCU */
754-
755-
/* In classic RCU, call_rcu() is just call_rcu_sched(). */
756-
#define call_rcu call_rcu_sched
757-
758-
#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
759-
760-
/**
761-
* call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
762-
* @head: structure to be used for queueing the RCU updates.
763-
* @func: actual callback function to be invoked after the grace period
764-
*
765-
* The callback function will be invoked some time after a full grace
766-
* period elapses, in other words after all currently executing RCU
767-
* read-side critical sections have completed. call_rcu_bh() assumes
768-
* that the read-side critical sections end on completion of a softirq
769-
* handler. This means that read-side critical sections in process
770-
* context must not be interrupted by softirqs. This interface is to be
771-
* used when most of the read-side critical sections are in softirq context.
772-
* RCU read-side critical sections are delimited by :
773-
* - rcu_read_lock() and rcu_read_unlock(), if in interrupt context.
774-
* OR
775-
* - rcu_read_lock_bh() and rcu_read_unlock_bh(), if in process context.
776-
* These may be nested.
777-
*/
778-
extern void call_rcu_bh(struct rcu_head *head,
779-
void (*func)(struct rcu_head *head));
780-
781797
/*
782798
* debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
783799
* by call_rcu() and rcu callback execution, and are therefore not part of the

‎include/linux/rcutiny.h‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ static inline void rcu_init(void)
3131
{
3232
}
3333

34+
static inline void rcu_barrier_bh(void)
35+
{
36+
wait_rcu_gp(call_rcu_bh);
37+
}
38+
39+
static inline void rcu_barrier_sched(void)
40+
{
41+
wait_rcu_gp(call_rcu_sched);
42+
}
43+
3444
#ifdef CONFIG_TINY_RCU
3545

3646
static inline void synchronize_rcu_expedited(void)
@@ -45,9 +55,13 @@ static inline void rcu_barrier(void)
4555

4656
#else /* #ifdef CONFIG_TINY_RCU */
4757

48-
void rcu_barrier(void);
4958
void synchronize_rcu_expedited(void);
5059

60+
static inline void rcu_barrier(void)
61+
{
62+
wait_rcu_gp(call_rcu);
63+
}
64+
5165
#endif /* #else #ifdef CONFIG_TINY_RCU */
5266

5367
static inline void synchronize_rcu_bh(void)

‎include/linux/rcutree.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static inline void synchronize_rcu_bh_expedited(void)
6767
}
6868

6969
extern void rcu_barrier(void);
70+
extern void rcu_barrier_bh(void);
71+
extern void rcu_barrier_sched(void);
7072

7173
extern unsigned long rcutorture_testseq;
7274
extern unsigned long rcutorture_vernum;

‎kernel/rcupdate.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,37 @@ EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
9494

9595
#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
9696

97+
struct rcu_synchronize {
98+
struct rcu_head head;
99+
struct completion completion;
100+
};
101+
97102
/*
98103
* Awaken the corresponding synchronize_rcu() instance now that a
99104
* grace period has elapsed.
100105
*/
101-
void wakeme_after_rcu(struct rcu_head *head)
106+
static void wakeme_after_rcu(struct rcu_head *head)
102107
{
103108
struct rcu_synchronize *rcu;
104109

105110
rcu = container_of(head, struct rcu_synchronize, head);
106111
complete(&rcu->completion);
107112
}
108113

114+
void wait_rcu_gp(call_rcu_func_t crf)
115+
{
116+
struct rcu_synchronize rcu;
117+
118+
init_rcu_head_on_stack(&rcu.head);
119+
init_completion(&rcu.completion);
120+
/* Will wake me after RCU finished. */
121+
crf(&rcu.head, wakeme_after_rcu);
122+
/* Wait for it. */
123+
wait_for_completion(&rcu.completion);
124+
destroy_rcu_head_on_stack(&rcu.head);
125+
}
126+
EXPORT_SYMBOL_GPL(wait_rcu_gp);
127+
109128
#ifdef CONFIG_PROVE_RCU
110129
/*
111130
* wrapper function to avoid #include problems.

‎kernel/rcutiny.c‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -281,34 +281,6 @@ void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
281281
}
282282
EXPORT_SYMBOL_GPL(call_rcu_bh);
283283

284-
void rcu_barrier_bh(void)
285-
{
286-
struct rcu_synchronize rcu;
287-
288-
init_rcu_head_on_stack(&rcu.head);
289-
init_completion(&rcu.completion);
290-
/* Will wake me after RCU finished. */
291-
call_rcu_bh(&rcu.head, wakeme_after_rcu);
292-
/* Wait for it. */
293-
wait_for_completion(&rcu.completion);
294-
destroy_rcu_head_on_stack(&rcu.head);
295-
}
296-
EXPORT_SYMBOL_GPL(rcu_barrier_bh);
297-
298-
void rcu_barrier_sched(void)
299-
{
300-
struct rcu_synchronize rcu;
301-
302-
init_rcu_head_on_stack(&rcu.head);
303-
init_completion(&rcu.completion);
304-
/* Will wake me after RCU finished. */
305-
call_rcu_sched(&rcu.head, wakeme_after_rcu);
306-
/* Wait for it. */
307-
wait_for_completion(&rcu.completion);
308-
destroy_rcu_head_on_stack(&rcu.head);
309-
}
310-
EXPORT_SYMBOL_GPL(rcu_barrier_sched);
311-
312284
/*
313285
* Spawn the kthread that invokes RCU callbacks.
314286
*/

‎kernel/rcutiny_plugin.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -697,20 +697,6 @@ void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
697697
}
698698
EXPORT_SYMBOL_GPL(call_rcu);
699699

700-
void rcu_barrier(void)
701-
{
702-
struct rcu_synchronize rcu;
703-
704-
init_rcu_head_on_stack(&rcu.head);
705-
init_completion(&rcu.completion);
706-
/* Will wake me after RCU finished. */
707-
call_rcu(&rcu.head, wakeme_after_rcu);
708-
/* Wait for it. */
709-
wait_for_completion(&rcu.completion);
710-
destroy_rcu_head_on_stack(&rcu.head);
711-
}
712-
EXPORT_SYMBOL_GPL(rcu_barrier);
713-
714700
/*
715701
* synchronize_rcu - wait until a grace period has elapsed.
716702
*

‎kernel/rcutree.c‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,18 +1613,9 @@ EXPORT_SYMBOL_GPL(call_rcu_bh);
16131613
*/
16141614
void synchronize_sched(void)
16151615
{
1616-
struct rcu_synchronize rcu;
1617-
16181616
if (rcu_blocking_is_gp())
16191617
return;
1620-
1621-
init_rcu_head_on_stack(&rcu.head);
1622-
init_completion(&rcu.completion);
1623-
/* Will wake me after RCU finished. */
1624-
call_rcu_sched(&rcu.head, wakeme_after_rcu);
1625-
/* Wait for it. */
1626-
wait_for_completion(&rcu.completion);
1627-
destroy_rcu_head_on_stack(&rcu.head);
1618+
wait_rcu_gp(call_rcu_sched);
16281619
}
16291620
EXPORT_SYMBOL_GPL(synchronize_sched);
16301621

@@ -1639,18 +1630,9 @@ EXPORT_SYMBOL_GPL(synchronize_sched);
16391630
*/
16401631
void synchronize_rcu_bh(void)
16411632
{
1642-
struct rcu_synchronize rcu;
1643-
16441633
if (rcu_blocking_is_gp())
16451634
return;
1646-
1647-
init_rcu_head_on_stack(&rcu.head);
1648-
init_completion(&rcu.completion);
1649-
/* Will wake me after RCU finished. */
1650-
call_rcu_bh(&rcu.head, wakeme_after_rcu);
1651-
/* Wait for it. */
1652-
wait_for_completion(&rcu.completion);
1653-
destroy_rcu_head_on_stack(&rcu.head);
1635+
wait_rcu_gp(call_rcu_bh);
16541636
}
16551637
EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
16561638

‎kernel/rcutree_plugin.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,18 +656,9 @@ EXPORT_SYMBOL_GPL(call_rcu);
656656
*/
657657
void synchronize_rcu(void)
658658
{
659-
struct rcu_synchronize rcu;
660-
661659
if (!rcu_scheduler_active)
662660
return;
663-
664-
init_rcu_head_on_stack(&rcu.head);
665-
init_completion(&rcu.completion);
666-
/* Will wake me after RCU finished. */
667-
call_rcu(&rcu.head, wakeme_after_rcu);
668-
/* Wait for it. */
669-
wait_for_completion(&rcu.completion);
670-
destroy_rcu_head_on_stack(&rcu.head);
661+
wait_rcu_gp(call_rcu);
671662
}
672663
EXPORT_SYMBOL_GPL(synchronize_rcu);
673664

0 commit comments

Comments
 (0)