tracing: Optimize trace_printk() with one arg to use trace_puts()
[deliverable/linux.git] / include / linux / kernel.h
index a3a5574a61fc932aaabeba220e3a4c8559c1b56c..d0a16fe03fefdc5b4edf207192b05890f3716f71 100644 (file)
@@ -516,9 +516,30 @@ do {                                                                       \
  * Please refrain from leaving trace_printks scattered around in
  * your code. (Extra memory is used for special buffers that are
  * allocated when trace_printk() is used)
+ *
+ * A little optization trick is done here. If there's only one
+ * argument, there's no need to scan the string for printf formats.
+ * The trace_puts() will suffice. But how can we take advantage of
+ * using trace_puts() when trace_printk() has only one argument?
+ * By stringifying the args and checking the size we can tell
+ * whether or not there are args. __stringify((__VA_ARGS__)) will
+ * turn into "()\0" with a size of 3 when there are no args, anything
+ * else will be bigger. All we need to do is define a string to this,
+ * and then take its size and compare to 3. If it's bigger, use
+ * do_trace_printk() otherwise, optimize it to trace_puts(). Then just
+ * let gcc optimize the rest.
  */
 
-#define trace_printk(fmt, args...)                                     \
+#define trace_printk(fmt, ...)                         \
+do {                                                   \
+       char _______STR[] = __stringify((__VA_ARGS__)); \
+       if (sizeof(_______STR) > 3)                     \
+               do_trace_printk(fmt, ##__VA_ARGS__);    \
+       else                                            \
+               trace_puts(fmt);                        \
+} while (0)
+
+#define do_trace_printk(fmt, args...)                                  \
 do {                                                                   \
        static const char *trace_printk_fmt                             \
                __attribute__((section("__trace_printk_fmt"))) =        \
This page took 0.025382 seconds and 5 git commands to generate.