lkml.org 
[lkml]   [2018]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] do not call trace_printk on non-debug build
Date
From: Wei Wang <wvw@google.com>

trace_printk will cause trace_printk_init_buffers executed in kernel
start, which will increase memory and also show bad warnings in
production kernel.

Signed-off-by: Wei Wang <wvw@google.com>
---
include/linux/kernel.h | 17 +++++++++++++++++
include/linux/trace_events.h | 4 ++++
2 files changed, 21 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6a1eb0b0aad96..f1a003e5986a9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -677,6 +677,7 @@ do { \
* let gcc optimize the rest.
*/

+#if defined(DEBUG)
#define trace_printk(fmt, ...) \
do { \
char _______STR[] = __stringify((__VA_ARGS__)); \
@@ -685,7 +686,11 @@ do { \
else \
trace_puts(fmt); \
} while (0)
+#else
+#define trace_printk(fmt, ...)
+#endif

+#if defined(DEBUG)
#define do_trace_printk(fmt, args...) \
do { \
static const char *trace_printk_fmt __used \
@@ -699,6 +704,9 @@ do { \
else \
__trace_printk(_THIS_IP_, fmt, ##args); \
} while (0)
+#else
+#define do_trace_printk(fmt, args...)
+#endif

extern __printf(2, 3)
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
@@ -731,6 +739,7 @@ int __trace_printk(unsigned long ip, const char *fmt, ...);
* (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
*/

+#if defined(DEBUG)
#define trace_puts(str) ({ \
static const char *trace_printk_fmt __used \
__attribute__((section("__trace_printk_fmt"))) = \
@@ -741,6 +750,10 @@ int __trace_printk(unsigned long ip, const char *fmt, ...);
else \
__trace_puts(_THIS_IP_, str, strlen(str)); \
})
+#else
+#define trace_puts(str)
+#endif
+
extern int __trace_bputs(unsigned long ip, const char *str);
extern int __trace_puts(unsigned long ip, const char *str, int size);

@@ -751,6 +764,7 @@ extern void trace_dump_stack(int skip);
* if we try to allocate the static variable to fmt if it is not a
* constant. Even with the outer if statement.
*/
+#if defined(DEBUG)
#define ftrace_vprintk(fmt, vargs) \
do { \
if (__builtin_constant_p(fmt)) { \
@@ -762,6 +776,9 @@ do { \
} else \
__ftrace_vprintk(_THIS_IP_, fmt, vargs); \
} while (0)
+#else
+#define ftrace_vprintk(fmt, vargs)
+#endif

extern __printf(2, 0) int
__ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 2bde3eff564cd..433208a1c6009 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -533,6 +533,7 @@ int trace_set_clr_event(const char *system, const char *event, int set);
* if we try to allocate the static variable to fmt if it is not a
* constant. Even with the outer if statement optimizing out.
*/
+#if defined(DEBUG)
#define event_trace_printk(ip, fmt, args...) \
do { \
__trace_printk_check_format(fmt, ##args); \
@@ -546,6 +547,9 @@ do { \
} else \
__trace_printk(ip, fmt, ##args); \
} while (0)
+#else
+#define event_trace_printk(ip, fmt, args...)
+#endif

#ifdef CONFIG_PERF_EVENTS
struct perf_event;
--
2.17.0.484.g0c8726318c-goog
\
 
 \ /
  Last update: 2018-04-24 20:09    [W:0.088 / U:1.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site