ratelimit.h 663 B

123456789101112131415161718192021222324252627282930
  1. #ifndef _LINUX_RATELIMIT_H
  2. #define _LINUX_RATELIMIT_H
  3. #include <linux/param.h>
  4. #include <linux/spinlock_types.h>
  5. #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
  6. #define DEFAULT_RATELIMIT_BURST 10
  7. struct ratelimit_state {
  8. spinlock_t lock; /* protect the state */
  9. int interval;
  10. int burst;
  11. int printed;
  12. int missed;
  13. unsigned long begin;
  14. };
  15. #define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
  16. \
  17. struct ratelimit_state name = { \
  18. .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
  19. .interval = interval_init, \
  20. .burst = burst_init, \
  21. }
  22. extern int __ratelimit(struct ratelimit_state *rs);
  23. #endif /* _LINUX_RATELIMIT_H */