Skip to content

Commit 78bf44d

Browse files
committed
ratelimit: Convert the ->missed field to atomic_t
The ratelimit_state structure's ->missed field is sometimes incremented locklessly, and it would be good to avoid lost counts. This is also needed to count the number of misses due to trylock failure. Therefore, convert the ratelimit_state structure's ->missed field to atomic_t. 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>
1 parent c6f7f1b commit 78bf44d

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

include/linux/ratelimit.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@ static inline void ratelimit_default_init(struct ratelimit_state *rs)
2424

2525
static inline void ratelimit_state_inc_miss(struct ratelimit_state *rs)
2626
{
27-
rs->missed++;
27+
atomic_inc(&rs->missed);
2828
}
2929

3030
static inline int ratelimit_state_get_miss(struct ratelimit_state *rs)
3131
{
32-
return rs->missed;
32+
return atomic_read(&rs->missed);
3333
}
3434

3535
static inline int ratelimit_state_reset_miss(struct ratelimit_state *rs)
3636
{
37-
int ret = rs->missed;
38-
39-
rs->missed = 0;
40-
return ret;
37+
return atomic_xchg_relaxed(&rs->missed, 0);
4138
}
4239

4340
static inline void ratelimit_state_reset_interval(struct ratelimit_state *rs, int interval_init)

include/linux/ratelimit_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ratelimit_state {
1818
int interval;
1919
int burst;
2020
int printed;
21-
int missed;
21+
atomic_t missed;
2222
unsigned int flags;
2323
unsigned long begin;
2424
};

lib/ratelimit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
6666
rs->printed++;
6767
ret = 1;
6868
} else {
69-
rs->missed++;
69+
ratelimit_state_inc_miss(rs);
7070
ret = 0;
7171
}
7272
raw_spin_unlock_irqrestore(&rs->lock, flags);

0 commit comments

Comments
 (0)