]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ratelimit: Count misses due to lock contention
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 14 Mar 2025 18:26:59 +0000 (11:26 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 8 May 2025 23:13:26 +0000 (16:13 -0700)
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 <paulmck@kernel.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
lib/ratelimit.c

index 18703f92d73e746baa867dc24e03200529ef5934..19ad3cdbd1711e42feb62e6a8bdd5b8c5774c1eb 100644 (file)
@@ -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;