Skip to content

Commit 0486a1f

Browse files
rostedtgregkh
authored andcommitted
tracing: Disable snapshot buffer when stopping instance tracers
commit b538bf7 upstream. It use to be that only the top level instance had a snapshot buffer (for latency tracers like wakeup and irqsoff). When stopping a tracer in an instance would not disable the snapshot buffer. This could have some unintended consequences if the irqsoff tracer is enabled. Consolidate the tracing_start/stop() with tracing_start/stop_tr() so that all instances behave the same. The tracing_start/stop() functions will just call their respective tracing_start/stop_tr() with the global_array passed in. Link: https://lkml.kernel.org/r/20231205220011.041220035@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Fixes: 6d9b3fa ("tracing: Move tracing_max_latency into trace_array") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 12c48e8 commit 0486a1f

File tree

1 file changed

+34
-76
lines changed

1 file changed

+34
-76
lines changed

kernel/trace/trace.c

Lines changed: 34 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,133 +2359,91 @@ int is_tracing_stopped(void)
23592359
return global_trace.stop_count;
23602360
}
23612361

2362-
/**
2363-
* tracing_start - quick start of the tracer
2364-
*
2365-
* If tracing is enabled but was stopped by tracing_stop,
2366-
* this will start the tracer back up.
2367-
*/
2368-
void tracing_start(void)
2362+
static void tracing_start_tr(struct trace_array *tr)
23692363
{
23702364
struct trace_buffer *buffer;
23712365
unsigned long flags;
23722366

23732367
if (tracing_disabled)
23742368
return;
23752369

2376-
raw_spin_lock_irqsave(&global_trace.start_lock, flags);
2377-
if (--global_trace.stop_count) {
2378-
if (global_trace.stop_count < 0) {
2370+
raw_spin_lock_irqsave(&tr->start_lock, flags);
2371+
if (--tr->stop_count) {
2372+
if (WARN_ON_ONCE(tr->stop_count < 0)) {
23792373
/* Someone screwed up their debugging */
2380-
WARN_ON_ONCE(1);
2381-
global_trace.stop_count = 0;
2374+
tr->stop_count = 0;
23822375
}
23832376
goto out;
23842377
}
23852378

23862379
/* Prevent the buffers from switching */
2387-
arch_spin_lock(&global_trace.max_lock);
2380+
arch_spin_lock(&tr->max_lock);
23882381

2389-
buffer = global_trace.array_buffer.buffer;
2382+
buffer = tr->array_buffer.buffer;
23902383
if (buffer)
23912384
ring_buffer_record_enable(buffer);
23922385

23932386
#ifdef CONFIG_TRACER_MAX_TRACE
2394-
buffer = global_trace.max_buffer.buffer;
2387+
buffer = tr->max_buffer.buffer;
23952388
if (buffer)
23962389
ring_buffer_record_enable(buffer);
23972390
#endif
23982391

2399-
arch_spin_unlock(&global_trace.max_lock);
2400-
2401-
out:
2402-
raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
2403-
}
2404-
2405-
static void tracing_start_tr(struct trace_array *tr)
2406-
{
2407-
struct trace_buffer *buffer;
2408-
unsigned long flags;
2409-
2410-
if (tracing_disabled)
2411-
return;
2412-
2413-
/* If global, we need to also start the max tracer */
2414-
if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
2415-
return tracing_start();
2416-
2417-
raw_spin_lock_irqsave(&tr->start_lock, flags);
2418-
2419-
if (--tr->stop_count) {
2420-
if (tr->stop_count < 0) {
2421-
/* Someone screwed up their debugging */
2422-
WARN_ON_ONCE(1);
2423-
tr->stop_count = 0;
2424-
}
2425-
goto out;
2426-
}
2427-
2428-
buffer = tr->array_buffer.buffer;
2429-
if (buffer)
2430-
ring_buffer_record_enable(buffer);
2392+
arch_spin_unlock(&tr->max_lock);
24312393

24322394
out:
24332395
raw_spin_unlock_irqrestore(&tr->start_lock, flags);
24342396
}
24352397

24362398
/**
2437-
* tracing_stop - quick stop of the tracer
2399+
* tracing_start - quick start of the tracer
24382400
*
2439-
* Light weight way to stop tracing. Use in conjunction with
2440-
* tracing_start.
2401+
* If tracing is enabled but was stopped by tracing_stop,
2402+
* this will start the tracer back up.
24412403
*/
2442-
void tracing_stop(void)
2404+
void tracing_start(void)
2405+
2406+
{
2407+
return tracing_start_tr(&global_trace);
2408+
}
2409+
2410+
static void tracing_stop_tr(struct trace_array *tr)
24432411
{
24442412
struct trace_buffer *buffer;
24452413
unsigned long flags;
24462414

2447-
raw_spin_lock_irqsave(&global_trace.start_lock, flags);
2448-
if (global_trace.stop_count++)
2415+
raw_spin_lock_irqsave(&tr->start_lock, flags);
2416+
if (tr->stop_count++)
24492417
goto out;
24502418

24512419
/* Prevent the buffers from switching */
2452-
arch_spin_lock(&global_trace.max_lock);
2420+
arch_spin_lock(&tr->max_lock);
24532421

2454-
buffer = global_trace.array_buffer.buffer;
2422+
buffer = tr->array_buffer.buffer;
24552423
if (buffer)
24562424
ring_buffer_record_disable(buffer);
24572425

24582426
#ifdef CONFIG_TRACER_MAX_TRACE
2459-
buffer = global_trace.max_buffer.buffer;
2427+
buffer = tr->max_buffer.buffer;
24602428
if (buffer)
24612429
ring_buffer_record_disable(buffer);
24622430
#endif
24632431

2464-
arch_spin_unlock(&global_trace.max_lock);
2432+
arch_spin_unlock(&tr->max_lock);
24652433

24662434
out:
2467-
raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
2435+
raw_spin_unlock_irqrestore(&tr->start_lock, flags);
24682436
}
24692437

2470-
static void tracing_stop_tr(struct trace_array *tr)
2438+
/**
2439+
* tracing_stop - quick stop of the tracer
2440+
*
2441+
* Light weight way to stop tracing. Use in conjunction with
2442+
* tracing_start.
2443+
*/
2444+
void tracing_stop(void)
24712445
{
2472-
struct trace_buffer *buffer;
2473-
unsigned long flags;
2474-
2475-
/* If global, we need to also stop the max tracer */
2476-
if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
2477-
return tracing_stop();
2478-
2479-
raw_spin_lock_irqsave(&tr->start_lock, flags);
2480-
if (tr->stop_count++)
2481-
goto out;
2482-
2483-
buffer = tr->array_buffer.buffer;
2484-
if (buffer)
2485-
ring_buffer_record_disable(buffer);
2486-
2487-
out:
2488-
raw_spin_unlock_irqrestore(&tr->start_lock, flags);
2446+
return tracing_stop_tr(&global_trace);
24892447
}
24902448

24912449
static int trace_save_cmdline(struct task_struct *tsk)

0 commit comments

Comments
 (0)