lkml.org 
[lkml]   [2009]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kernel.h: Add printk_ratelimited and pr_<level>_rl

* Joe Perches <joe@perches.com> wrote:

> Add a printk_ratelimited statement expression macro that uses a
> per-call ratelimit_state so that multiple subsystems output messages
> are not suppressed by a global __ratelimit state.
>
> Signed-off-by: Joe Perches <joe@perches.com>
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index f4e3184..555560c 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -407,6 +407,50 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
> #endif
>
> /*
> + * ratelimited messages with local ratelimit_state,
> + * no local ratelimit_state used in the !PRINTK case
> + */
> +#ifdef CONFIG_PRINTK
> +#define printk_ratelimited(fmt, ...) ({ \
> + static struct ratelimit_state _rs = { \
> + .interval = DEFAULT_RATELIMIT_INTERVAL, \
> + .burst = DEFAULT_RATELIMIT_BURST, \
> + }; \
> + \
> + if (!__ratelimit(&_rs)) \
> + printk(fmt, ##__VA_ARGS__); \
> +})
> +#else
> +/* No effect, but we still get type checking even in the !PRINTK case: */
> +#define printk_ratelimited printk
> +#endif
> +
> +#define pr_emerg_rl(fmt, ...) \
> + printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_alert_rl(fmt, ...) \
> + printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_crit_rl(fmt, ...) \
> + printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_err_rl(fmt, ...) \
> + printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_warning_rl(fmt, ...) \
> + printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_notice_rl(fmt, ...) \
> + printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_info_rl(fmt, ...) \
> + printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
> +/* no pr_cont_rl, don't do that... */
> +/* If you are writing a driver, please use dev_dbg instead */
> +#if defined(DEBUG)
> +#define pr_debug_rl(fmt, ...) \
> + printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
> +#else
> +#define pr_debug_rl(fmt, ...) \
> + ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
> + ##__VA_ARGS__); 0; })
> +#endif
> +

Looks like a useful addition. Somewhat bloatier, but then again, more
correct and the bloat problem can be solved by explicit state
definitions.

Ingo


\
 
 \ /
  Last update: 2009-11-02 17:01    [W:0.113 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site