ratelimit: patchset focus on return value of __ratelimit()
cover ratelimit: patchset focus on return value of __ratelimit()
When try to use the new API pr_*_ratelimited(), I got the opposite outcome. After some checking, I find print_ratelimited() misunderstand the return value of __ratelimit(). So I fix it in this patchset and also annotate __ratelimit() for later user.
I mark patch 3 with RFC because I'm afraid I misunderstand the intention, Ingo, can you please take a look at it? You know that change is introduced by edaac8e3167501cda336231d00611bf59c164346.
Yong Zhang (3):
ratelimit: annotate ___ratelimit() kernel.h: fix wrong usage of __ratelimit()
ratelimit: Fix return value when fail to get lock
include/linux/kernel.h | 2 +- lib/ratelimit.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
PATCH 1/3 ratelimit: annotate ___ratelimit()
Especially to prevent from wrong using of the return value.
--- lib/ratelimit.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
lib/ratelimit.c +7 -2
@@ -16,9 +16,14 @@/* * __ratelimit - rate limiting * @rs: ratelimit_state data +* @func: name of calling function * -* This enforces a rate limit: not more than @rs->ratelimit_burst callbacks -* in every @rs->ratelimit_jiffies +* This enforces a rate limit: not more than @rs->burst callbacks +* in every @rs->interval +* +* RETURNS: +* 0 means callbacks will be suppuressed. +* 1 means go ahead and do it. */ int ___ratelimit (struct ratelimit_state *rs,const char *func) {
Signature · 1 line
1.6.3.3
PATCH 2/3 kernel.h: fix wrong usage of __ratelimit()
In reply to Yong Zhang__ratelimit() rerurn 1 means we can go ahead.
--- include/linux/kernel.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/kernel.h +1 -1
@@ -426,7 +426,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte) .burst = DEFAULT_RATELIMIT_BURST, \ }; \ \ -if (!__ratelimit (&_rs)) \ +if (__ratelimit (&_rs)) \ printk(fmt, ##__VA_ARGS__); \ })#else
Signature · 1 line
1.6.3.3
RFC PATCH 3/3 ratelimit: Fix return value when fail to get lock
In reply to Yong ZhangQuoted 1 line
From log of commit
edaac8e3167501cda336231d00611bf59c164346,
It seems that we want to suppress the callback when trylock fails.
--- lib/ratelimit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/ratelimit.c +1 -1
@@ -40,7 +40,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)* the entity that is holding the lock already: */ if (!spin_trylock_irqsave (&rs->lock, flags)) -return 1 ; +return 0 ;if (!rs->begin) rs->begin = jiffies;
Signature · 1 line
1.6.3.3
Andrew Morton
maintainerRe: [RFC PATCH 3/3] ratelimit: Fix return value when fail to get lock
Quoted 16 lines · On Wed, 17 Mar 2010 10:58:44 +0800 Yong Zhang <[email protected]> wrote:
Quoted 1 line
From log of commit
edaac8e3167501cda336231d00611bf59c164346,It seems that we want to suppress the callback when trylock fails.
Signed-off-by Yong Zhang <[email protected]>Cc Ingo Molnar <[email protected]>Cc Christian Borntraeger <[email protected]>--- lib/ratelimit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)lib/ratelimit.c +0
-0
lib/ratelimit.c int ___ratelimit(struct ratelimit_state *rs, const char *func) · line 46
Quoted 8 lines
lib/ratelimit.c +1
-1@@ -40,7 +40,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)* the entity that is holding the lock already: */ if (!spin_trylock_irqsave (&rs->lock, flags)) -return 1 ; +return 0 ;if (!rs->begin) rs->begin = jiffies;
Looks right to me. I queued all three patches for 2.6.34.