From: Paul E. McKenney Date: Fri, 14 Mar 2025 18:26:59 +0000 (-0700) Subject: ratelimit: Count misses due to lock contention X-Git-Tag: v6.16-rc1~178^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d343732ddbfa15db88a628bf3284eb088efbaaf7;p=thirdparty%2Fkernel%2Fstable.git ratelimit: Count misses due to lock contention The ___ratelimit() function simply returns zero ("do ratelimiting") if the trylock fails, but does not adjust the ->missed field. This means that the resulting dropped printk()s are dropped silently, which could seriously confuse people trying to do console-log-based debugging. Therefore, increment the ->missed field upon trylock failure. Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/20250423115409.3425-1-spasswolf@web.de/ Signed-off-by: Paul E. McKenney Reviewed-by: Petr Mladek Cc: Andrew Morton Cc: Kuniyuki Iwashima Cc: Mateusz Guzik Cc: Steven Rostedt Cc: John Ogness Cc: Sergey Senozhatsky --- diff --git a/lib/ratelimit.c b/lib/ratelimit.c index 18703f92d73e7..19ad3cdbd1711 100644 --- a/lib/ratelimit.c +++ b/lib/ratelimit.c @@ -44,8 +44,10 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func) * in addition to the one that will be printed by * the entity that is holding the lock already: */ - if (!raw_spin_trylock_irqsave(&rs->lock, flags)) + if (!raw_spin_trylock_irqsave(&rs->lock, flags)) { + ratelimit_state_inc_miss(rs); return 0; + } if (!rs->begin) rs->begin = jiffies;