tracing: optimize trace_printk()
authorIngo Molnar <mingo@elte.hu>
Mon, 9 Mar 2009 09:11:36 +0000 (10:11 +0100)
committerIngo Molnar <mingo@elte.hu>
Mon, 9 Mar 2009 09:11:36 +0000 (10:11 +0100)
Impact: micro-optimization

trace_printk() does this unconditionally:

trace_printk_fmt = fmt;

Where trace_printk_fmt is an entry into a global array. This is
very SMP-unfriendly.

So only write it once per bootup.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1236356510-8381-5-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/kernel.h

index 4e726b9a71ec5a8d418b43f165b5714aa21312f7..7742798c920880f1e194bd2c44eb1a5a47f00288 100644 (file)
@@ -454,7 +454,10 @@ do {                                                                       \
 do {                                                                   \
        static const char *trace_printk_fmt                             \
        __attribute__((section("__trace_printk_fmt")));                 \
 do {                                                                   \
        static const char *trace_printk_fmt                             \
        __attribute__((section("__trace_printk_fmt")));                 \
-       trace_printk_fmt = fmt;                                 \
+                                                                       \
+       if (!trace_printk_fmt)                                          \
+               trace_printk_fmt = fmt;                                 \
+                                                                       \
        __trace_printk_check_format(fmt, ##args);                       \
        __trace_printk(_THIS_IP_, trace_printk_fmt, ##args);            \
 } while (0)
        __trace_printk_check_format(fmt, ##args);                       \
        __trace_printk(_THIS_IP_, trace_printk_fmt, ##args);            \
 } while (0)
@@ -467,7 +470,10 @@ __trace_printk(unsigned long ip, const char *fmt, ...)
 do {                                                                   \
        static const char *trace_printk_fmt                             \
        __attribute__((section("__trace_printk_fmt")));                 \
 do {                                                                   \
        static const char *trace_printk_fmt                             \
        __attribute__((section("__trace_printk_fmt")));                 \
-       trace_printk_fmt = fmt;                                 \
+                                                                       \
+       if (!trace_printk_fmt)                                          \
+               trace_printk_fmt = fmt;                                 \
+                                                                       \
        __ftrace_vprintk(_THIS_IP_, trace_printk_fmt, vargs);           \
 } while (0)
 
        __ftrace_vprintk(_THIS_IP_, trace_printk_fmt, vargs);           \
 } while (0)