mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 00:52:01 +00:00
5c82871335
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>
63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
/*
|
|
* ratelimit.c - Do something with rate limit.
|
|
*
|
|
* Isolated from kernel/printk.c by Dave Young <hidave.darkstar@gmail.com>
|
|
*
|
|
* 2008-05-01 rewrite the function and use a ratelimit_state data struct as
|
|
* parameter. Now every user can use their own standalone ratelimit_state.
|
|
*
|
|
* This file is released under the GPLv2.
|
|
*/
|
|
|
|
#include <linux/ratelimit.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/module.h>
|
|
|
|
/*
|
|
* __ratelimit - rate limiting
|
|
* @rs: ratelimit_state data
|
|
*
|
|
* This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
|
|
* in every @rs->ratelimit_jiffies
|
|
*/
|
|
int ___ratelimit(struct ratelimit_state *rs, const char *func)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
if (!rs->interval)
|
|
return 1;
|
|
|
|
/*
|
|
* If we contend on this state's lock then almost
|
|
* by definition we are too busy to print a message,
|
|
* in addition to the one that will be printed by
|
|
* the entity that is holding the lock already:
|
|
*/
|
|
if (!spin_trylock_irqsave(&rs->lock, flags))
|
|
return 1;
|
|
|
|
if (!rs->begin)
|
|
rs->begin = jiffies;
|
|
|
|
if (time_is_before_jiffies(rs->begin + rs->interval)) {
|
|
if (rs->missed)
|
|
printk(KERN_WARNING "%s: %d callbacks suppressed\n",
|
|
func, rs->missed);
|
|
rs->begin = 0;
|
|
rs->printed = 0;
|
|
rs->missed = 0;
|
|
}
|
|
if (rs->burst && rs->burst > rs->printed) {
|
|
rs->printed++;
|
|
ret = 1;
|
|
} else {
|
|
rs->missed++;
|
|
ret = 0;
|
|
}
|
|
spin_unlock_irqrestore(&rs->lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(___ratelimit);
|