All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] do not call trace_printk on non-debug build
@ 2018-04-24 18:08 Wei Wang
  2018-04-24 18:50 ` Steven Rostedt
  0 siblings, 1 reply; 14+ messages in thread
From: Wei Wang @ 2018-04-24 18:08 UTC (permalink / raw)
  Cc: gregkh, wei.vince.wang, Wei Wang, Steven Rostedt, Ingo Molnar,
	Andrew Morton, Kees Cook, Peter Zijlstra, Thomas Gleixner,
	Crt Mori, Alexei Starovoitov, Randy Dunlap, linux-kernel

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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-04-27  1:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24 18:08 [PATCH] do not call trace_printk on non-debug build Wei Wang
2018-04-24 18:50 ` Steven Rostedt
2018-04-24 19:02   ` Wei Wang
2018-04-24 19:14     ` Steven Rostedt
2018-04-24 19:20       ` Wei Wang
2018-04-24 19:26         ` Steven Rostedt
2018-04-24 20:39           ` Wei Wang
2018-04-24 20:45             ` Steven Rostedt
2018-04-24 20:48               ` Steven Rostedt
2018-04-24 21:32                 ` Wei Wang
2018-04-25  0:49               ` Randy Dunlap
2018-04-25  4:53           ` Wei Wang
2018-04-27  1:46             ` Steven Rostedt
2018-04-25  6:12     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.