Commit 5c828713358cb9df8aa174371edcbbb62203a490

Authored by Christian Borntraeger
Committed by Ingo Molnar
1 parent 3fff4c42bd

ratelimit: Make suppressed output messages more useful

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>

Showing 4 changed files with 10 additions and 8 deletions Side-by-side Diff

include/linux/kernel.h
... ... @@ -240,7 +240,8 @@
240 240 asmlinkage int printk(const char * fmt, ...)
241 241 __attribute__ ((format (printf, 1, 2))) __cold;
242 242  
243   -extern int printk_ratelimit(void);
  243 +extern int __printk_ratelimit(const char *func);
  244 +#define printk_ratelimit() __printk_ratelimit(__func__)
244 245 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
245 246 unsigned int interval_msec);
246 247  
include/linux/ratelimit.h
... ... @@ -25,7 +25,8 @@
25 25 .burst = burst_init, \
26 26 }
27 27  
28   -extern int __ratelimit(struct ratelimit_state *rs);
  28 +extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
  29 +#define __ratelimit(state) ___ratelimit(state, __func__)
29 30  
30 31 #endif /* _LINUX_RATELIMIT_H */
... ... @@ -1364,11 +1364,11 @@
1364 1364 */
1365 1365 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
1366 1366  
1367   -int printk_ratelimit(void)
  1367 +int __printk_ratelimit(const char *func)
1368 1368 {
1369   - return __ratelimit(&printk_ratelimit_state);
  1369 + return ___ratelimit(&printk_ratelimit_state, func);
1370 1370 }
1371   -EXPORT_SYMBOL(printk_ratelimit);
  1371 +EXPORT_SYMBOL(__printk_ratelimit);
1372 1372  
1373 1373 /**
1374 1374 * printk_timed_ratelimit - caller-controlled printk ratelimiting
... ... @@ -20,7 +20,7 @@
20 20 * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
21 21 * in every @rs->ratelimit_jiffies
22 22 */
23   -int __ratelimit(struct ratelimit_state *rs)
  23 +int ___ratelimit(struct ratelimit_state *rs, const char *func)
24 24 {
25 25 unsigned long flags;
26 26 int ret;
... ... @@ -43,7 +43,7 @@
43 43 if (time_is_before_jiffies(rs->begin + rs->interval)) {
44 44 if (rs->missed)
45 45 printk(KERN_WARNING "%s: %d callbacks suppressed\n",
46   - __func__, rs->missed);
  46 + func, rs->missed);
47 47 rs->begin = 0;
48 48 rs->printed = 0;
49 49 rs->missed = 0;
... ... @@ -59,5 +59,5 @@
59 59  
60 60 return ret;
61 61 }
62   -EXPORT_SYMBOL(__ratelimit);
  62 +EXPORT_SYMBOL(___ratelimit);