aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2016-08-02 17:03:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-02 19:35:04 -0400
commit874f9c7da9a4acbc1b9e12ca722579fb50e4d142 (patch)
treea0a327d2092edfc20c453d3f9858633a5369548a /kernel/printk
parentbebca05281d039e4144e1c51f402fd1d5f54b5e2 (diff)
printk: create pr_<level> functions
Using functions instead of macros can reduce overall code size by eliminating unnecessary "KERN_SOH<digit>" prefixes from format strings. defconfig x86-64: $ size vmlinux* text data bss dec hex filename 10193570 4331464 1105920 15630954 ee826a vmlinux.new 10192623 4335560 1105920 15634103 ee8eb7 vmlinux.old As the return value are unimportant and unused in the kernel tree, these new functions return void. Miscellanea: - change pr_<level> macros to call new __pr_<level> functions - change vprintk_nmi and vprintk_default to add LOGLEVEL_<level> argument [akpm@linux-foundation.org: fix LOGLEVEL_INFO, per Joe] Link: http://lkml.kernel.org/r/e16cc34479dfefcae37c98b481e6646f0f69efc3.1466718827.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/internal.h16
-rw-r--r--kernel/printk/nmi.c13
-rw-r--r--kernel/printk/printk.c27
3 files changed, 45 insertions, 11 deletions
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 7fd2838fa417..5d4505f30083 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -16,9 +16,11 @@
16 */ 16 */
17#include <linux/percpu.h> 17#include <linux/percpu.h>
18 18
19typedef __printf(1, 0) int (*printk_func_t)(const char *fmt, va_list args); 19typedef __printf(2, 0) int (*printk_func_t)(int level, const char *fmt,
20 va_list args);
20 21
21int __printf(1, 0) vprintk_default(const char *fmt, va_list args); 22__printf(2, 0)
23int vprintk_default(int level, const char *fmt, va_list args);
22 24
23#ifdef CONFIG_PRINTK_NMI 25#ifdef CONFIG_PRINTK_NMI
24 26
@@ -31,9 +33,10 @@ extern raw_spinlock_t logbuf_lock;
31 * via per-CPU variable. 33 * via per-CPU variable.
32 */ 34 */
33DECLARE_PER_CPU(printk_func_t, printk_func); 35DECLARE_PER_CPU(printk_func_t, printk_func);
34static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args) 36__printf(2, 0)
37static inline int vprintk_func(int level, const char *fmt, va_list args)
35{ 38{
36 return this_cpu_read(printk_func)(fmt, args); 39 return this_cpu_read(printk_func)(level, fmt, args);
37} 40}
38 41
39extern atomic_t nmi_message_lost; 42extern atomic_t nmi_message_lost;
@@ -44,9 +47,10 @@ static inline int get_nmi_message_lost(void)
44 47
45#else /* CONFIG_PRINTK_NMI */ 48#else /* CONFIG_PRINTK_NMI */
46 49
47static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args) 50__printf(2, 0)
51static inline int vprintk_func(int level, const char *fmt, va_list args)
48{ 52{
49 return vprintk_default(fmt, args); 53 return vprintk_default(level, fmt, args);
50} 54}
51 55
52static inline int get_nmi_message_lost(void) 56static inline int get_nmi_message_lost(void)
diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c
index b69eb8a2876f..bc3eeb1ae6da 100644
--- a/kernel/printk/nmi.c
+++ b/kernel/printk/nmi.c
@@ -58,7 +58,7 @@ static DEFINE_PER_CPU(struct nmi_seq_buf, nmi_print_seq);
58 * one writer running. But the buffer might get flushed from another 58 * one writer running. But the buffer might get flushed from another
59 * CPU, so we need to be careful. 59 * CPU, so we need to be careful.
60 */ 60 */
61static int vprintk_nmi(const char *fmt, va_list args) 61static int vprintk_nmi(int level, const char *fmt, va_list args)
62{ 62{
63 struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq); 63 struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
64 int add = 0; 64 int add = 0;
@@ -79,7 +79,16 @@ again:
79 if (!len) 79 if (!len)
80 smp_rmb(); 80 smp_rmb();
81 81
82 add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args); 82 if (level != LOGLEVEL_DEFAULT) {
83 add = snprintf(s->buffer + len, sizeof(s->buffer) - len,
84 KERN_SOH "%c", '0' + level);
85 add += vsnprintf(s->buffer + len + add,
86 sizeof(s->buffer) - len - add,
87 fmt, args);
88 } else {
89 add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len,
90 fmt, args);
91 }
83 92
84 /* 93 /*
85 * Do it once again if the buffer has been flushed in the meantime. 94 * Do it once again if the buffer has been flushed in the meantime.
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 09af62e71fee..d2accf2f4448 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1801,7 +1801,28 @@ asmlinkage int printk_emit(int facility, int level,
1801} 1801}
1802EXPORT_SYMBOL(printk_emit); 1802EXPORT_SYMBOL(printk_emit);
1803 1803
1804int vprintk_default(const char *fmt, va_list args) 1804#ifdef CONFIG_PRINTK
1805#define define_pr_level(func, loglevel) \
1806asmlinkage __visible void func(const char *fmt, ...) \
1807{ \
1808 va_list args; \
1809 \
1810 va_start(args, fmt); \
1811 vprintk_default(loglevel, fmt, args); \
1812 va_end(args); \
1813} \
1814EXPORT_SYMBOL(func)
1815
1816define_pr_level(__pr_emerg, LOGLEVEL_EMERG);
1817define_pr_level(__pr_alert, LOGLEVEL_ALERT);
1818define_pr_level(__pr_crit, LOGLEVEL_CRIT);
1819define_pr_level(__pr_err, LOGLEVEL_ERR);
1820define_pr_level(__pr_warn, LOGLEVEL_WARNING);
1821define_pr_level(__pr_notice, LOGLEVEL_NOTICE);
1822define_pr_level(__pr_info, LOGLEVEL_INFO);
1823#endif
1824
1825int vprintk_default(int level, const char *fmt, va_list args)
1805{ 1826{
1806 int r; 1827 int r;
1807 1828
@@ -1811,7 +1832,7 @@ int vprintk_default(const char *fmt, va_list args)
1811 return r; 1832 return r;
1812 } 1833 }
1813#endif 1834#endif
1814 r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); 1835 r = vprintk_emit(0, level, NULL, 0, fmt, args);
1815 1836
1816 return r; 1837 return r;
1817} 1838}
@@ -1844,7 +1865,7 @@ asmlinkage __visible int printk(const char *fmt, ...)
1844 int r; 1865 int r;
1845 1866
1846 va_start(args, fmt); 1867 va_start(args, fmt);
1847 r = vprintk_func(fmt, args); 1868 r = vprintk_func(LOGLEVEL_DEFAULT, fmt, args);
1848 va_end(args); 1869 va_end(args);
1849 1870
1850 return r; 1871 return r;