From d558309d67b9ad4dbc4c47bccabe078af3f9eb6e Mon Sep 17 00:00:00 2001 From: Mark Collins Date: Thu, 20 Oct 2022 18:35:57 +0000 Subject: [PATCH] freedreno/cffdec: Add NOP debug messages We want to encode special messages into the CS that can be printed by cffdec, these messages have identifiers that describe their usage (message, scope begin and scope end) which allow for an improved trace navigation experience due to the additional information. Signed-off-by: Mark Collins Part-of: --- docs/u_trace.rst | 3 +++ src/freedreno/decode/cffdec.c | 45 ++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/docs/u_trace.rst b/docs/u_trace.rst index f055e44397c..834d9931373 100644 --- a/docs/u_trace.rst +++ b/docs/u_trace.rst @@ -41,6 +41,9 @@ u_trace is controlled by environment variables: enables marker instrumentation, will print utrace markers into the CS which can then be viewed by dumping the CS from the driver. + - For Turnip, ``cffdump`` can be used to view the markers in + the trace. + :envvar:`MESA_GPU_TRACEFILE` specifies a file where to write the output instead of ``stdout`` diff --git a/src/freedreno/decode/cffdec.c b/src/freedreno/decode/cffdec.c index 9c9ccc23913..8a8ec976730 100644 --- a/src/freedreno/decode/cffdec.c +++ b/src/freedreno/decode/cffdec.c @@ -2106,26 +2106,55 @@ cp_run_cl(uint32_t *dwords, uint32_t sizedwords, int level) } static void -cp_nop(uint32_t *dwords, uint32_t sizedwords, int level) +print_nop_tail_string(uint32_t *dwords, uint32_t sizedwords) { const char *buf = (void *)dwords; - int i; + for (int i = 0; i < 4 * sizedwords; i++) { + if (buf[i] == '\0') + break; + if (isascii(buf[i])) + printf("%c", buf[i]); + } +} +static void +cp_nop(uint32_t *dwords, uint32_t sizedwords, int level) +{ if (quiet(3)) return; + /* NOP is used to encode special debug strings by Turnip. + * See tu_cs_emit_debug_magic_strv(...) + */ + static int scope_level = 0; + uint32_t identifier = dwords[0]; + bool is_special = false; + if (identifier == CP_NOP_MESG) { + printf("### "); + is_special = true; + } else if (identifier == CP_NOP_BEGN) { + printf(">>> #%d: ", ++scope_level); + is_special = true; + } else if (identifier == CP_NOP_END) { + printf("<<< #%d: ", scope_level--); + is_special = true; + } + + if (is_special) { + if (sizedwords > 1) { + print_nop_tail_string(dwords + 1, sizedwords - 1); + printf("\n"); + } + return; + } + // blob doesn't use CP_NOP for string_marker but it does // use it for things that end up looking like, but aren't // ascii chars: if (!options->decode_markers) return; - for (i = 0; i < 4 * sizedwords; i++) { - if (buf[i] == '\0') - break; - if (isascii(buf[i])) - printf("%c", buf[i]); - } + print_nop_tail_string(dwords, sizedwords); printf("\n"); }