Skip to content

Commit 8169883

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Enable comm recording if trace_printk() is used
If comm recording is not enabled when trace_printk() is used then you just get this type of output: [ adding trace_printk("hello! %d", irq); in do_IRQ ] <...>-2843 [001] d.h. 80.812300: do_IRQ: hello! 14 <...>-2734 [002] d.h2 80.824664: do_IRQ: hello! 14 <...>-2713 [003] d.h. 80.829971: do_IRQ: hello! 14 <...>-2814 [000] d.h. 80.833026: do_IRQ: hello! 14 By enabling the comm recorder when trace_printk is enabled: hackbench-6715 [001] d.h. 193.233776: do_IRQ: hello! 21 sshd-2659 [001] d.h. 193.665862: do_IRQ: hello! 21 <idle>-0 [001] d.h1 193.665996: do_IRQ: hello! 21 Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent b382ede commit 8169883

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,10 +1559,10 @@ static int alloc_percpu_trace_buffer(void)
15591559
return -ENOMEM;
15601560
}
15611561

1562+
static int buffers_allocated;
1563+
15621564
void trace_printk_init_buffers(void)
15631565
{
1564-
static int buffers_allocated;
1565-
15661566
if (buffers_allocated)
15671567
return;
15681568

@@ -1575,6 +1575,34 @@ void trace_printk_init_buffers(void)
15751575
tracing_update_buffers();
15761576

15771577
buffers_allocated = 1;
1578+
1579+
/*
1580+
* trace_printk_init_buffers() can be called by modules.
1581+
* If that happens, then we need to start cmdline recording
1582+
* directly here. If the global_trace.buffer is already
1583+
* allocated here, then this was called by module code.
1584+
*/
1585+
if (global_trace.buffer)
1586+
tracing_start_cmdline_record();
1587+
}
1588+
1589+
void trace_printk_start_comm(void)
1590+
{
1591+
/* Start tracing comms if trace printk is set */
1592+
if (!buffers_allocated)
1593+
return;
1594+
tracing_start_cmdline_record();
1595+
}
1596+
1597+
static void trace_printk_start_stop_comm(int enabled)
1598+
{
1599+
if (!buffers_allocated)
1600+
return;
1601+
1602+
if (enabled)
1603+
tracing_start_cmdline_record();
1604+
else
1605+
tracing_stop_cmdline_record();
15781606
}
15791607

15801608
/**
@@ -2797,6 +2825,9 @@ static void set_tracer_flags(unsigned int mask, int enabled)
27972825

27982826
if (mask == TRACE_ITER_OVERWRITE)
27992827
ring_buffer_change_overwrite(global_trace.buffer, enabled);
2828+
2829+
if (mask == TRACE_ITER_PRINTK)
2830+
trace_printk_start_stop_comm(enabled);
28002831
}
28012832

28022833
static ssize_t
@@ -5099,6 +5130,7 @@ __init static int tracer_alloc_buffers(void)
50995130

51005131
/* Only allocate trace_printk buffers if a trace_printk exists */
51015132
if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
5133+
/* Must be called before global_trace.buffer is allocated */
51025134
trace_printk_init_buffers();
51035135

51045136
/* To save memory, keep the ring buffer size to its minimum */

‎kernel/trace/trace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ extern const char *__start___trace_bprintk_fmt[];
841841
extern const char *__stop___trace_bprintk_fmt[];
842842

843843
void trace_printk_init_buffers(void);
844+
void trace_printk_start_comm(void);
844845

845846
#undef FTRACE_ENTRY
846847
#define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \

‎kernel/trace/trace_events.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ static __init int event_trace_enable(void)
14891489
if (ret)
14901490
pr_warn("Failed to enable trace event: %s\n", token);
14911491
}
1492+
1493+
trace_printk_start_comm();
1494+
14921495
return 0;
14931496
}
14941497

0 commit comments

Comments
 (0)