lkml.org 
[lkml]   [2009]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 1/3] include/linux: kernel.h dynamic_debug.h device.h - Use section fmts
    Date
    Allow printk format strings to be placed into specific sections

    ({const char section __fmt[] = fmt; printk(__fmt, ...); })

    Signed-off-by: Joe Perches <joe@perches.com>
    ---
    include/linux/device.h | 4 +++
    include/linux/dynamic_debug.h | 34 +++++++++++++++++++++++++-
    include/linux/kernel.h | 51 +++++++++++++++++++++++++++++++++++++++++
    3 files changed, 87 insertions(+), 2 deletions(-)

    diff --git a/include/linux/device.h b/include/linux/device.h
    index aebb810..badabb2 100644
    --- a/include/linux/device.h
    +++ b/include/linux/device.h
    @@ -554,6 +554,10 @@ extern void sysdev_shutdown(void);

    /* debugging and troubleshooting/diagnostic helpers. */
    extern const char *dev_driver_string(const struct device *dev);
    +
    +#define dev_printk_section(section, level, dev, format, arg...) \
    + printk_section(section, level "%s %s: " format, \
    + dev_driver_string(dev), dev_name(dev), ##arg)
    #define dev_printk(level, dev, format, arg...) \
    printk(level "%s %s: " format , dev_driver_string(dev) , \
    dev_name(dev) , ## arg)
    diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
    index a0d9422..f5a00de 100644
    --- a/include/linux/dynamic_debug.h
    +++ b/include/linux/dynamic_debug.h
    @@ -74,6 +74,30 @@ extern int ddebug_remove_module(char *mod_name);
    ##__VA_ARGS__); \
    } while (0)

    +#define dynamic_pr_debug_section(section, fmt, ...) do { \
    + static struct _ddebug descriptor \
    + __used \
    + __attribute__((section("__verbose"), aligned(8))) = \
    + { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
    + DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
    + if (__dynamic_dbg_enabled(descriptor)) \
    + printk_section(section, \
    + KERN_DEBUG KBUILD_MODNAME ":" pr_fmt(fmt), \
    + ##__VA_ARGS__); \
    + } while (0)
    +
    +
    +#define dynamic_dev_dbg_section(section, dev, fmt, ...) do { \
    + static struct _ddebug descriptor \
    + __used \
    + __attribute__((section("__verbose"), aligned(8))) = \
    + { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
    + DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
    + if (__dynamic_dbg_enabled(descriptor)) \
    + dev_printk_section(section, KERN_DEBUG, dev, \
    + KBUILD_MODNAME ": " fmt, ##__VA_ARGS__); \
    + } while (0)
    +
    #else

    static inline int ddebug_remove_module(char *mod)
    @@ -81,8 +105,14 @@ static inline int ddebug_remove_module(char *mod)
    return 0;
    }

    -#define dynamic_pr_debug(fmt, ...) do { } while (0)
    -#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
    +#define dynamic_pr_debug(fmt, ...) \
    + ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
    +#define dynamic_dev_dbg(dev, format, ...) \
    + ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##__VA_ARGS__); 0; })
    +#define dynamic_pr_debug_section(section, fmt, ...) \
    + ({ if (0) printk_section(section, KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
    +#define dynamic_dev_dbg_section(section, dev, format, ...) \
    + ({ if (0) dev_printk_section(section, KERN_DEBUG, dev, format, ##__VA_ARGS__); 0; })
    #endif

    #endif
    diff --git a/include/linux/kernel.h b/include/linux/kernel.h
    index d6320a3..2afb826 100644
    --- a/include/linux/kernel.h
    +++ b/include/linux/kernel.h
    @@ -404,6 +404,57 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
    #endif

    /*
    + * Special section printks, put the format string in a particular data section
    + */
    +#define printk_section(section, fmt, ...) \
    + ({ static const section char __fmt[] = fmt; \
    + printk(__fmt, ##__VA_ARGS__); })
    +
    +#define pr_emerg_section(section, fmt, ...) \
    + printk_section(section, KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_alert_section(section, fmt, ...) \
    + printk_section(section, KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_crit_section(section, fmt, ...) \
    + printk_section(section, KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_err_section(section, fmt, ...) \
    + printk_section(section, KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_warning_section(section, fmt, ...) \
    + printk_section(section, KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_notice_section(section, fmt, ...) \
    + printk_section(section, KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_info_section(section, fmt, ...) \
    + printk_section(section, KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
    +#define pr_cont_section(section, fmt, ...) \
    + printk_section(section, KERN_CONT fmt, ##__VA_ARGS__)
    +
    +/* pr_devel() should produce zero code unless DEBUG is defined */
    +#ifdef DEBUG
    +#define pr_devel_section(section, fmt, ...) \
    + printk_section(section, KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
    +#else
    +#define pr_devel_section(fmt, ...) \
    + ({ if (0) \
    + printk_section(section, KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__);\
    + 0; })
    +#endif
    +
    +/* If you are writing a driver, please use dev_dbg instead */
    +#if defined(DEBUG)
    +#define pr_debug_section(section, fmt, ...) \
    + printk_section(section, KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
    +#elif defined(CONFIG_DYNAMIC_DEBUG)
    +/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
    +#define pr_debug_section(section, fmt, ...) do { \
    + dynamic_pr_debug(fmt, ##__VA_ARGS__); \
    + } while (0)
    +#else
    +#define pr_debug_section(fmt, ...) \
    + ({ if (0) \
    + printk_section(section, KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__);\
    + 0; })
    +#endif
    +
    +/*
    * General tracing related utility functions - trace_printk(),
    * tracing_on/tracing_off and tracing_start()/tracing_stop
    *
    --
    1.6.3.1.10.g659a0.dirty


    \
     
     \ /
      Last update: 2009-07-21 06:37    [W:0.028 / U:0.028 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site