| .. | .. |
|---|
| 2 | 2 | #ifndef _LINUX_RATELIMIT_H |
|---|
| 3 | 3 | #define _LINUX_RATELIMIT_H |
|---|
| 4 | 4 | |
|---|
| 5 | | -#include <linux/param.h> |
|---|
| 5 | +#include <linux/ratelimit_types.h> |
|---|
| 6 | 6 | #include <linux/sched.h> |
|---|
| 7 | 7 | #include <linux/spinlock.h> |
|---|
| 8 | | - |
|---|
| 9 | | -#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) |
|---|
| 10 | | -#define DEFAULT_RATELIMIT_BURST 10 |
|---|
| 11 | | - |
|---|
| 12 | | -/* issue num suppressed message on exit */ |
|---|
| 13 | | -#define RATELIMIT_MSG_ON_RELEASE BIT(0) |
|---|
| 14 | | - |
|---|
| 15 | | -struct ratelimit_state { |
|---|
| 16 | | - raw_spinlock_t lock; /* protect the state */ |
|---|
| 17 | | - |
|---|
| 18 | | - int interval; |
|---|
| 19 | | - int burst; |
|---|
| 20 | | - int printed; |
|---|
| 21 | | - int missed; |
|---|
| 22 | | - unsigned long begin; |
|---|
| 23 | | - unsigned long flags; |
|---|
| 24 | | -}; |
|---|
| 25 | | - |
|---|
| 26 | | -#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \ |
|---|
| 27 | | - .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ |
|---|
| 28 | | - .interval = interval_init, \ |
|---|
| 29 | | - .burst = burst_init, \ |
|---|
| 30 | | - } |
|---|
| 31 | | - |
|---|
| 32 | | -#define RATELIMIT_STATE_INIT_DISABLED \ |
|---|
| 33 | | - RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST) |
|---|
| 34 | | - |
|---|
| 35 | | -#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \ |
|---|
| 36 | | - \ |
|---|
| 37 | | - struct ratelimit_state name = \ |
|---|
| 38 | | - RATELIMIT_STATE_INIT(name, interval_init, burst_init) \ |
|---|
| 39 | 8 | |
|---|
| 40 | 9 | static inline void ratelimit_state_init(struct ratelimit_state *rs, |
|---|
| 41 | 10 | int interval, int burst) |
|---|
| .. | .. |
|---|
| 72 | 41 | } |
|---|
| 73 | 42 | |
|---|
| 74 | 43 | extern struct ratelimit_state printk_ratelimit_state; |
|---|
| 75 | | - |
|---|
| 76 | | -extern int ___ratelimit(struct ratelimit_state *rs, const char *func); |
|---|
| 77 | | -#define __ratelimit(state) ___ratelimit(state, __func__) |
|---|
| 78 | 44 | |
|---|
| 79 | 45 | #ifdef CONFIG_PRINTK |
|---|
| 80 | 46 | |
|---|