Skip to content

Commit b538bf7

Browse files
committed
tracing: Disable snapshot buffer when stopping instance tracers
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/[email protected] Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Fixes: 6d9b3fa ("tracing: Move tracing_max_latency into trace_array") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent d78ab79 commit b538bf7

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
@@ -2360,133 +2360,91 @@ int is_tracing_stopped(void)
23602360
return global_trace.stop_count;
23612361
}
23622362

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

23742368
if (tracing_disabled)
23752369
return;
23762370

2377-
raw_spin_lock_irqsave(&global_trace.start_lock, flags);
2378-
if (--global_trace.stop_count) {
2379-
if (global_trace.stop_count < 0) {
2371+
raw_spin_lock_irqsave(&tr->start_lock, flags);
2372+
if (--tr->stop_count) {
2373+
if (WARN_ON_ONCE(tr->stop_count < 0)) {
23802374
/* Someone screwed up their debugging */
2381-
WARN_ON_ONCE(1);
2382-
global_trace.stop_count = 0;
2375+
tr->stop_count = 0;
23832376
}
23842377
goto out;
23852378
}
23862379

23872380
/* Prevent the buffers from switching */
2388-
arch_spin_lock(&global_trace.max_lock);
2381+
arch_spin_lock(&tr->max_lock);
23892382

2390-
buffer = global_trace.array_buffer.buffer;
2383+
buffer = tr->array_buffer.buffer;
23912384
if (buffer)
23922385
ring_buffer_record_enable(buffer);
23932386

23942387
#ifdef CONFIG_TRACER_MAX_TRACE
2395-
buffer = global_trace.max_buffer.buffer;
2388+
buffer = tr->max_buffer.buffer;
23962389
if (buffer)
23972390
ring_buffer_record_enable(buffer);
23982391
#endif
23992392

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

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

24372399
/**
2438-
* tracing_stop - quick stop of the tracer
2400+
* tracing_start - quick start of the tracer
24392401
*
2440-
* Light weight way to stop tracing. Use in conjunction with
2441-
* tracing_start.
2402+
* If tracing is enabled but was stopped by tracing_stop,
2403+
* this will start the tracer back up.
24422404
*/
2443-
void tracing_stop(void)
2405+
void tracing_start(void)
2406+
2407+
{
2408+
return tracing_start_tr(&global_trace);
2409+
}
2410+
2411+
static void tracing_stop_tr(struct trace_array *tr)
24442412
{
24452413
struct trace_buffer *buffer;
24462414
unsigned long flags;
24472415

2448-
raw_spin_lock_irqsave(&global_trace.start_lock, flags);
2449-
if (global_trace.stop_count++)
2416+
raw_spin_lock_irqsave(&tr->start_lock, flags);
2417+
if (tr->stop_count++)
24502418
goto out;
24512419

24522420
/* Prevent the buffers from switching */
2453-
arch_spin_lock(&global_trace.max_lock);
2421+
arch_spin_lock(&tr->max_lock);
24542422

2455-
buffer = global_trace.array_buffer.buffer;
2423+
buffer = tr->array_buffer.buffer;
24562424
if (buffer)
24572425
ring_buffer_record_disable(buffer);
24582426

24592427
#ifdef CONFIG_TRACER_MAX_TRACE
2460-
buffer = global_trace.max_buffer.buffer;
2428+
buffer = tr->max_buffer.buffer;
24612429
if (buffer)
24622430
ring_buffer_record_disable(buffer);
24632431
#endif
24642432

2465-
arch_spin_unlock(&global_trace.max_lock);
2433+
arch_spin_unlock(&tr->max_lock);
24662434

24672435
out:
2468-
raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
2436+
raw_spin_unlock_irqrestore(&tr->start_lock, flags);
24692437
}
24702438

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

24922450
static int trace_save_cmdline(struct task_struct *tsk)

0 commit comments

Comments
 (0)