make pr_debug() dynamic
PATCH 1/4 make pr_debug() dynamic
-make pr_debug() dynamic so it can be switched on/off. The off state
is implemented on top of the immediate infrastructure, so as to promote more dynamic printing and debugging. depends on CONFIG_HAVE_IMMEDIATE and CONFIG_PRINTK
Signed-off-by Jason Baron <[email protected]>
---
include/linux/kernel.h | 10 ++++++++++ init/Kconfig | 5 +++++ kernel/printk.c | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 0 deletions(-)
include/linux/kernel.h +10 -0
@@ -14,6 +14,7 @@#include <linux/compiler.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/immediate.h> #include <asm/byteorder.h> #include <asm/bug.h>
@@ -276,6 +277,14 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, #define pr_info(fmt, arg...) \ printk(KERN_INFO fmt, ##arg) +#ifdef CONFIG_PR_DEBUG_DYNAMIC +DECLARE_IMV (char, pr_debug_on); +#define pr_debug (fmt, ...) \ + do { \ + if (unlikely(imv_read(pr_debug_on))) \ + printk(KERN_DEBUG fmt, ##__VA_ARGS__); \ + } while (0) +#else #ifdef DEBUG /* If you are writing a driver, please use dev_dbg instead */ #define pr_debug(fmt, arg...) \
@@ -286,6 +295,7 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char *return 0 ; }#endif +#endif /* * Display an IP address in readable format.
init/Kconfig +5 -0
@@ -539,6 +539,11 @@ config PRINTK very difficult to diagnose system problems, saying N here is strongly discouraged. +config PR_DEBUG_DYNAMIC + bool + depends on PRINTK && HAVE_IMMEDIATE + default y + config BUG bool "BUG() support" if EMBEDDED default y
kernel/printk.c +17 -0
@@ -33,6 +33,7 @@#include <linux/bootmem.h> #include <linux/syscalls.h> #include <linux/jiffies.h> +#include <linux/immediate.h> #include <asm/uaccess.h>
@@ -1334,3 +1335,19 @@ bool printk_timed_ratelimit(unsigned long *caller_jiffies,return false; }EXPORT_SYMBOL (printk_timed_ratelimit); + +#ifdef CONFIG_PR_DEBUG_DYNAMIC + +DEFINE_IMV (char, pr_debug_on) =0 ; +EXPORT_IMV_SYMBOL_GPL (pr_debug_on); + +static int __init pr_debug_setup (char *str) +{ +if (str) +return -ENOENT ; +imv_set (pr_debug_on,1 ); +return 0 ; +} +early_param ("pr_debug" , pr_debug_setup); + +#endif