Skip to content

Commit a541a95

Browse files
committed
tracing: Do not free snapshot if tracer is on cmdline
The ftrace_boot_snapshot and alloc_snapshot cmdline options allocate the snapshot buffer at boot up for use later. The ftrace_boot_snapshot in particular requires the snapshot to be allocated because it will take a snapshot at the end of boot up allowing to see the traces that happened during boot so that it's not lost when user space takes over. When a tracer is registered (started) there's a path that checks if it requires the snapshot buffer or not, and if it does not and it was allocated it will do a synchronization and free the snapshot buffer. This is only required if the previous tracer was using it for "max latency" snapshots, as it needs to make sure all max snapshots are complete before freeing. But this is only needed if the previous tracer was using the snapshot buffer for latency (like irqoff tracer and friends). But it does not make sense to free it, if the previous tracer was not using it, and the snapshot was allocated by the cmdline parameters. This basically takes away the point of allocating it in the first place! Note, the allocated snapshot worked fine for just trace events, but fails when a tracer is enabled on the cmdline. Further investigation, this goes back even further and it does not require a tracer on the cmdline to fail. Simply enable snapshots and then enable a tracer, and it will remove the snapshot. Link: https://lkml.kernel.org/r/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Andrew Morton <[email protected]> Cc: [email protected] Fixes: 45ad21c ("tracing: Have trace_array keep track if snapshot buffer is allocated") Reported-by: Ross Zwisler <[email protected]> Tested-by: Ross Zwisler <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent cf04f2d commit a541a95

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kernel/trace/trace.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6428,12 +6428,12 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
64286428
if (tr->current_trace->reset)
64296429
tr->current_trace->reset(tr);
64306430

6431+
#ifdef CONFIG_TRACER_MAX_TRACE
6432+
had_max_tr = tr->current_trace->use_max_tr;
6433+
64316434
/* Current trace needs to be nop_trace before synchronize_rcu */
64326435
tr->current_trace = &nop_trace;
64336436

6434-
#ifdef CONFIG_TRACER_MAX_TRACE
6435-
had_max_tr = tr->allocated_snapshot;
6436-
64376437
if (had_max_tr && !t->use_max_tr) {
64386438
/*
64396439
* We need to make sure that the update_max_tr sees that
@@ -6446,11 +6446,13 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
64466446
free_snapshot(tr);
64476447
}
64486448

6449-
if (t->use_max_tr && !had_max_tr) {
6449+
if (t->use_max_tr && !tr->allocated_snapshot) {
64506450
ret = tracing_alloc_snapshot_instance(tr);
64516451
if (ret < 0)
64526452
goto out;
64536453
}
6454+
#else
6455+
tr->current_trace = &nop_trace;
64546456
#endif
64556457

64566458
if (t->init) {

0 commit comments

Comments
 (0)