[RFC 3/9] printk: Add printk_emit_ratelimited macro

Tony Asleson
2019-12-23T22:56:18Z

Needed so we can add structured data to the block layer
logging.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
include/linux/printk.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 06c3ba5b695e..dd41b79e6f06 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -172,6 +172,18 @@ int printk_emit(int facility, int level,
const char *dict, size_t dictlen,
const char *fmt, ...);

+#define printk_emit_ratelimited(facility, level, \
+ dict, dict_len, fmt, ...) \
+({ \
+ static DEFINE_RATELIMIT_STATE(_ers, \
+ DEFAULT_RATELIMIT_INTERVAL, \
+ DEFAULT_RATELIMIT_BURST); \
+ \
+ if (__ratelimit(&_ers)) \
+ printk_emit(facility, level, \
+ dict, dict_len, fmt, ##__VA_ARGS__); \
+})
+
asmlinkage __printf(1, 2) __cold
int printk(const char *fmt, ...);

--
2.21.0