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 <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22891>
This commit is contained in:
Asahi Lina 2023-04-05 18:03:02 +09:00 committed by Alyssa Rosenzweig
parent be3a1e2e88
commit ae2b312ecb
3 changed files with 22 additions and 0 deletions

View 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 */

View file

@ -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);

View 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 */