From ae2b312ecb9b83f35b32ad1a21a259ec0521ab23 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Wed, 5 Apr 2023 18:03:02 +0900 Subject: [PATCH] asahi: Add batch state debugging I've had to reimplement this more than once, let's just make a flag for it. Signed-off-by: Asahi Lina Part-of: --- src/asahi/lib/agx_device.h | 1 + src/gallium/drivers/asahi/agx_batch.c | 20 ++++++++++++++++++++ src/gallium/drivers/asahi/agx_pipe.c | 1 + 3 files changed, 22 insertions(+) diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 05819bb..424d10e 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -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 */ diff --git a/src/gallium/drivers/asahi/agx_batch.c b/src/gallium/drivers/asahi/agx_batch.c index 8ab4648..04b8def 100644 --- a/src/gallium/drivers/asahi/agx_batch.c +++ b/src/gallium/drivers/asahi/agx_batch.c @@ -14,6 +14,13 @@ #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); diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 22dd39d..45371d2 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -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 */ -- 2.7.4