Skip to contentSkip to conversation

rtdm: add rtdm_printk_ratelimited

PATCH Applied Wolfgang Grandegger 2 participants 2 messages Nov 17, 2011 – Nov 20, 2011

lore
Share & tools
lore
#0 lore raw

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.

---
 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
index 85624ed..4267bd7 100644
@@ -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
#1 lore raw
Quoted 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.