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/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Kuniyuki Iwashima <[email protected]> Cc: Mateusz Guzik <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: John Ogness <[email protected]> Cc: Sergey Senozhatsky <[email protected]>
1 parent c6f7f1b commit 78bf44d

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

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)