From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org
Cc: Jim Cromie <jim.cromie@gmail.com>
Subject: [RFC PATCH v6 34/34] dyndbg: prototype print-once and print-ratelimited RFC
Date: Sat, 29 May 2021 14:00:29 -0600 [thread overview]
Message-ID: <20210529200029.205306-35-jim.cromie@gmail.com> (raw)
In-Reply-To: <20210529200029.205306-1-jim.cromie@gmail.com>
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
prev parent reply other threads:[~2021-05-29 20:03 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-29 19:59 [RFC PATCH v6 00/34] DYNAMIC_DEBUG diet progress, dropped 30kb Jim Cromie
2021-05-29 19:59 ` [RFC PATCH v6 01/34] dyndbg: avoid calling dyndbg_emit_prefix when it has no work Jim Cromie
2021-05-29 19:59 ` [RFC PATCH v6 02/34] dyndbg: drop uninformative vpr_info Jim Cromie
2021-05-29 19:59 ` [RFC PATCH v6 03/34] dyndbg: display KiB of data memory used Jim Cromie
2021-05-29 19:59 ` [RFC PATCH v6 04/34] dyndbg: split struct _ddebug's display fields to new _ddebug_site Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 05/34] dyndbg: __init iterate over __dyndbg & __dyndbg_site in parallel Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 06/34] dyndbg+module: expose ddebug_sites to modules Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 07/34] dyndbg: refactor part of ddebug_change to ddebug_match_site Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 08/34] dyndbg: accept null site in ddebug_match_site Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 09/34] dyndbg: hoist ->site out of ddebug_match_site Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 10/34] dyndbg: accept null site in ddebug_change Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 11/34] dyndbg: accept null site in dynamic_emit_prefix Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 12/34] dyndbg: accept null site in ddebug_proc_show Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 13/34] dyndbg: refactor ddebug_alter_site out of ddebug_change Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 14/34] dyndbg: allow deleting site info via control interface Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 15/34] dyndbg: add ddebug_site(_get|_put) abstraction Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 16/34] dyndbg: ddebug_add_module avoid adding empty modules Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 17/34] dyndbg: add _index to struct _ddebug Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 18/34] dyndbg: prevent build bugs via -DNO_DYNAMIC_DEBUG_TABLE Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 19/34] dyndbg: RFC - DEFINE_DYNAMIC_DEBUG_TABLE Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 20/34] dyndbg: RFC handle __dyndbg* sections in module.lds.h Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 21/34] dyndbg: ddebug_add_module() handle headers Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 22/34] dyndbg: validate ddebug_site_get invariants Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 23/34] dyndbg: fix NULL deref after deleting sites Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 24/34] dyndbg: dont show header records in control Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 25/34] dyndbg: make site pointer and checks on it optional (almost) Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 26/34] dyndbg: swap WARN_ON for BUG_ON see what 0-day says Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 27/34] dyndbg: fixup protect header when deleting site Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 28/34] dyndbg: unionize _ddebug*_headers with struct _ddebug* Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 29/34] dyndbg: RFC drop _ddebug.site pointer Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 30/34] dyndbg: split/copy ._index into 2 new fields: ._back, ._map Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 31/34] dyndbg: detect repeated site recs in add_module Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 32/34] dyndbg: pack module pr_debug sites Jim Cromie
2021-05-29 20:00 ` [RFC PATCH v6 33/34] dyndbg: pack pr-debug site-recs in builtin modules Jim Cromie
2021-05-29 20:00 ` Jim Cromie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210529200029.205306-35-jim.cromie@gmail.com \
--to=jim.cromie@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jbaron@akamai.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox