[PATCH] support for fine-grained control of printk messages
Tim Bird
tim.bird at am.sony.com
Thu Jul 13 22:20:47 CDT 2006
Hi all,
This is a patch I've had kicking around for some time, that I finally
decided to release. We've used this feature inside Sony. Basically
it allows you to control, on a file-by-file basis, which printk messages
to include in your kernel. The patch is against linux 2.6.17.4 from
kernel.org, and is pretty small.
Usage instructions are included in the Kconfig help, and online
on a wiki page I've created for it. The wiki page also
has some results using this on an x86 machine.
See: http://tree.celinuxforum.org/CelfPubWiki/DoPrintk
I hope others find this useful. Comments and feedback are
appreciated. If people think this is a good idea, I'll try
to mainline it.
diffstat:
include/linux/kernel.h | 2 +-
init/Kconfig | 24 +++++++++++++++++++++---
kernel/printk.c | 7 ++++++-
3 files changed, 28 insertions(+), 5 deletions(-)
Signed-off-by: Tim Bird <tim.bird at am.sony.com>
----------------------------
Index: linux/include/linux/kernel.h
===================================================================
--- linux.orig/include/linux/kernel.h 2006-07-13 16:41:52.000000000 -0700
+++ linux/include/linux/kernel.h 2006-07-13 16:42:09.000000000 -0700
@@ -131,7 +131,7 @@
extern void dump_thread(struct pt_regs *regs, struct user *dump);
-#ifdef CONFIG_PRINTK
+#if defined(CONFIG_PRINTK) || (defined(CONFIG_PRINTK_FUNC) && defined(DO_PRINTK))
asmlinkage int vprintk(const char *fmt, va_list args)
__attribute__ ((format (printf, 1, 0)));
asmlinkage int printk(const char * fmt, ...)
Index: linux/init/Kconfig
===================================================================
--- linux.orig/init/Kconfig 2006-07-13 16:41:52.000000000 -0700
+++ linux/init/Kconfig 2006-07-13 16:42:09.000000000 -0700
@@ -305,15 +305,33 @@
disabling this option for embedded systems that do not use modules, a
dynamic /dev tree, or dynamic device discovery. Just say Y.
+config PRINTK_FUNC
+ default y
+ bool "Enable printk function in the kernel" if EMBEDDED
+ help
+ This option controls whether the printk function is compiled
+ into the kernel or not. Removing it eliminates a small amount of
+ code size from the kernel, which is OK if it is not being used.
+ See CONFIG_PRINTK to disable the function calls to printk(),
+ which is where the big win comes in reducing kernel size.
+
config PRINTK
default y
- bool "Enable support for printk" if EMBEDDED
+ bool "Enable support for printk messages" if EMBEDDED
+ depends on PRINTK_FUNC
help
This option enables normal printk support. Removing it
eliminates most of the message strings from the kernel image
and makes the kernel more or less silent. As this makes it
- very difficult to diagnose system problems, saying N here is
- strongly discouraged.
+ very difficult to diagnose system problems, saying N here on
+ non-embedded systems is strongly discouraged.
+
+ With this set to 'N', if the printk function is still enabled,
+ (see CONFIG_PRINTK_FUNC) you can enable printk messages from
+ a single file, by putting "#define DO_PRINTK" at the top of
+ the file. This must appear before any #include lines.
+ This makes it possible to have fine-grained control over
+ which printk messages to include in the kernel.
config BUG
bool "BUG() support" if EMBEDDED
Index: linux/kernel/printk.c
===================================================================
--- linux.orig/kernel/printk.c 2006-07-13 16:41:52.000000000 -0700
+++ linux/kernel/printk.c 2006-07-13 16:42:46.000000000 -0700
@@ -16,6 +16,11 @@
* 01Mar01 Andrew Morton <andrewm at uow.edu.au>
*/
+/*
+ * have kernel.h produce real declarations, depending on configuration
+ */
+#define DO_PRINTK 1
+
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/tty.h>
@@ -115,7 +120,7 @@
/* Flag: console code may call schedule() */
static int console_may_schedule;
-#ifdef CONFIG_PRINTK
+#ifdef CONFIG_PRINTK_FUNC
static char __log_buf[__LOG_BUF_LEN];
static char *log_buf = __log_buf;
More information about the Linux-tiny
mailing list