[OPW,kernel,v3,2/4] printk: Compile out all printk messages below a certain priority level.
diff mbox

Message ID fb0fdbfe18c3336936302e4cdeeb4e882f5dc94e.1414653432.git.kumari.radha3@gmail.com
State New, archived
Headers show

Commit Message

Kumari Radha Oct. 30, 2014, 7:56 a.m. UTC
This patch compiles out all printk messages below a certain priority
level defined by CONFIG_PRINTK_LOG_PRIORITY making it a no-op, one
that GCC still checks for format string issues before throwing away.

Output of size(defconfig vs defconfig with CONFIG_PRINTK_LOG_PRIORITY
at each level):

  text     data     bss     dec     hex filename
10621917  736768 1810432 13169117 c8f1dd vmlinux.default

10534394  738184 1810432 13083010 c7a182 vmlinux.level5

10529194  734088 1810432 13073714 c77d32 vmlinux.level4

10501696  734088 1810432 13046216 c711c8 vmlinux.level3

10457965  734088 1810432 13002485 c666f5 vmlinux.level2

10457093  734088 1810432 13001613 c6638d vmlinux.level1

10456949  734088 1810432 13001469 c662fd vmlinux.level0

Signed-off-by: Kumari Radha <kumari.radha3@gmail.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
---
 include/linux/printk.h |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/include/linux/printk.h b/include/linux/printk.h
index d78125f..474feb8 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -232,19 +232,57 @@  extern asmlinkage void dump_stack(void) __cold;
  */
 #define pr_emerg(fmt, ...) \
 	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+
+/* Compile out printks below CONFIG_PRINTK_LOG_PRIORITY */
+#if (CONFIG_PRINTK_LOG_PRIORITY < 1)
+#define pr_alert(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_alert(fmt, ...) \
 	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 2)
+#define pr_crit(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_crit(fmt, ...) \
 	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 3)
+#define pr_err(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_err(fmt, ...) \
 	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 4)
+#define pr_warning(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_warning(fmt, ...) \
 	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#endif
 #define pr_warn pr_warning
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 5)
+#define pr_notice(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_notice(fmt, ...) \
 	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 6)
+#define pr_info(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_info(fmt, ...) \
 	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
 #define pr_cont(fmt, ...) \
 	printk(KERN_CONT fmt, ##__VA_ARGS__)
 
@@ -259,8 +297,11 @@  extern asmlinkage void dump_stack(void) __cold;
 
 #include <linux/dynamic_debug.h>
 
+#if (CONFIG_PRINTK_LOG_PRIORITY < 7)
+#define pr_debug(fmt, ...) \
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
 /* If you are writing a driver, please use dev_dbg instead */
-#if defined(CONFIG_DYNAMIC_DEBUG)
+#elif defined(CONFIG_DYNAMIC_DEBUG)
 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
 #define pr_debug(fmt, ...) \
 	dynamic_pr_debug(fmt, ##__VA_ARGS__)