Skip to content

Commit 29fc2bc

Browse files
JoePerchesgregkh
authored andcommitted
printk: pr_debug_ratelimited: check state first to reduce "callbacks suppressed" messages
pr_debug_ratelimited should be coded similarly to dev_dbg_ratelimited to reduce the "callbacks suppressed" messages. Add #include <linux/dynamic_debug.h> to printk.h. Unfortunately, this new #include must be after the prototype/declaration of function printk. It may be better to split out these _ratelimited declarations into a separate file one day. Any use of these pr_<foo>_ratelimited functions must also have another specific #include <ratelimited.h>. Most users have this done indirectly via #include <linux/kernel.h> printk.h may not #include <linux/ratelimit.h> as it causes circular dependencies and compilation failures. Signed-off-by: Joe Perches <[email protected]> Tested-by: Krzysztof Mazur <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9d3bd76 commit 29fc2bc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

include/linux/printk.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ extern asmlinkage void dump_stack(void) __cold;
233233
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
234234
#endif
235235

236+
#include <linux/dynamic_debug.h>
237+
236238
/* If you are writing a driver, please use dev_dbg instead */
237239
#if defined(CONFIG_DYNAMIC_DEBUG)
238240
/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
@@ -343,7 +345,19 @@ extern asmlinkage void dump_stack(void) __cold;
343345
#endif
344346

345347
/* If you are writing a driver, please use dev_dbg instead */
346-
#if defined(DEBUG)
348+
#if defined(CONFIG_DYNAMIC_DEBUG)
349+
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
350+
#define pr_debug_ratelimited(fmt, ...) \
351+
do { \
352+
static DEFINE_RATELIMIT_STATE(_rs, \
353+
DEFAULT_RATELIMIT_INTERVAL, \
354+
DEFAULT_RATELIMIT_BURST); \
355+
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
356+
if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
357+
__ratelimit(&_rs)) \
358+
__dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
359+
} while (0)
360+
#elif defined(DEBUG)
347361
#define pr_debug_ratelimited(fmt, ...) \
348362
printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
349363
#else

0 commit comments

Comments
 (0)