From: Wei Wang <wvw@google.com>
Cc: gregkh@linuxfoundation.org, wei.vince.wang@gmail.com,
Wei Wang <wvw@google.com>, Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <keescook@chromium.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>, Crt Mori <cmo@melexis.com>,
Alexei Starovoitov <ast@kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] do not call trace_printk on non-debug build
Date: Tue, 24 Apr 2018 11:08:10 -0700 [thread overview]
Message-ID: <20180424180812.215900-1-wvw@google.com> (raw)
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
next reply other threads:[~2018-04-24 18:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 18:08 Wei Wang [this message]
2018-04-24 18:50 ` [PATCH] do not call trace_printk on non-debug build 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180424180812.215900-1-wvw@google.com \
--to=wvw@google.com \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=cmo@melexis.com \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=wei.vince.wang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox