[PATCH v4 32/58] dyndbg: refactor *dynamic_emit_prefix to split lookups
Jim Cromie
jim.cromie at gmail.com
Sun Aug 3 03:57:50 UTC 2025
Split dynamic_emit_prefix():
1. keep dynamic_emit_prefix() static inline
check ANY flags before calling 2
2. __dynamic_emit_prefix()
prints [TID] or <intr> if +t flag
check LOOKUP flags before calling 3
3. __dynamic_emit_lookup()
prints 1+ of: module, function, src-file, line
Notes:
With 3 only called when needed, print the trailing whitespace
unconditionally, and drop the pos_after_tid var.
By doing TID in 2, 3's output is cacheable in principle.
A prefix cache would allow de-duplicating the redundant data in the
_ddebug tables, and replacing them with space-efficient storage which
is not fast enough for every-time pr_debugs, but would work to fill
the cache the 1st time its enabled and invoked.
Signed-off-by: Jim Cromie <jim.cromie at gmail.com>
---
lib/dynamic_debug.c | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c3e27637d9357..26261b5f99f05 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -824,19 +824,8 @@ static int remaining(int wrote)
return 0;
}
-static char *__dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
+static int __dynamic_emit_lookup(const struct _ddebug *desc, char *buf, int pos)
{
- int pos_after_tid;
- int pos = 0;
-
- if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
- if (in_interrupt())
- pos += snprintf(buf + pos, remaining(pos), "<intr> ");
- else
- pos += snprintf(buf + pos, remaining(pos), "[%d] ",
- task_pid_vnr(current));
- }
- pos_after_tid = pos;
if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
pos += snprintf(buf + pos, remaining(pos), "%s:",
desc->modname);
@@ -849,8 +838,29 @@ static char *__dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
pos += snprintf(buf + pos, remaining(pos), "%d:",
desc->lineno);
- if (pos - pos_after_tid)
- pos += snprintf(buf + pos, remaining(pos), " ");
+
+ /* we have a non-empty prefix, add trailing space */
+ if (remaining(pos))
+ buf[pos++] = ' ';
+
+ return pos;
+}
+
+static char *__dynamic_emit_prefix(struct _ddebug *desc, char *buf)
+{
+ int pos = 0;
+
+ if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
+ if (in_interrupt())
+ pos += snprintf(buf + pos, remaining(pos), "<intr> ");
+ else
+ pos += snprintf(buf + pos, remaining(pos), "[%d] ",
+ task_pid_vnr(current));
+ }
+
+ if (unlikely(desc->flags & _DPRINTK_FLAGS_INCL_LOOKUP))
+ pos += __dynamic_emit_lookup(desc, buf, pos);
+
if (pos >= PREFIX_SIZE)
buf[PREFIX_SIZE - 1] = '\0';
@@ -859,7 +869,7 @@ static char *__dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
static inline char *dynamic_emit_prefix(struct _ddebug *desc, char *buf)
{
- if (unlikely(desc->flags & _DPRINTK_FLAGS_INCL_ANY))
+ if (desc->flags & _DPRINTK_FLAGS_INCL_ANY)
return __dynamic_emit_prefix(desc, buf);
return buf;
}
--
2.50.1
More information about the amd-gfx
mailing list