asahi: Add batch state debugging
authorAsahi Lina <lina@asahilina.net>
Wed, 5 Apr 2023 09:03:02 +0000 (18:03 +0900)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 7 May 2023 12:59:41 +0000 (08:59 -0400)
I've had to reimplement this more than once, let's just make a flag for
it.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22891>

src/asahi/lib/agx_device.h
src/gallium/drivers/asahi/agx_batch.c
src/gallium/drivers/asahi/agx_pipe.c

index 05819bb..424d10e 100644 (file)
@@ -24,6 +24,7 @@ enum agx_dbg {
    AGX_DBG_SYNC = BITFIELD_BIT(8),
    AGX_DBG_STATS = BITFIELD_BIT(9),
    AGX_DBG_RESOURCE = BITFIELD_BIT(10),
+   AGX_DBG_BATCH = BITFIELD_BIT(11),
 };
 
 /* Dummy partial declarations, pending real UAPI */
index 8ab4648..04b8def 100644 (file)
 #define foreach_submitted(ctx, idx)                                            \
    BITSET_FOREACH_SET(idx, ctx->batches.submitted, AGX_MAX_BATCHES)
 
+#define batch_debug(batch, fmt, ...)                                           \
+   do {                                                                        \
+      if (unlikely(agx_device(batch->ctx->base.screen)->debug &                \
+                   AGX_DBG_BATCH))                                             \
+         agx_msg("[Batch %u] " fmt "\n", agx_batch_idx(batch), ##__VA_ARGS__); \
+   } while (0)
+
 static unsigned
 agx_batch_idx(struct agx_batch *batch)
 {
@@ -37,6 +44,8 @@ agx_batch_mark_active(struct agx_batch *batch)
 {
    unsigned batch_idx = agx_batch_idx(batch);
 
+   batch_debug(batch, "ACTIVE");
+
    assert(!BITSET_TEST(batch->ctx->batches.submitted, batch_idx));
    assert(!BITSET_TEST(batch->ctx->batches.active, batch_idx));
    BITSET_SET(batch->ctx->batches.active, batch_idx);
@@ -47,6 +56,8 @@ agx_batch_mark_submitted(struct agx_batch *batch)
 {
    unsigned batch_idx = agx_batch_idx(batch);
 
+   batch_debug(batch, "SUBMIT");
+
    assert(BITSET_TEST(batch->ctx->batches.active, batch_idx));
    assert(!BITSET_TEST(batch->ctx->batches.submitted, batch_idx));
    BITSET_CLEAR(batch->ctx->batches.active, batch_idx);
@@ -58,6 +69,8 @@ agx_batch_mark_complete(struct agx_batch *batch)
 {
    unsigned batch_idx = agx_batch_idx(batch);
 
+   batch_debug(batch, "COMPLETE");
+
    assert(!BITSET_TEST(batch->ctx->batches.active, batch_idx));
    assert(BITSET_TEST(batch->ctx->batches.submitted, batch_idx));
    BITSET_CLEAR(batch->ctx->batches.submitted, batch_idx);
@@ -563,6 +576,8 @@ agx_batch_submit(struct agx_context *ctx, struct agx_batch *batch,
       struct agx_bo *bo = agx_lookup_bo(dev, handle);
 
       if (bo->flags & AGX_BO_SHARED) {
+         batch_debug(batch, "Waits on shared BO @ 0x%" PRIx64, bo->ptr.gpu);
+
          /* Get a sync file fd from the buffer */
          int in_sync_fd = agx_export_sync_file(dev, bo);
          assert(in_sync_fd >= 0);
@@ -604,6 +619,9 @@ agx_batch_submit(struct agx_context *ctx, struct agx_batch *batch,
       assert(out_sync_fd >= 0);
 
       for (unsigned i = 0; i < shared_bo_count; i++) {
+         batch_debug(batch, "Signals shared BO @ 0x%" PRIx64,
+                     shared_bos[i]->ptr.gpu);
+
          /* Free the in_sync handle we just acquired */
          ret = drmSyncobjDestroy(dev->fd, in_syncs[i].handle);
          assert(ret >= 0);
@@ -714,6 +732,8 @@ agx_sync_all(struct agx_context *ctx, const char *reason)
 void
 agx_batch_reset(struct agx_context *ctx, struct agx_batch *batch)
 {
+   batch_debug(batch, "RESET");
+
    /* Reset an empty batch. Like submit, but does nothing. */
    agx_batch_mark_submitted(batch);
 
index 22dd39d..45371d2 100644 (file)
@@ -68,6 +68,7 @@ static const struct debug_named_value agx_debug_options[] = {
    {"sync",      AGX_DBG_SYNC,     "Synchronously wait for all submissions"},
    {"stats",     AGX_DBG_STATS,    "Show command execution statistics"},
    {"resource",  AGX_DBG_RESOURCE, "Log resource operations"},
+   {"batch",     AGX_DBG_BATCH,    "Log batches"},
    DEBUG_NAMED_VALUE_END
 };
 /* clang-format on */