Skip to contentSkip to conversation

ratelimit: patchset focus on return value of __ratelimit()

PATCH In review Yong Zhang 2 participants 5 messages Mar 17, 2010 – Mar 22, 2010 Library code

lore
Share & tools
lore

Yong Zhang

author
#0 lore raw

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(-)
author
#1 lore raw

PATCH 1/3 ratelimit: annotate ___ratelimit()

Especially to prevent from wrong using of the return value.

Cc Ingo Molnar <[email protected]>
Cc Dave Young <[email protected]>
---
 lib/ratelimit.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
lib/ratelimit.c +7 -2
index 09f5ce1..29a10b3 100644
@@ -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
author
#2 lore raw

PATCH 2/3 kernel.h: fix wrong usage of __ratelimit()

In reply to Yong Zhang

__ratelimit() rerurn 1 means we can go ahead.

Cc Andrew Morton <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Joe Perches <[email protected]>
---
 include/linux/kernel.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/kernel.h +1 -1
index 7f07074..9365227 100644
@@ -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
author
#3 lore raw

RFC PATCH 3/3 ratelimit: Fix return value when fail to get lock

In reply to Yong Zhang
Quoted 1 line

From log of commit edaac8e3167501cda336231d00611bf59c164346,

It seems that we want to suppress the callback when trylock fails.

Cc Ingo Molnar <[email protected]>
Cc Christian Borntraeger <[email protected]>
---
 lib/ratelimit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/ratelimit.c +1 -1
index 29a10b3..358638f 100644
@@ -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
maintainer
#4 lore raw

Re: [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.

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
index 29a10b3..358638f 100644

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.