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

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

Commit Message

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

10528554  734024 1810432 13073010 c77a72 vmlinux.ratelimited.level4

10495360  737864 1810432 13043656 c707c8 vmlinux.ratelimited.level3

10451373  737800 1810432 12999605 c65bb5 vmlinux.ratelimited.level2

10450501  733704 1810432 12994637 c6484d vmlinux.ratelimited.level1

10450357  733704 1810432 12994493 c647bd vmlinux.ratelimited.level0

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

Patch
diff mbox

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 9de9cba8..23fb5e5 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -436,18 +436,55 @@  extern asmlinkage void dump_stack(void) __cold;
 
 #define pr_emerg_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+
+/* pr_*_ratelimited produces zero code below CONFIG_PRINTK_LOG_PRIORITY */
+#if (CONFIG_PRINTK_LOG_PRIORITY < 1)
+#define pr_alert_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_alert_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 2)
+#define pr_crit_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_crit_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 3)
+#define pr_err_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_err_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 4)
+#define pr_warn_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_warn_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 5)
+#define pr_notice_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_notice_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#if (CONFIG_PRINTK_LOG_PRIORITY < 6)
+#define pr_info_ratelimited(fmt, ...)					\
+	no_printk(pr_fmt(fmt), ##__VA_ARGS__)
+#else
 #define pr_info_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#endif
 /* no pr_cont_ratelimited, don't do that... */
 
 #if defined(DEBUG)