dynamic printk
RFC PATCH 1/1 dynamic printk
This patch implements a dynamically auto-resizing printk. It replaces the static printk buffer with a dynamic relayfs channel at init time; the static buffer is copied to the relayfs channel and then discarded.
The relayfs file system it depends on was posted to this list a few minutes ago and is also available at http://www.opersys.com/relayfs.
There are a couple of benefits to using the dynamic version:
- the initial static printk buffer can be made large enough to capture all the boot messages even on a noisy system
- printks are no longer lost, which can come in handy when debugging drivers or the kernel
I've been running it on my uniprocessor x86 development machine, and haven't had any problems. I've verified that it does indeed save printks that the static version loses, by generating a lot of printks from a test module. In fact it should never lose a printk (unless the maximum buffer size is exceeded, currently that's an arbitrary 2M). It still needs testing before I'd put it on a production machine, but it should be pretty useful even so as a tool for diagnosing init-time problems and debugging drivers and other kernel code.
The current version can always be found at
http://www.opersys.com/relayfs/printk-on-relayfs.html.
Known problems:
Buffer shrinking happens only when another printk comes along - if one doesn't come along for awhile, it could remain at its expanded size for awhile. I need to make shrinking happen under a timer.
I wanted to keep the dynamic version separate from the static version but since they're both needed at least until after init, I couldn't just configure one out and the other in. I had to make some of the static printk variables non-static, and do some other ugly things to make the unused static printk functions and variables go away after init. Also the else clause of the new dispatching versions of a few printk functions reference the static versions which would have disappeared after init, but since these paths can never be taken after init, isn't a problem. The alternative would be to use function pointers, but that didn't seem great either. I plan on extending relayfs to work with static buffers, which will remove the need for the static version altogether.
Comments welcome.
include/linux/printk-dynamic.h +38 -0
@@ -0,0 +1,38 @@ +/* +* linux/include/linux/printk-dynamic.h +* +* Copyright (C) 2003 - Tom Zanussi ([email protected]), IBM Corp +* +* Included by static printk (printk.c) so its functions and data +* get the right names and attributes depending on whether dynamic +* printk is configured in or not. Also needed by printk channel +* registerers. +*/ + +#ifndef _LINUX_PRINTK_DYNAMIC_H +#define _LINUX_PRINTK_DYNAMIC_H + +#if defined(CONFIG_DYNAMIC_PRINTK ) +/* static printk needs to be able to find these (in printk-dynamic.c) */ +extern int do_syslog (int type,char * buf,int len); +extern void release_console_sem (void ); +extern int register_printk_channel (void ); +/* static printk data and functions go away after init */ +#define DO_SYSLOG __init do_syslog_static +#define RELEASE_CONSOLE_SEM __init release_console_sem_static +#define _PRINTK __init _printk +#define PRINTK __init unused_printk +#define PRINTK_INITDATA __initdata = { 0, } +#define PRINTK_INIT __init +#else +/* normal printk */ +#define DO_SYSLOG do_syslog +#define RELEASE_CONSOLE_SEM release_console_sem +#define _PRINTK _printk +#define PRINTK printk +#define PRINTK_INITDATA +#define PRINTK_INIT +/* so init compiles if normal printk */ +#define register_printk_channel () (0) +#endif /* CONFIG_DYNAMIC_PRINTK */ +#endif /* _LINUX_PRINTK_DYNAMIC_H */
init/Kconfig +34 -0
@@ -92,6 +92,20 @@ config SYSCTL building a kernel for install/rescue disks or your system is very limited in memory. +config DYNAMIC_PRINTK + bool "Dynamic printk support" if DEBUG_KERNEL + depends on RELAYFS_FS=y + ---help--- + If you say Y here, printk will use a dynamically auto-resizing + buffer. The static printk buffer is still needed for system init, + but will be discarded after that, and so can be configured much + larger if necessary to capture large numbers of init-time messages + (i.e. increase the LOG_BUF_SHIFT value). The normal working size + the dynamic printk buffer will try to maintain is specified by + MIN_LOG_BUF_SHIFT, which should probably be the same value you + would have made the static printk buffer if dynamic printk wasn't + enabled. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" if DEBUG_KERNEL range 12 20
@@ -109,6 +123,26 @@ config LOG_BUF_SHIFT 13 => 8 KB 12 => 4 KB +config MIN_LOG_BUF_SHIFT + int "Dynamic kernel log buffer size (16 => 64KB, 17 => 128KB)" if DYNAMIC_PRINTK + range 12 22 + default 17 if ARCH_S390 + default 16 if X86_NUMAQ || IA64 + default 15 if SMP + default 14 + help + The normal working size the dynamic printk buffer will try to + maintain. This should probably be the same value you would have + made the static printk buffer if dynamic printk wasn't enabled. + + Select dynamic kernel log buffer size as a power of 2. + Defaults and Examples: + 17 => 128 KB for S/390 + 16 => 64 KB for x86 NUMAQ or IA-64 + 15 => 32 KB for SMP + 14 => 16 KB for uniprocessor + 13 => 8 KB + 12 => 4 KB menuconfig EMBEDDED bool "Remove kernel features (for embedded systems)"
init/main.c +5 -0
@@ -38,6 +38,7 @@#include <linux/moduleparam.h> #include <linux/writeback.h> #include <linux/cpu.h> +#include <linux/printk-dynamic.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -551,6 +552,7 @@ extern void prepare_namespace(void);static int init (void * unused) {static char * argv_sh[] = {"sh" ,NULL , }; +int err;lock_kernel ();/*
@@ -572,6 +574,9 @@ static int init(void * unused)do_basic_setup ();prepare_namespace (); + +if ((err =register_printk_channel ()) <0 ) +panic ("Couldn't register printk channel: errcode %d\n" , err);/* * Ok, we have completed the initial bootup, and
kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_CPU_FREQ) += cpufreq.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o obj-$(CONFIG_COMPAT) += compat.o +obj-$(CONFIG_DYNAMIC_PRINTK) += printk-dynamic.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/printk-dynamic.c +733 -0
733 lines not on this page · raw message
kernel/printk.c +43 -34
165 lines not on this page · raw message
Signature · 4 lines
Regards, Tom Zanussi <[email protected]> IBM Linux Technology Center/RAS