tracing: Enable comm recording if trace_printk() is used
authorSteven Rostedt <srostedt@redhat.com>
Thu, 11 Oct 2012 14:15:05 +0000 (10:15 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 31 Oct 2012 20:45:29 +0000 (16:45 -0400)
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>
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events.c

index a5411b7414b16c56fdc90dd562561d6a22e2fbfd..b90a827a4641b0a53de7dd3203a039a71b3b7ad2 100644 (file)
@@ -1559,10 +1559,10 @@ static int alloc_percpu_trace_buffer(void)
        return -ENOMEM;
 }
 
+static int buffers_allocated;
+
 void trace_printk_init_buffers(void)
 {
-       static int buffers_allocated;
-
        if (buffers_allocated)
                return;
 
@@ -1575,6 +1575,34 @@ void trace_printk_init_buffers(void)
        tracing_update_buffers();
 
        buffers_allocated = 1;
+
+       /*
+        * trace_printk_init_buffers() can be called by modules.
+        * If that happens, then we need to start cmdline recording
+        * directly here. If the global_trace.buffer is already
+        * allocated here, then this was called by module code.
+        */
+       if (global_trace.buffer)
+               tracing_start_cmdline_record();
+}
+
+void trace_printk_start_comm(void)
+{
+       /* Start tracing comms if trace printk is set */
+       if (!buffers_allocated)
+               return;
+       tracing_start_cmdline_record();
+}
+
+static void trace_printk_start_stop_comm(int enabled)
+{
+       if (!buffers_allocated)
+               return;
+
+       if (enabled)
+               tracing_start_cmdline_record();
+       else
+               tracing_stop_cmdline_record();
 }
 
 /**
@@ -2797,6 +2825,9 @@ static void set_tracer_flags(unsigned int mask, int enabled)
 
        if (mask == TRACE_ITER_OVERWRITE)
                ring_buffer_change_overwrite(global_trace.buffer, enabled);
+
+       if (mask == TRACE_ITER_PRINTK)
+               trace_printk_start_stop_comm(enabled);
 }
 
 static ssize_t
@@ -5099,6 +5130,7 @@ __init static int tracer_alloc_buffers(void)
 
        /* Only allocate trace_printk buffers if a trace_printk exists */
        if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
+               /* Must be called before global_trace.buffer is allocated */
                trace_printk_init_buffers();
 
        /* To save memory, keep the ring buffer size to its minimum */
index c56a233c006e107edc69ecf8418441b80a054401..7824a55bd3fcc43f72adb6737af94da40c56b1e8 100644 (file)
@@ -841,6 +841,7 @@ extern const char *__start___trace_bprintk_fmt[];
 extern const char *__stop___trace_bprintk_fmt[];
 
 void trace_printk_init_buffers(void);
+void trace_printk_start_comm(void);
 
 #undef FTRACE_ENTRY
 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter)    \
index d608d09d08c0de8ba8bab4a3e0b1edd6df30c033..dec47e70e25437817a76c0773e9faca39c443d4d 100644 (file)
@@ -1489,6 +1489,9 @@ static __init int event_trace_enable(void)
                if (ret)
                        pr_warn("Failed to enable trace event: %s\n", token);
        }
+
+       trace_printk_start_comm();
+
        return 0;
 }