vc4: Add labels to BOs for debug builds or with VC4_DEBUG=surf set.
authorEric Anholt <eric@anholt.net>
Fri, 12 May 2017 23:05:44 +0000 (16:05 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 27 Sep 2017 17:21:49 +0000 (10:21 -0700)
This has proven to be incredibly useful for debugging CMA allocation
failures and driving memory management improvements.  However, we don't
want to burden entry and exit from the BO cache with the labeling ioctl's
overhead on release builds.

src/gallium/drivers/vc4/vc4_bufmgr.c
src/gallium/drivers/vc4/vc4_bufmgr.h
src/gallium/drivers/vc4/vc4_resource.c
src/gallium/drivers/vc4/vc4_state.c

index 0653f882323225e95b7c4b776e74849bd9778804..9c4cc4cba88cef4aeee87e2b911c336fa3054857 100644 (file)
@@ -48,6 +48,32 @@ static bool dump_stats = false;
 static void
 vc4_bo_cache_free_all(struct vc4_bo_cache *cache);
 
+void
+vc4_bo_label(struct vc4_screen *screen, struct vc4_bo *bo, const char *fmt, ...)
+{
+        /* Perform BO labeling by default on debug builds (so that you get
+         * whole-system allocation information), or if VC4_DEBUG=surf is set
+         * (for debugging a single app's allocation).
+         */
+#ifndef DEBUG
+        if (!(VC4_DEBUG & VC4_DEBUG_SURFACE))
+                return;
+#endif
+        va_list va;
+        va_start(va, fmt);
+        char *name = ralloc_vasprintf(NULL, fmt, va);
+        va_end(va);
+
+        struct drm_vc4_label_bo label = {
+                .handle = bo->handle,
+                .len = strlen(name),
+                .name = (uintptr_t)name,
+        };
+        drmIoctl(screen->fd, DRM_IOCTL_VC4_LABEL_BO, &label);
+
+        ralloc_free(name);
+}
+
 static void
 vc4_bo_dump_stats(struct vc4_screen *screen)
 {
@@ -114,6 +140,7 @@ vc4_bo_from_cache(struct vc4_screen *screen, uint32_t size, const char *name)
                 pipe_reference_init(&bo->reference, 1);
                 vc4_bo_remove_from_cache(cache, bo);
 
+                vc4_bo_label(screen, bo, "%s", name);
                 bo->name = name;
         }
         mtx_unlock(&cache->lock);
@@ -176,6 +203,8 @@ vc4_bo_alloc(struct vc4_screen *screen, uint32_t size, const char *name)
                 vc4_bo_dump_stats(screen);
         }
 
+        vc4_bo_label(screen, bo, "%s", name);
+
         return bo;
 }
 
@@ -307,6 +336,7 @@ vc4_bo_last_unreference_locked_timed(struct vc4_bo *bo, time_t time)
                 vc4_bo_dump_stats(screen);
         }
         bo->name = NULL;
+        vc4_bo_label(screen, bo, "mesa cache");
 
         free_stale_bos(screen, time);
 }
index 838314f43dfa7607b01bab139d560287acaf9233..4e7b23e0862477b1c45c1bf18aa4232f47fd96af 100644 (file)
@@ -131,6 +131,9 @@ bool
 vc4_wait_seqno(struct vc4_screen *screen, uint64_t seqno, uint64_t timeout_ns,
                const char *reason);
 
+void
+vc4_bo_label(struct vc4_screen *screen, struct vc4_bo *bo, const char *fmt, ...);
+
 void
 vc4_bufmgr_destroy(struct pipe_screen *pscreen);
 
index 853f7bbfa17ddf25e9b7b5f63b37dca43c9f1011..cdcbcc917e0dfbf9b4bc3b96dc6e60c092b5c9d1 100644 (file)
@@ -675,6 +675,11 @@ vc4_resource_create_with_modifiers(struct pipe_screen *pscreen,
                         goto fail;
         }
 
+        vc4_bo_label(screen, rsc->bo, "%sresource %dx%d@%d/%d",
+                     (tmpl->bind & PIPE_BIND_SCANOUT) ? "scanout " : "",
+                     tmpl->width0, tmpl->height0,
+                     rsc->cpp * 8, prsc->last_level);
+
         return prsc;
 fail:
         vc4_resource_destroy(pscreen, prsc);
index d6d44793e383bdaf400a1178271fb88fb14d5505..17aa7eb39715ea938ec35ee8726390ea26484560 100644 (file)
@@ -587,6 +587,9 @@ vc4_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
                         return NULL;
                 }
                 rsc = vc4_resource(prsc);
+                vc4_bo_label(vc4_screen(pctx->screen), rsc->bo,
+                            "tiling shadow %dx%d",
+                             tmpl.width0, tmpl.height0);
 
                 /* Flag it as needing update of the contents from the parent. */
                 rsc->writes = shadow_parent->writes - 1;