Skip to content

Commit

Permalink
ratelimit: Make suppressed output messages more useful
Browse files Browse the repository at this point in the history
Today I got:

  [39648.224782] Registered led device: iwl-phy0::TX
  [40676.545099] __ratelimit: 246 callbacks suppressed
  [40676.545103] abcdef[23675]: segfault at 0 ...

as you can see the ratelimit message contains a function prefix.
Since this is always __ratelimit, this wont help much.

This patch changes __ratelimit and printk_ratelimit to print the
function name that calls ratelimit.

This will pinpoint the responsible function, as long as not several
different places call ratelimit with the same ratelimit state at
the same time. In that case we catch only one random function that
calls ratelimit after the wait period.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Dave Young <hidave.darkstar@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
CC: Andrew Morton <akpm@linux-foundation.org>
LKML-Reference: <200910231458.11832.borntraeger@de.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Christian Borntraeger authored and Ingo Molnar committed Oct 23, 2009
1 parent 3fff4c4 commit 5c82871
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
asmlinkage int printk(const char * fmt, ...)
__attribute__ ((format (printf, 1, 2))) __cold;

extern int printk_ratelimit(void);
extern int __printk_ratelimit(const char *func);
#define printk_ratelimit() __printk_ratelimit(__func__)
extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msec);

Expand Down
3 changes: 2 additions & 1 deletion include/linux/ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ratelimit_state {
.burst = burst_init, \
}

extern int __ratelimit(struct ratelimit_state *rs);
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
#define __ratelimit(state) ___ratelimit(state, __func__)

#endif /* _LINUX_RATELIMIT_H */
6 changes: 3 additions & 3 deletions kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1364,11 +1364,11 @@ late_initcall(disable_boot_consoles);
*/
DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);

int printk_ratelimit(void)
int __printk_ratelimit(const char *func)
{
return __ratelimit(&printk_ratelimit_state);
return ___ratelimit(&printk_ratelimit_state, func);
}
EXPORT_SYMBOL(printk_ratelimit);
EXPORT_SYMBOL(__printk_ratelimit);

/**
* printk_timed_ratelimit - caller-controlled printk ratelimiting
Expand Down
6 changes: 3 additions & 3 deletions lib/ratelimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
* in every @rs->ratelimit_jiffies
*/
int __ratelimit(struct ratelimit_state *rs)
int ___ratelimit(struct ratelimit_state *rs, const char *func)
{
unsigned long flags;
int ret;
Expand All @@ -43,7 +43,7 @@ int __ratelimit(struct ratelimit_state *rs)
if (time_is_before_jiffies(rs->begin + rs->interval)) {
if (rs->missed)
printk(KERN_WARNING "%s: %d callbacks suppressed\n",
__func__, rs->missed);
func, rs->missed);
rs->begin = 0;
rs->printed = 0;
rs->missed = 0;
Expand All @@ -59,4 +59,4 @@ int __ratelimit(struct ratelimit_state *rs)

return ret;
}
EXPORT_SYMBOL(__ratelimit);
EXPORT_SYMBOL(___ratelimit);

0 comments on commit 5c82871

Please sign in to comment.