History

[PATCH] clean up kernel messages

Arrange for all kernel printks to be no-ops. Only available if CONFIG_EMBEDDED. This patch saves about 375k on my laptop config and nearly 100k on minimal configs.

Matt Mackall committed 21 years ago

Commit d59745c1 parent cd7619d4 files · +43 −6Browse files

Unified · Split

4 files
  1. arch/i386/kernel/head.S +2 −0
  2. include/linux/kernel.h +9 −0
  3. init/Kconfig +11 −0
  4. kernel/printk.c +21 −6
arch/i386/kernel/head.S+2−0
@@ -380,6 +380,7 @@ rp_sidt: · 379 unmodified lines
380380 ALIGN
381381 ignore_int:
382382 cld
383+#ifdef CONFIG_PRINTK
383384 pushl %eax
384385 pushl %ecx
385386 pushl %edx
@@ -400,6 +401,7 @@ ignore_int: · 14 unmodified lines
400401 popl %edx
401402 popl %ecx
402403 popl %eax
404+#endif
403405 iret
404406
405407 /*
include/linux/kernel.h+9−0
@@ -115,10 +115,19 @@ extern int __kernel_text_address(unsigned long addr); · 114 unmodified lines
115115 extern int kernel_text_address(unsigned long addr);
116116 extern int session_of_pgrp(int pgrp);
117117
118+#ifdef CONFIG_PRINTK
118119 asmlinkage int vprintk(const char *fmt, va_list args)
119120 __attribute__ ((format (printf, 1, 0)));
120121 asmlinkage int printk(const char * fmt, ...)
121122 __attribute__ ((format (printf, 1, 2)));
123+#else
124+static inline int vprintk(const char *s, va_list args)
125+ __attribute__ ((format (printf, 1, 0)));
126+static inline int vprintk(const char *s, va_list args) { return 0; }
127+static inline int printk(const char *s, ...)
128+ __attribute__ ((format (printf, 1, 2)));
129+static inline int printk(const char *s, ...) { return 0; }
130+#endif
122131
123132 unsigned long int_sqrt(unsigned long);
124133
init/Kconfig+11−0
@@ -275,6 +275,17 @@ config KALLSYMS_EXTRA_PASS · 274 unmodified lines
275275 reported. KALLSYMS_EXTRA_PASS is only a temporary workaround while
276276 you wait for kallsyms to be fixed.
277277
278+
279+config PRINTK
280+ default y
281+ bool "Enable support for printk" if EMBEDDED
282+ help
283+ This option enables normal printk support. Removing it
284+ eliminates most of the message strings from the kernel image
285+ and makes the kernel more or less silent. As this makes it
286+ very difficult to diagnose system problems, saying N here is
287+ strongly discouraged.
288+
278289 config BUG
279290 bool "BUG() support" if EMBEDDED
280291 default y
kernel/printk.c+21−6
@@ -85,10 +85,6 @@ static int console_locked; · 84 unmodified lines
8585 */
8686 static DEFINE_SPINLOCK(logbuf_lock);
8787
88−static char __log_buf[__LOG_BUF_LEN];
89−static char *log_buf = __log_buf;
90−static int log_buf_len = __LOG_BUF_LEN;
91−
9288 #define LOG_BUF_MASK (log_buf_len-1)
9389 #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
9490
@@ -99,7 +95,6 @@ static int log_buf_len = __LOG_BUF_LEN; · 4 unmodified lines
9995 static unsigned long log_start; /* Index into log_buf: next char to be read by syslog() */
10096 static unsigned long con_start; /* Index into log_buf: next char to be sent to consoles */
10197 static unsigned long log_end; /* Index into log_buf: most-recently-written-char + 1 */
102−static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */
10398
10499 /*
105100 * Array of consoles built from command line options (console=)
@@ -120,6 +115,13 @@ static int preferred_console = -1; · 14 unmodified lines
120115 /* Flag: console code may call schedule() */
121116 static int console_may_schedule;
122117
118+#ifdef CONFIG_PRINTK
119+
120+static char __log_buf[__LOG_BUF_LEN];
121+static char *log_buf = __log_buf;
122+static int log_buf_len = __LOG_BUF_LEN;
123+static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */
124+
123125 /*
124126 * Setup a list of consoles. Called from init/main.c
125127 */
@@ -535,6 +537,7 @@ __setup("time", printk_time_setup); · 409 unmodified lines
535537 * then changes console_loglevel may break. This is because console_loglevel
536538 * is inspected when the actual printing occurs.
537539 */
540+
538541 asmlinkage int printk(const char *fmt, ...)
539542 {
540543 va_list args;
@@ -655,6 +658,18 @@ out: · 114 unmodified lines
655658 EXPORT_SYMBOL(printk);
656659 EXPORT_SYMBOL(vprintk);
657660
661+#else
662+
663+asmlinkage long sys_syslog(int type, char __user * buf, int len)
664+{
665+ return 0;
666+}
667+
668+int do_syslog(int type, char __user * buf, int len) { return 0; }
669+static void call_console_drivers(unsigned long start, unsigned long end) {}
670+
671+#endif
672+
658673 /**
659674 * acquire_console_sem - lock the console system for exclusive use.
660675 *
@@ -931,7 +946,7 @@ int unregister_console(struct console * console) · 270 unmodified lines
931946 return res;
932947 }
933948 EXPORT_SYMBOL(unregister_console);
934−
949+
935950 /**
936951 * tty_write_message - write a message to a certain tty, not just the console.
937952 *