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

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

Commit Message

Kumari Radha Oct. 30, 2014, 7:57 a.m. UTC
This patch compiles out all pr_*_once 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

10533818  738184 1810432 13082434 c79f42 vmlinux.once.level5

10528618  734088 1810432 13073138 c77af2 vmlinux.once.level4

10496000  738056 1810432 13044488 c70b08 vmlinux.once.level3

10452141  738056 1810432 13000629 c65fb5 vmlinux.once.level2

10451205  738056 1810432 12999693 c65c0d vmlinux.once.level1

10451125  738056 1810432 12999613 c65bbd vmlinux.once.level0

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

Patch
diff mbox

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 474feb8..9de9cba8 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -345,18 +345,56 @@  extern asmlinkage void dump_stack(void) __cold;
 
 #define pr_emerg_once(fmt, ...)					\
 	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+
+/* pr_*_once produces zero code below CONFIG_PRINTK_LOG_PRIORITY */
+#if (CONFIG_PRINTK_LOG_PRIORITY < 1)
+#define pr_alert_once(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_alert_once(fmt, ...)					\
 	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 2)
+#define pr_crit_once(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_crit_once(fmt, ...)					\
 	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 3)
+#define pr_err_once(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_err_once(fmt, ...)					\
 	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 4)
+#define pr_warn_once(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_warn_once(fmt, ...)					\
 	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 5)
+#define pr_notice_once(fmt, ...)				\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_notice_once(fmt, ...)				\
 	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 6)
+#define pr_info_once(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS)
+#else
 #define pr_info_once(fmt, ...)					\
 	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
 #define pr_cont_once(fmt, ...)					\
 	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)