aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2013-01-22 13:35:11 -0500
committerSteven Rostedt <rostedt@goodmis.org>2013-01-22 23:33:07 -0500
commit34600f0e9c33c9cd48ae87448205f51332b7d5a0 (patch)
treefb6159552edf55526219b4c4c55f6120595be53e /kernel/trace
parent0a71e4c6d749d06f52e75a406fc9046924fcfcc1 (diff)
tracing: Fix race with max_tr and changing tracers
There's a race condition between the setting of a new tracer and the update of the max trace buffers (the swap). When a new tracer is added, it sets current_trace to nop_trace before disabling the old tracer. At this moment, if the old tracer uses update_max_tr(), the update may trigger the warning against !current_trace->use_max-tr, as nop_trace doesn't have that set. As update_max_tr() requires that interrupts be disabled, we can add a check to see if current_trace == nop_trace and bail if it does. Then when disabling the current_trace, set it to nop_trace and run synchronize_sched(). This will make sure all calls to update_max_tr() have completed (it was called with interrupts disabled). As a clean up, this commit also removes shrinking and recreating the max_tr buffer if the old and new tracers both have use_max_tr set. The old way use to always shrink the buffer, and then expand it for the next tracer. This is a waste of time. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a387bd271e71..d2a658349ca1 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -709,10 +709,14 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
709 return; 709 return;
710 710
711 WARN_ON_ONCE(!irqs_disabled()); 711 WARN_ON_ONCE(!irqs_disabled());
712 if (!current_trace->use_max_tr) { 712
713 WARN_ON_ONCE(1); 713 /* If we disabled the tracer, stop now */
714 if (current_trace == &nop_trace)
714 return; 715 return;
715 } 716
717 if (WARN_ON_ONCE(!current_trace->use_max_tr))
718 return;
719
716 arch_spin_lock(&ftrace_max_lock); 720 arch_spin_lock(&ftrace_max_lock);
717 721
718 tr->buffer = max_tr.buffer; 722 tr->buffer = max_tr.buffer;
@@ -3185,6 +3189,7 @@ static int tracing_set_tracer(const char *buf)
3185 static struct trace_option_dentry *topts; 3189 static struct trace_option_dentry *topts;
3186 struct trace_array *tr = &global_trace; 3190 struct trace_array *tr = &global_trace;
3187 struct tracer *t; 3191 struct tracer *t;
3192 bool had_max_tr;
3188 int ret = 0; 3193 int ret = 0;
3189 3194
3190 mutex_lock(&trace_types_lock); 3195 mutex_lock(&trace_types_lock);
@@ -3211,7 +3216,19 @@ static int tracing_set_tracer(const char *buf)
3211 trace_branch_disable(); 3216 trace_branch_disable();
3212 if (current_trace && current_trace->reset) 3217 if (current_trace && current_trace->reset)
3213 current_trace->reset(tr); 3218 current_trace->reset(tr);
3214 if (current_trace && current_trace->use_max_tr) { 3219
3220 had_max_tr = current_trace && current_trace->use_max_tr;
3221 current_trace = &nop_trace;
3222
3223 if (had_max_tr && !t->use_max_tr) {
3224 /*
3225 * We need to make sure that the update_max_tr sees that
3226 * current_trace changed to nop_trace to keep it from
3227 * swapping the buffers after we resize it.
3228 * The update_max_tr is called from interrupts disabled
3229 * so a synchronized_sched() is sufficient.
3230 */
3231 synchronize_sched();
3215 /* 3232 /*
3216 * We don't free the ring buffer. instead, resize it because 3233 * We don't free the ring buffer. instead, resize it because
3217 * The max_tr ring buffer has some state (e.g. ring->clock) and 3234 * The max_tr ring buffer has some state (e.g. ring->clock) and
@@ -3222,10 +3239,8 @@ static int tracing_set_tracer(const char *buf)
3222 } 3239 }
3223 destroy_trace_option_files(topts); 3240 destroy_trace_option_files(topts);
3224 3241
3225 current_trace = &nop_trace;
3226
3227 topts = create_trace_option_files(t); 3242 topts = create_trace_option_files(t);
3228 if (t->use_max_tr) { 3243 if (t->use_max_tr && !had_max_tr) {
3229 /* we need to make per cpu buffer sizes equivalent */ 3244 /* we need to make per cpu buffer sizes equivalent */
3230 ret = resize_buffer_duplicate_size(&max_tr, &global_trace, 3245 ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
3231 RING_BUFFER_ALL_CPUS); 3246 RING_BUFFER_ALL_CPUS);