lkml.org 
[lkml]   [2021]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v6 34/34] dyndbg: prototype print-once and print-ratelimited RFC
Date
Expand ddebug.flags to 11 bits, and define new flags to support
pr_debug_once() and pr_debug_ratelimited() semantics:

echo module main +o > control # init/main runs once anyway
echo module foo +r > control # turn on ratelimiting
echo module foo +g > control # turn on group flag

Test these conditions in new is_onced_or_ratelimited(),
and call it from __dynamic_pr_debug and others.

print-once: can be done with just 2 bits in flags;

.o _DPRINTK_FLAGS_ONCE enables state test and set
.P _DPRINTK_FLAGS_PRINTED state bit

Just adding the flags lets the existing code operate them.
We will need new code to enforce constraints on flag combos;
'+ro' is nonsense, but this can wait, or can take a new meaning.

is_onced_or_ratelimited() should be correct for +o,
and should be testable now. tbd.

rate-limiting:
. for now, reserve the flag only !
.r _DPRINTK_FLAGS_RATELIMITED - track & limit prdbgs callrate

Intention is to wait til a prdebug is called, and if RATELIMITED is
set, THEN lookup a RateLimitState (RL) for it. If found, bump its
state and return true/false, otherwise create one, initialize it and
return false.

That lookup is basically a hash, with 2 part key:
. &builtin-vector-base OR &module
or the hash(s) could hang off the header struct
. ._back OR ._map
chosen by _DPRINTK_FLAGS_GROUPED
choice dictates per-site OR sharing across function

heres what happens:
- header fail seen before, time to dig more

dyndbg: get: header fail on 100-3231
dyndbg: changed drivers/gpu/drm/i915/gvt/mmio_context.c:3231 [i915]restore_context_mmio_for_inhibit =prg
dyndbg: get: header fail on 101-1412
dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:1412 [i915]init_cmd_table =prg
dyndbg: get: header fail on 102-1409
dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:1409 [i915]gen8_check_mi_display_flip =prg
dyndbg: get: header fail on 103-761
dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:761 [i915]gen8_check_mi_display_flip =prg
dyndbg: get: header fail on 104-760
dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:760 [i915]parser_exec_state_dump =prg
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/dynamic_debug.h | 10 ++++++---
lib/dynamic_debug.c | 42 ++++++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index fe70dda704d2..300fd0eed66f 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -64,18 +64,22 @@ struct _ddebug {
#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
#define _DPRINTK_FLAGS_INCL_TID (1<<4)
-#define _DPRINTK_FLAGS_DELETE_SITE (1<<7) /* drop site info to save ram */
-
#define _DPRINTK_FLAGS_INCL_ANY \
(_DPRINTK_FLAGS_INCL_MODNAME | _DPRINTK_FLAGS_INCL_FUNCNAME |\
_DPRINTK_FLAGS_INCL_LINENO | _DPRINTK_FLAGS_INCL_TID)

+#define _DPRINTK_FLAGS_ONCE (1<<5) /* print once flag */
+#define _DPRINTK_FLAGS_PRINTED (1<<6) /* print once state */
+#define _DPRINTK_FLAGS_RATELIMITED (1<<7)
+#define _DPRINTK_FLAGS_GROUPED (1<<8) /* manipulate as a group */
+#define _DPRINTK_FLAGS_DELETE_SITE (1<<9) /* drop site info to save ram */
+
#if defined DEBUG
#define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
#else
#define _DPRINTK_FLAGS_DEFAULT 0
#endif
- unsigned int flags:8;
+ unsigned int flags:11;

#ifdef CONFIG_JUMP_LABEL
union {
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 66b48f1cb2d0..a81461b58f6e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -86,13 +86,17 @@ static inline const char *trim_prefix(const char *path)
return path + skip;
}

-static struct { unsigned flag:8; char opt_char; } opt_array[] = {
+static struct { unsigned flag:11; char opt_char; } opt_array[] = {
{ _DPRINTK_FLAGS_PRINT, 'p' },
{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
{ _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
{ _DPRINTK_FLAGS_INCL_LINENO, 'l' },
{ _DPRINTK_FLAGS_INCL_TID, 't' },
{ _DPRINTK_FLAGS_NONE, '_' },
+ { _DPRINTK_FLAGS_ONCE, 'o' },
+ { _DPRINTK_FLAGS_PRINTED, 'P' },
+ { _DPRINTK_FLAGS_RATELIMITED, 'r' },
+ { _DPRINTK_FLAGS_GROUPED, 'g' },
{ _DPRINTK_FLAGS_DELETE_SITE, 'D' },
};

@@ -728,6 +732,30 @@ static inline char *dynamic_emit_prefix(struct _ddebug *desc, char *buf)
return buf;
}

+/* test print-once or ratelimited conditions */
+static bool is_onced_or_limited(struct _ddebug *descriptor)
+{
+ if (descriptor->flags & _DPRINTK_FLAGS_ONCE &&
+ descriptor->flags & _DPRINTK_FLAGS_RATELIMITED)
+ pr_info(" ONCE & RATELIMITED together is nonsense\n");
+
+ if (descriptor->flags & _DPRINTK_FLAGS_ONCE) {
+ if (descriptor->flags & _DPRINTK_FLAGS_PRINTED) {
+ v3pr_info(" would suppress print once\n");
+ // return true;
+ }
+ descriptor->flags |= _DPRINTK_FLAGS_PRINTED;
+ // return false; // wanna see rate stuff
+ }
+ /* test rate-limits */
+ if (descriptor->flags & _DPRINTK_FLAGS_RATELIMITED) {
+ v3pr_info("todo: fetch RLstate{%s}\n",
+ descriptor->flags & _DPRINTK_FLAGS_GROUPED
+ ? "grouped" : "solo");
+ }
+ return false;
+}
+
void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
{
va_list args;
@@ -737,6 +765,9 @@ void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
BUG_ON(!descriptor);
BUG_ON(!fmt);

+ if (is_onced_or_limited(descriptor))
+ return;
+
va_start(args, fmt);

vaf.fmt = fmt;
@@ -757,6 +788,9 @@ void __dynamic_dev_dbg(struct _ddebug *descriptor,
BUG_ON(!descriptor);
BUG_ON(!fmt);

+ if (is_onced_or_limited(descriptor))
+ return;
+
va_start(args, fmt);

vaf.fmt = fmt;
@@ -788,6 +822,9 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
BUG_ON(!descriptor);
BUG_ON(!fmt);

+ if (is_onced_or_limited(descriptor))
+ return;
+
va_start(args, fmt);

vaf.fmt = fmt;
@@ -824,6 +861,9 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
struct va_format vaf;
va_list args;

+ if (is_onced_or_limited(descriptor))
+ return;
+
va_start(args, fmt);

vaf.fmt = fmt;
--
2.31.1
\
 
 \ /
  Last update: 2021-05-29 22:04    [W:1.531 / U:1.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site