tracing: Fix snapshot accounting
Steven Rostedt
maintainercover tracing: Fix snapshot accounting
The ring buffer mapping test failed after running the ftrace tests. This was due to some mismatched snapshot accounting that left the snapshot counter enabled when it was not, which prevents the ring buffer from being mapped.
Steven Rostedt (Google) (2):
tracing: Fix snapshot counter going between two tracers that use it
tracing: Decrement the snapshot if the snapshot trigger fails to register
----
kernel/trace/trace.c | 2 +- kernel/trace/trace_events_trigger.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
Steven Rostedt
maintainerPATCH 1/2 tracing: Fix snapshot counter going between two tracers that use it
From: "Steven Rostedt (Google)" <[email protected]>
Running the ftrace selftests caused the ring buffer mapping test to fail. Investigating, I found that the snapshot counter would be incremented every time a tracer that uses the snapshot is enabled even if the snapshot was used by the previous tracer.
That is:
# cd /sys/kernel/tracing # echo wakeup_rt > current_tracer # echo wakeup_dl > current_tracer # echo nop > current_tracer
would leave the snapshot counter at 1 and not zero. That's because the enabling of wakeup_dl would increment the counter again but the setting the tracer to nop would only decrement it once.
Do not arm the snapshot for a tracer if the previous tracer already had it armed.
--- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -6164,7 +6164,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)tracing_disarm_snapshot (tr); } -if (t->use_max_tr) { +if (!had_max_tr && t->use_max_tr) { ret =tracing_arm_snapshot_locked (tr);if (ret) goto out;
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 2/2 tracing: Decrement the snapshot if the snapshot trigger fails to register
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Running the ftrace selftests caused the ring buffer mapping test to fail. Investigating, I found that the snapshot counter would be incremented every time a snapshot trigger was added, even if that snapshot trigger failed.
# cd /sys/kernel/tracing # echo "snapshot" > events/sched/sched_process_fork/trigger # echo "snapshot" > events/sched/sched_process_fork/trigger -bash: echo: write error: File exists
That second one that fails increments the snapshot counter but doesn't decrement it. It needs to be decremented when the snapshot fails.
--- kernel/trace/trace_events_trigger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/trace_events_trigger.c +4 -1
@@ -1491,7 +1491,10 @@ register_snapshot_trigger(char *glob,if (ret <0 )return ret; -return register_trigger (glob, data, file); + ret =register_trigger (glob, data, file); +if (ret <0 ) +tracing_disarm_snapshot (file->tr); +return ret; } static void unregister_snapshot_trigger(char *glob,
Signature · 1 line
2.43.0