Skip to content

Commit e6753f2

Browse files
joelagnelrostedt
authored andcommitted
tracepoint: Make rcuidle tracepoint callers use SRCU
In recent tests with IRQ on/off tracepoints, a large performance overhead ~10% is noticed when running hackbench. This is root caused to calls to rcu_irq_enter_irqson and rcu_irq_exit_irqson from the tracepoint code. Following a long discussion on the list [1] about this, we concluded that srcu is a better alternative for use during rcu idle. Although it does involve extra barriers, its lighter than the sched-rcu version which has to do additional RCU calls to notify RCU idle about entry into RCU sections. In this patch, we change the underlying implementation of the trace_*_rcuidle API to use SRCU. This has shown to improve performance alot for the high frequency irq enable/disable tracepoints. Test: Tested idle and preempt/irq tracepoints. Here are some performance numbers: With a run of the following 30 times on a single core x86 Qemu instance with 1GB memory: hackbench -g 4 -f 2 -l 3000 Completion times in seconds. CONFIG_PROVE_LOCKING=y. No patches (without this series) Mean: 3.048 Median: 3.025 Std Dev: 0.064 With Lockdep using irq tracepoints with RCU implementation: Mean: 3.451 (-11.66 %) Median: 3.447 (-12.22%) Std Dev: 0.049 With Lockdep using irq tracepoints with SRCU implementation (this series): Mean: 3.020 (I would consider the improvement against the "without this series" case as just noise). Median: 3.013 Std Dev: 0.033 [1] https://patchwork.kernel.org/patch/10344297/ [remove rcu_read_lock_sched_notrace as its the equivalent of preempt_disable_notrace and is unnecessary to call in tracepoint code] Link: http://lkml.kernel.org/r/[email protected] Cleaned-up-by: Peter Zijlstra <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Joel Fernandes (Google) <[email protected]> [ Simplified WARN_ON_ONCE() ] Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 01f3849 commit e6753f2

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

include/linux/tracepoint.h

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <linux/smp.h>
18+
#include <linux/srcu.h>
1819
#include <linux/errno.h>
1920
#include <linux/types.h>
2021
#include <linux/cpumask.h>
@@ -33,6 +34,8 @@ struct trace_eval_map {
3334

3435
#define TRACEPOINT_DEFAULT_PRIO 10
3536

37+
extern struct srcu_struct tracepoint_srcu;
38+
3639
extern int
3740
tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
3841
extern int
@@ -75,10 +78,16 @@ int unregister_tracepoint_module_notifier(struct notifier_block *nb)
7578
* probe unregistration and the end of module exit to make sure there is no
7679
* caller executing a probe when it is freed.
7780
*/
81+
#ifdef CONFIG_TRACEPOINTS
7882
static inline void tracepoint_synchronize_unregister(void)
7983
{
84+
synchronize_srcu(&tracepoint_srcu);
8085
synchronize_sched();
8186
}
87+
#else
88+
static inline void tracepoint_synchronize_unregister(void)
89+
{ }
90+
#endif
8291

8392
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
8493
extern int syscall_regfunc(void);
@@ -129,28 +138,43 @@ extern void syscall_unregfunc(void);
129138
* as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
130139
* "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
131140
*/
132-
#define __DO_TRACE(tp, proto, args, cond, rcucheck) \
141+
#define __DO_TRACE(tp, proto, args, cond, rcuidle) \
133142
do { \
134143
struct tracepoint_func *it_func_ptr; \
135144
void *it_func; \
136145
void *__data; \
146+
int __maybe_unused idx = 0; \
137147
\
138148
if (!(cond)) \
139149
return; \
140-
if (rcucheck) \
141-
rcu_irq_enter_irqson(); \
142-
rcu_read_lock_sched_notrace(); \
143-
it_func_ptr = rcu_dereference_sched((tp)->funcs); \
150+
\
151+
/* srcu can't be used from NMI */ \
152+
WARN_ON_ONCE(rcuidle && in_nmi()); \
153+
\
154+
/* keep srcu and sched-rcu usage consistent */ \
155+
preempt_disable_notrace(); \
156+
\
157+
/* \
158+
* For rcuidle callers, use srcu since sched-rcu \
159+
* doesn't work from the idle path. \
160+
*/ \
161+
if (rcuidle) \
162+
idx = srcu_read_lock_notrace(&tracepoint_srcu); \
163+
\
164+
it_func_ptr = rcu_dereference_raw((tp)->funcs); \
165+
\
144166
if (it_func_ptr) { \
145167
do { \
146168
it_func = (it_func_ptr)->func; \
147169
__data = (it_func_ptr)->data; \
148170
((void(*)(proto))(it_func))(args); \
149171
} while ((++it_func_ptr)->func); \
150172
} \
151-
rcu_read_unlock_sched_notrace(); \
152-
if (rcucheck) \
153-
rcu_irq_exit_irqson(); \
173+
\
174+
if (rcuidle) \
175+
srcu_read_unlock_notrace(&tracepoint_srcu, idx);\
176+
\
177+
preempt_enable_notrace(); \
154178
} while (0)
155179

156180
#ifndef MODULE

kernel/tracepoint.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
extern struct tracepoint * const __start___tracepoints_ptrs[];
3232
extern struct tracepoint * const __stop___tracepoints_ptrs[];
3333

34+
DEFINE_SRCU(tracepoint_srcu);
35+
EXPORT_SYMBOL_GPL(tracepoint_srcu);
36+
3437
/* Set to 1 to enable tracepoint debug output */
3538
static const int tracepoint_debug;
3639

@@ -67,16 +70,27 @@ static inline void *allocate_probes(int count)
6770
return p == NULL ? NULL : p->probes;
6871
}
6972

70-
static void rcu_free_old_probes(struct rcu_head *head)
73+
static void srcu_free_old_probes(struct rcu_head *head)
7174
{
7275
kfree(container_of(head, struct tp_probes, rcu));
7376
}
7477

78+
static void rcu_free_old_probes(struct rcu_head *head)
79+
{
80+
call_srcu(&tracepoint_srcu, head, srcu_free_old_probes);
81+
}
82+
7583
static inline void release_probes(struct tracepoint_func *old)
7684
{
7785
if (old) {
7886
struct tp_probes *tp_probes = container_of(old,
7987
struct tp_probes, probes[0]);
88+
/*
89+
* Tracepoint probes are protected by both sched RCU and SRCU,
90+
* by calling the SRCU callback in the sched RCU callback we
91+
* cover both cases. So let us chain the SRCU and sched RCU
92+
* callbacks to wait for both grace periods.
93+
*/
8094
call_rcu_sched(&tp_probes->rcu, rcu_free_old_probes);
8195
}
8296
}

0 commit comments

Comments
 (0)