rtdm: add rtdm_printk_ratelimited
PATCH 1/1 rtdm: add rtdm_printk_ratelimited
This patch implements a real-time safe rate-limited message printing on kernel console similar to Linux's printk_ratelimited.
Signed-off-by Wolfgang Grandegger <[email protected]>
--- include/rtdm/rtdm_driver.h | 31 +++++++++++++++++ ksrc/skins/rtdm/drvlib.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 0 deletions(-)
include/rtdm/rtdm_driver.h +31 -0
@@ -1241,6 +1241,37 @@ static inline void rtdm_mutex_destroy(rtdm_mutex_t *mutex)#define rtdm_printk (format, ...) printk(format, ##__VA_ARGS__) +struct rtdm_ratelimit_state { +rtdm_lock_t lock;/* protect the state */ +nanosecs_abs_t interval; +int burst; +int printed; +int missed; +nanosecs_abs_t begin; +}; + +int rtdm_ratelimit (struct rtdm_ratelimit_state *rs,const char *func); + +#define DEFINE_RTDM_RATELIMIT_STATE (name, interval_init, burst_init) \ + struct rtdm_ratelimit_state name = { \ + .lock = RTDM_LOCK_UNLOCKED, \ + .interval = interval_init, \ + .burst = burst_init, \ + } + +/* We use the Linux defaults */ +#define DEF_RTDM_RATELIMIT_INTERVAL 5000000000LL +#define DEF_RTDM_RATELIMIT_BURST 10 + +#define rtdm_printk_ratelimited (fmt, ...) ({ \ + static DEFINE_RTDM_RATELIMIT_STATE(_rs, \ + DEF_RTDM_RATELIMIT_INTERVAL, \ + DEF_RTDM_RATELIMIT_BURST); \ + \ + if (rtdm_ratelimit(&_rs, __func__)) \ + printk(fmt, ##__VA_ARGS__); \ +}) +#ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */ static inline void *rtdm_malloc (size_t size) {
ksrc/skins/rtdm/drvlib.c +77 -0
86 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Gilles Chanteperdrix
AppliedQuoted 2 lines · Wolfgang Grandegger
This patch implements a real-time safe rate-limited message printing on kernel console similar to Linux's
printk_ratelimited.
Applied, thanks.
Signature · 1 line
Gilles.