Mesa (main): panfrost: Log reasons for flushes

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 14 18:05:14 UTC 2021


Module: Mesa
Branch: main
Commit: a266a0fbbb1cf7b5653807c86db8ddfe60cae495
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a266a0fbbb1cf7b5653807c86db8ddfe60cae495

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Mon Jul 12 14:05:09 2021 -0400

panfrost: Log reasons for flushes

Premature flushes (i.e. before pipe->flush() is called) can be
expensive, particularly if they require extra reloads/resolves.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11830>

---

 src/gallium/drivers/panfrost/pan_cmdstream.c |  6 +++---
 src/gallium/drivers/panfrost/pan_compute.c   |  2 +-
 src/gallium/drivers/panfrost/pan_context.c   | 10 +++++-----
 src/gallium/drivers/panfrost/pan_job.c       | 13 ++++++++++---
 src/gallium/drivers/panfrost/pan_job.h       |  8 +++++---
 src/gallium/drivers/panfrost/pan_resource.c  | 15 +++++++++------
 6 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index d31a7466a9d..20331881e39 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -1182,7 +1182,7 @@ panfrost_map_constant_buffer_cpu(struct panfrost_context *ctx,
 
         if (rsrc) {
                 panfrost_bo_mmap(rsrc->image.data.bo);
-                panfrost_flush_writer(ctx, rsrc);
+                panfrost_flush_writer(ctx, rsrc, "CPU constant buffer mapping");
                 panfrost_bo_wait(rsrc->image.data.bo, INT64_MAX, false);
 
                 return rsrc->image.data.bo->ptr.cpu + cb->buffer_offset;
@@ -3151,7 +3151,7 @@ panfrost_launch_grid(struct pipe_context *pipe,
 
         /* XXX - shouldn't be necessary with working memory barriers. Affected
          * test: KHR-GLES31.core.compute_shader.pipeline-post-xfb */
-        panfrost_flush_all_batches(ctx);
+        panfrost_flush_all_batches(ctx, "Launch grid pre-barrier");
 
         struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
 
@@ -3259,7 +3259,7 @@ panfrost_launch_grid(struct pipe_context *pipe,
         panfrost_add_job(&batch->pool.base, &batch->scoreboard,
                          MALI_JOB_TYPE_COMPUTE, true, false,
                          indirect_dep, 0, &t, false);
-        panfrost_flush_all_batches(ctx);
+        panfrost_flush_all_batches(ctx, "Launch grid post-barrier");
 }
 
 static void *
diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c
index 246c467c066..57beb6f3ef9 100644
--- a/src/gallium/drivers/panfrost/pan_compute.c
+++ b/src/gallium/drivers/panfrost/pan_compute.c
@@ -126,7 +126,7 @@ panfrost_memory_barrier(struct pipe_context *pctx, unsigned flags)
 {
         /* TODO: Be smart and only flush the minimum needed, maybe emitting a
          * cache flush job if that would help */
-        panfrost_flush_all_batches(pan_context(pctx));
+        panfrost_flush_all_batches(pan_context(pctx), "Memory barrier");
 }
 
 void
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 9f82998dc8b..66f98e61e91 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -99,7 +99,7 @@ panfrost_flush(
 
 
         /* Submit all pending jobs */
-        panfrost_flush_all_batches(ctx);
+        panfrost_flush_all_batches(ctx, NULL);
 
         if (fence) {
                 struct pipe_fence_handle *f = panfrost_fence_create(ctx);
@@ -115,14 +115,14 @@ static void
 panfrost_texture_barrier(struct pipe_context *pipe, unsigned flags)
 {
         struct panfrost_context *ctx = pan_context(pipe);
-        panfrost_flush_all_batches(ctx);
+        panfrost_flush_all_batches(ctx, "Texture barrier");
 }
 
 static void
 panfrost_set_frontend_noop(struct pipe_context *pipe, bool enable)
 {
         struct panfrost_context *ctx = pan_context(pipe);
-        panfrost_flush_all_batches(ctx);
+        panfrost_flush_all_batches(ctx, "Frontend no-op change");
         ctx->is_noop = enable;
 }
 
@@ -916,7 +916,7 @@ panfrost_get_query_result(struct pipe_context *pipe,
         case PIPE_QUERY_OCCLUSION_COUNTER:
         case PIPE_QUERY_OCCLUSION_PREDICATE:
         case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
-                panfrost_flush_writer(ctx, rsrc);
+                panfrost_flush_writer(ctx, rsrc, "Occlusion query");
                 panfrost_bo_wait(rsrc->image.data.bo, INT64_MAX, false);
 
                 /* Read back the query results */
@@ -939,7 +939,7 @@ panfrost_get_query_result(struct pipe_context *pipe,
 
         case PIPE_QUERY_PRIMITIVES_GENERATED:
         case PIPE_QUERY_PRIMITIVES_EMITTED:
-                panfrost_flush_all_batches(ctx);
+                panfrost_flush_all_batches(ctx, "Primitive count query");
                 vresult->u64 = query->end - query->start;
                 break;
 
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index a2964766e75..18462aa762d 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -902,13 +902,16 @@ out:
 /* Submit all batches, applying the out_sync to the currently bound batch */
 
 void
-panfrost_flush_all_batches(struct panfrost_context *ctx)
+panfrost_flush_all_batches(struct panfrost_context *ctx, const char *reason)
 {
         struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         panfrost_batch_submit(batch, ctx->syncobj, ctx->syncobj);
 
         for (unsigned i = 0; i < PAN_MAX_BATCHES; i++) {
                 if (ctx->batches.slots[i].seqnum) {
+                        if (reason)
+                                perf_debug_ctx(ctx, "Flushing everything due to: %s", reason);
+
                         panfrost_batch_submit(&ctx->batches.slots[i],
                                               ctx->syncobj, ctx->syncobj);
                 }
@@ -917,9 +920,11 @@ panfrost_flush_all_batches(struct panfrost_context *ctx)
 
 void
 panfrost_flush_writer(struct panfrost_context *ctx,
-                      struct panfrost_resource *rsrc)
+                      struct panfrost_resource *rsrc,
+                      const char *reason)
 {
         if (rsrc->track.writer) {
+                perf_debug_ctx(ctx, "Flushing writer due to: %s", reason);
                 panfrost_batch_submit(rsrc->track.writer, ctx->syncobj, ctx->syncobj);
                 rsrc->track.writer = NULL;
         }
@@ -927,10 +932,12 @@ panfrost_flush_writer(struct panfrost_context *ctx,
 
 void
 panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
-                                      struct panfrost_resource *rsrc)
+                                      struct panfrost_resource *rsrc,
+                                      const char *reason)
 {
         unsigned i;
         BITSET_FOREACH_SET(i, rsrc->track.users, PAN_MAX_BATCHES) {
+                perf_debug_ctx(ctx, "Flushing user due to: %s", reason);
                 panfrost_batch_submit(&ctx->batches.slots[i],
                                       ctx->syncobj, ctx->syncobj);
         }
diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h
index 2e5af79d73c..707245d9788 100644
--- a/src/gallium/drivers/panfrost/pan_job.h
+++ b/src/gallium/drivers/panfrost/pan_job.h
@@ -170,15 +170,17 @@ panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
                          const char *label);
 
 void
-panfrost_flush_all_batches(struct panfrost_context *ctx);
+panfrost_flush_all_batches(struct panfrost_context *ctx, const char *reason);
 
 void
 panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
-                                      struct panfrost_resource *rsrc);
+                                      struct panfrost_resource *rsrc,
+                                      const char *reason);
 
 void
 panfrost_flush_writer(struct panfrost_context *ctx,
-                      struct panfrost_resource *rsrc);
+                      struct panfrost_resource *rsrc,
+                      const char *reason);
 
 void
 panfrost_batch_adjust_stack_size(struct panfrost_batch *batch);
diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 14baf909aaf..17fcf3f6986 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -844,7 +844,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
 
                 if ((usage & PIPE_MAP_READ) && (valid || rsrc->track.writer)) {
                         pan_blit_to_staging(pctx, transfer);
-                        panfrost_flush_writer(ctx, staging);
+                        panfrost_flush_writer(ctx, staging, "AFBC read staging blit");
                         panfrost_bo_wait(staging->image.data.bo, INT64_MAX, false);
                 }
 
@@ -873,7 +873,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
                  * to flush and split the frame in two.
                  */
 
-                panfrost_flush_writer(ctx, rsrc);
+                panfrost_flush_writer(ctx, rsrc, "Shadow resource creation");
                 panfrost_bo_wait(bo, INT64_MAX, false);
 
                 create_new_bo = true;
@@ -916,7 +916,8 @@ panfrost_ptr_map(struct pipe_context *pctx,
                                 /* Allocation failed or was impossible, let's
                                  * fall back on a flush+wait.
                                  */
-                                panfrost_flush_batches_accessing_rsrc(ctx, rsrc);
+                                panfrost_flush_batches_accessing_rsrc(ctx, rsrc,
+                                                "Resource access with high memory pressure");
                                 panfrost_bo_wait(bo, INT64_MAX, true);
                         }
                 }
@@ -926,10 +927,10 @@ panfrost_ptr_map(struct pipe_context *pctx,
                 /* No flush for writes to uninitialized */
         } else if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
                 if (usage & PIPE_MAP_WRITE) {
-                        panfrost_flush_batches_accessing_rsrc(ctx, rsrc);
+                        panfrost_flush_batches_accessing_rsrc(ctx, rsrc, "Synchronized write");
                         panfrost_bo_wait(bo, INT64_MAX, true);
                 } else if (usage & PIPE_MAP_READ) {
-                        panfrost_flush_writer(ctx, rsrc);
+                        panfrost_flush_writer(ctx, rsrc, "Synchronized read");
                         panfrost_bo_wait(bo, INT64_MAX, false);
                 }
         }
@@ -1099,7 +1100,9 @@ panfrost_ptr_unmap(struct pipe_context *pctx,
                                 panfrost_bo_reference(prsrc->image.data.bo);
                         } else {
                                 pan_blit_from_staging(pctx, trans);
-                                panfrost_flush_batches_accessing_rsrc(pan_context(pctx), pan_resource(trans->staging.rsrc));
+                                panfrost_flush_batches_accessing_rsrc(pan_context(pctx),
+                                                pan_resource(trans->staging.rsrc),
+                                                "AFBC write staging blit");
                         }
                 }
 



More information about the mesa-commit mailing list