Skip to contentSkip to conversation

ratelimit: fix time interval by setting right start time

RFC New Jaewon Kim 1 participant 1 message Jan 18, 2016 Library code

lore
Share & tools
lore

Jaewon Kim

author
#0 lore raw

RFC 1/1 ratelimit: fix time interval by setting right start time

rs->begin should be initialized to the current jiffies if the begin was 0. Even when the time interval passes, the current resetting logic sets the begin back to 0. So next interval starts from the next call rather than from the current resetting call. This incurrs improper suppression.

For example:
B will be suppressed althouth 3 seconds passed.

	DEFINE_RATELIMIT_STATE(limit, HZ, 1);
	__ratelimit(&limit); /* A */
	sleep(3);
	__ratelimit(&limit); /* B */
---
 lib/ratelimit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ratelimit.c +1 -1
index 40e03ea..2c5de86 100644
@@ -49,7 +49,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
 		if (rs->missed)
 			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
 				func, rs->missed);
-		rs->begin   = 0;
+		rs->begin   = jiffies;
 		rs->printed = 0;
 		rs->missed  = 0;
 	}
Signature · 1 line
1.9.1