dynamic_printk: core
Subsystems (2)
PATCH 1/3 dynamic_printk: core
Add the ability to dynamically enable/disable pr_debug()/dev_dbg() in the kernel. Yes, these calls could be converted to printk(KERN_DEBUG), but there are enough to cause overhead. Additionally, the logs become difficult to read. Here, one can turn these messages on/off per module via:
echo "add module_name" > <debugfs>/dynamic_printk/modules echo "remove module_name" > <debugfs>/dynamic_printk/modules
There is also a special 'all' value that turns on all the debugging messages.
---
include/linux/device.h | 10 ++ include/linux/kernel.h | 9 ++ lib/Kconfig.debug | 40 ++++++++ lib/Makefile | 2 lib/dynamic_printk.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 312 insertions(+), 0 deletions(-) create mode 100644 lib/dynamic_printk.c
include/linux/device.h +10 -0
@@ -595,6 +595,16 @@ extern const char *dev_driver_string(struct device *dev);#ifdef DEBUG #define dev_dbg(dev, format, arg...) \ dev_printk(KERN_DEBUG , dev , format , ## arg) +#elif defined(CONFIG_DYNAMIC_PRINTK ) +extern void dynamic_printk (char *,char *, ...); +extern int dynamic_debug_on; +#define dev_dbg (dev, format, ...) do { \ + if (unlikely(dynamic_debug_on)) \ + dynamic_printk(KBUILD_MODNAME, \ + KERN_DEBUG KBUILD_MODNAME ": %s %s: " format,\ + dev_driver_string(dev), (dev)->bus_id, \ + ##__VA_ARGS__); \ + } while (0)#else #define dev_dbg(dev, format, arg...) \ ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; })
include/linux/kernel.h +9 -0
@@ -292,6 +292,15 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,/* If you are writing a driver, please use dev_dbg instead */ #define pr_debug(fmt, arg...) \ printk(KERN_DEBUG fmt, ##arg) +#elif defined(CONFIG_DYNAMIC_PRINTK ) +extern void dynamic_printk (char *,char *, ...); +extern int dynamic_debug_on; +#define pr_debug (fmt, ...) do { \ + if (unlikely(dynamic_debug_on)) \ + dynamic_printk(KBUILD_MODNAME, \ + KERN_DEBUG KBUILD_MODNAME ": " fmt,\ + ##__VA_ARGS__); \ + } while (0)#else #define pr_debug(fmt, arg...) \ ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
lib/Kconfig.debug +40 -0
@@ -632,6 +632,46 @@ config FIREWIRE_OHCI_REMOTE_DMA If unsure, say N. +config DYNAMIC_PRINTK + bool "Enable dynamic printk() call support" + default n + depends on PRINTK + help + + Allows pr_debug() and dev_dbg() calls to be dynamically enabled based + upon their source module. Traditionally, these calls are only + enabled if one set #define DEBUG and recompiled the kernel. This + option obviates time consuming re-compiles. + + The impact of this compile option is a larger kerenl text size ~1%. + However, if CONFIG_IMMEDIATE is set, the run-time impact is + negligible. Without CONFIG_IMMEDIATE set, a global variable is + referenced for each pr_debug() and dev_dbg() calls. + + Usage: + + The printing of pr_debug() and dev_dbg() is controlled by the + debugfs file, dynamic_printk/modules. This file contains a list of + the active modules. To add and remove modules: + + echo "add <module_name>" > dynamic_printk/modules + echo "remove <module_name>" > dynamic_printk/modules + + For example: + + echo "add kobject" > dynamic_printk/modules + /sbin/modprobe <module> + + This will cause kobject debug messages to spew out. Also, a special + "all" value will print all pr_debug() and dev_dbg() calls. I.e.: + + echo "add all" > dynamic_printk/modules + echo "remove all" > dynamic_printk/modules + + Finally, passing "dynamic_printk" at the command line enables all + pr_debug() and dev_dbg() call to come out (same as "all"). This mode + can be disabled via a "remove all". + source "samples/Kconfig" source "lib/Kconfig.kgdb"
lib/Makefile +2 -0
@@ -66,6 +66,8 @@ obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o +obj-$(CONFIG_DYNAMIC_PRINTK) += dynamic_printk.o + lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_LMB) += lmb.o
lib/dynamic_printk.c new file +251 -0
251 lines not on this page · raw message
2008/4/29 Jason Baron <[email protected]>:
Quoted 3 lines
[...]
+ The impact of this compile option is a larger kerenl text size ~1%.
[...]
Hi,
Just noticed the typo above!
Signature · 3 lines
Regards, Tom Spink University of Edinburgh
Quoted 17 lines · On Tue, 29 Apr 2008 14:41:43 -0400 Jason Baron wrote:
Add the ability to dynamically enable/disable pr_debug()/dev_dbg() in the kernel. Yes, these calls could be converted to
printk(KERN_DEBUG), but there are enough to cause overhead. Additionally, the logs become difficult to read. Here, one can turn these messages on/off per module via:echo "add
module_name" > <debugfs>/dynamic_printk/modules echo "removemodule_name" > <debugfs>/dynamic_printk/modulesThere is also a special 'all' value that turns on all the debugging messages.
---lib/Kconfig.debug +0
-0
lib/Kconfig.debug config FIREWIRE_OHCI_REMOTE_DMA · line 638
Quoted 7 lines
lib/Kconfig.debug +4
-0@@ -632,6 +632,46 @@ config FIREWIRE_OHCI_REMOTE_DMA If unsure, say N. +config DYNAMIC_PRINTK + bool "Enable dynamic printk() call support" + default n + depends on PRINTK
and depends on DEBUG_FS ??
We shouldn't advertise this option unless the kernel can actually enable those pr_debug/dev_dbg calls...
Quoted 29 lines
lib/Kconfig.debug +29
-0+ help + + Allows pr_debug() and dev_dbg() calls to be dynamically enabled based + upon their source module. Traditionally, these calls are only + enabled if one set #define DEBUG and recompiled the kernel. This + option obviates time consuming re-compiles. + + The impact of this compile option is a larger kerenl text size ~1%. + However, if CONFIG_IMMEDIATE is set, the run-time impact is + negligible. Without CONFIG_IMMEDIATE set, a global variable is + referenced for each pr_debug() and dev_dbg() calls. + + Usage: + + The printing of pr_debug() and dev_dbg() is controlled by the + debugfs file, dynamic_printk/modules. This file contains a list of + the active modules. To add and remove modules: + + echo "add <module_name>" > dynamic_printk/modules + echo "remove <module_name>" > dynamic_printk/modules + + For example: + + echo "add kobject" > dynamic_printk/modules + /sbin/modprobe <module> + + This will cause kobject debug messages to spew out. Also, a special + "all" value will print all pr_debug() and dev_dbg() calls. I.e.: +
lib/Kconfig.debug config FIREWIRE_OHCI_REMOTE_DMA · line 677
Quoted 10 lines
lib/Kconfig.debug +7
-0+ echo "add all" > dynamic_printk/modules + echo "remove all" > dynamic_printk/modules + + Finally, passing "dynamic_printk" at the command line enables all + pr_debug() and dev_dbg() call to come out (same as "all"). This mode + can be disabled via a "remove all". + source "samples/Kconfig" source "lib/Kconfig.kgdb"
---
~Randy