XenevaOS
Loading...
Searching...
No Matches
ratelimit.h
Go to the documentation of this file.
1#ifndef __LINUX_RATELIMIT_H__
2#define __LINUX_RATELIMIT_H__
3
4/*
5 * DCL <linux/ratelimit.h> -- error printing that does not repeat itself.
6 *
7 * The staged set needs the *_ratelimited spellings (serial_core.c:1014 warns
8 * once per process about deprecated ASYNC_ flags; tty_io.c does the same for
9 * legacy TIOC* ioctls), and it includes this header to get them.
10 *
11 * DCL has no ratelimit_state worth the name -- there is no jiffies-driven
12 * suppression to borrow cheaply, and a suppressed warning on a single-user
13 * console is a warning nobody was going to act on anyway. So the macros pass
14 * straight through to their pr_* counterparts. The result is *louder* than
15 * mainline, never quieter, and that is the direction to be wrong in: a
16 * deprecation warning printed every time is noise; one silently dropped
17 * because a rate limiter ticked wrong is a lost diagnostic.
18 *
19 * struct ratelimit_state and __ratelimit() exist so code that builds a limiter
20 * explicitly still compiles; __ratelimit() always answers 1 (proceed).
21 */
22
23#include <linux/printk.h>
24
25/*
26 * DCL delta: mainline's defaults, added with the virtio-gpu port --
27 * virtgpu_vq.c:254's DRM_ERROR_RATELIMITED expands DEFINE_RATELIMIT_STATE
28 * with these. The value is inert here (__ratelimit() always proceeds), so
29 * the interval is written out rather than left as `5 * HZ`: this header
30 * cannot count on <linux/timer.h> being in scope at every use site, and 1250
31 * is five seconds at DCL's HZ (250, linux/timer.h:57) if the limiter ever
32 * grows teeth.
33 */
34#define DEFAULT_RATELIMIT_INTERVAL 1250
35#define DEFAULT_RATELIMIT_BURST 10
36
39 int burst;
41 int missed;
42 unsigned long begin;
43};
44
45#define RATELIMIT_DISABLED (struct ratelimit_state){ .interval = 0 }
46
47static inline int __ratelimit(struct ratelimit_state* rs)
48{
49 (void)rs;
50 return 1;
51}
52
53#define ratelimit_state_init(rs, b, i) \
54 do { (void)(rs); (void)(b); (void)(i); } while (0)
55
56#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
57 struct ratelimit_state name = { (interval_init), (burst_init), 0, 0, 0 }
58
59#define pr_emerg_ratelimited(fmt, ...) pr_emerg(fmt, ##__VA_ARGS__)
60#define pr_alert_ratelimited(fmt, ...) pr_alert(fmt, ##__VA_ARGS__)
61#define pr_crit_ratelimited(fmt, ...) pr_crit(fmt, ##__VA_ARGS__)
62#define pr_err_ratelimited(fmt, ...) pr_err(fmt, ##__VA_ARGS__)
63#define pr_warn_ratelimited(fmt, ...) pr_warn(fmt, ##__VA_ARGS__)
64#define pr_notice_ratelimited(fmt, ...) pr_notice(fmt, ##__VA_ARGS__)
65#define pr_info_ratelimited(fmt, ...) pr_info(fmt, ##__VA_ARGS__)
66#define pr_debug_ratelimited(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
67
68#define printk_ratelimited(fmt, ...) printk(fmt, ##__VA_ARGS__)
69
70#endif /* __LINUX_RATELIMIT_H__ */
Definition ratelimit.h:37
int interval
Definition ratelimit.h:38
int printed
Definition ratelimit.h:40
int missed
Definition ratelimit.h:41
unsigned long begin
Definition ratelimit.h:42
int burst
Definition ratelimit.h:39