freedreno: debug GEM obj names
authorRob Clark <robdclark@gmail.com>
Fri, 30 Nov 2018 13:29:51 +0000 (08:29 -0500)
committerRob Clark <robdclark@gmail.com>
Thu, 13 Dec 2018 20:51:01 +0000 (15:51 -0500)
With a recent enough kernel, set debug names for GEM BOs, which will
show up in $debugfs/gem

Signed-off-by: Rob Clark <robdclark@gmail.com>
13 files changed:
src/freedreno/drm/freedreno_bo.c
src/freedreno/drm/freedreno_drmif.h
src/freedreno/drm/freedreno_priv.h
src/freedreno/drm/msm_bo.c
src/freedreno/ir3/ir3_shader.c
src/gallium/drivers/freedreno/a3xx/fd3_context.c
src/gallium/drivers/freedreno/a3xx/fd3_gmem.c
src/gallium/drivers/freedreno/a4xx/fd4_context.c
src/gallium/drivers/freedreno/a4xx/fd4_gmem.c
src/gallium/drivers/freedreno/a5xx/fd5_context.c
src/gallium/drivers/freedreno/a5xx/fd5_gmem.c
src/gallium/drivers/freedreno/a6xx/fd6_context.c
src/gallium/drivers/freedreno/freedreno_resource.c

index ec46e16e9e9780c0f4c162df28c75fe7c2c361fb..7449160f1371ea8f890124290af518b60875ded4 100644 (file)
@@ -105,7 +105,7 @@ bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
 }
 
 struct fd_bo *
-fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
+_fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
 {
        struct fd_bo *bo = bo_new(dev, size, flags, &dev->bo_cache);
        if (bo)
@@ -113,6 +113,12 @@ fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
        return bo;
 }
 
+void
+_fd_bo_set_name(struct fd_bo *bo, const char *fmt, va_list ap)
+{
+       bo->funcs->set_name(bo, fmt, ap);
+}
+
 /* internal function to allocate bo's that use the ringbuffer cache
  * instead of the normal bo_cache.  The purpose is, because cmdstream
  * bo's get vmap'd on the kernel side, and that is expensive, we want
@@ -124,6 +130,7 @@ fd_bo_new_ring(struct fd_device *dev, uint32_t size, uint32_t flags)
        struct fd_bo *bo = bo_new(dev, size, flags, &dev->ring_cache);
        if (bo)
                bo->bo_reuse = RING_CACHE;
+       fd_bo_set_name(bo, "cmdstream");
        return bo;
 }
 
index 27ca0a96f264124900d159ee57b7ad6d32284681..a53c34069504aa6249e9934c43829aec67aaa5ff 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <stdint.h>
 
+#include "util/u_debug.h"
+
 struct fd_bo;
 struct fd_pipe;
 struct fd_device;
@@ -107,8 +109,44 @@ int fd_pipe_wait_timeout(struct fd_pipe *pipe, uint32_t timestamp,
 /* buffer-object functions:
  */
 
-struct fd_bo * fd_bo_new(struct fd_device *dev,
+struct fd_bo * _fd_bo_new(struct fd_device *dev,
                uint32_t size, uint32_t flags);
+void _fd_bo_set_name(struct fd_bo *bo, const char *fmt, va_list ap);
+
+static inline void
+fd_bo_set_name(struct fd_bo *bo, const char *fmt, ...) _util_printf_format(2, 3);
+
+static inline void
+fd_bo_set_name(struct fd_bo *bo, const char *fmt, ...)
+{
+#ifndef NDEBUG
+       va_list ap;
+       va_start(ap, fmt);
+       _fd_bo_set_name(bo, fmt, ap);
+       va_end(ap);
+#endif
+}
+
+static inline struct fd_bo *
+fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
+               const char *fmt, ...) _util_printf_format(4, 5);
+
+static inline struct fd_bo *
+fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
+               const char *fmt, ...)
+{
+       struct fd_bo *bo = _fd_bo_new(dev, size, flags);
+#ifndef NDEBUG
+       if (fmt) {
+               va_list ap;
+               va_start(ap, fmt);
+               _fd_bo_set_name(bo, fmt, ap);
+               va_end(ap);
+       }
+#endif
+       return bo;
+}
+
 struct fd_bo *fd_bo_from_handle(struct fd_device *dev,
                uint32_t handle, uint32_t size);
 struct fd_bo * fd_bo_from_name(struct fd_device *dev, uint32_t name);
index 45a5d6ccba17d8b1c0981860071c6ff51ece6d31..349a2296472c7fed4b829453aa50f82746d59bf0 100644 (file)
@@ -154,6 +154,7 @@ struct fd_bo_funcs {
        void (*cpu_fini)(struct fd_bo *bo);
        int (*madvise)(struct fd_bo *bo, int willneed);
        uint64_t (*iova)(struct fd_bo *bo);
+       void (*set_name)(struct fd_bo *bo, const char *fmt, va_list ap);
        void (*destroy)(struct fd_bo *bo);
 };
 
index 95f888b6cf68e7680f0f5aa44229a935a64270b6..fd9955ea8051f4c12d93bd523e6b30a5593f34dc 100644 (file)
@@ -117,11 +117,30 @@ static uint64_t msm_bo_iova(struct fd_bo *bo)
        return req.value;
 }
 
+static void msm_bo_set_name(struct fd_bo *bo, const char *fmt, va_list ap)
+{
+       struct drm_msm_gem_info req = {
+                       .handle = bo->handle,
+                       .info = MSM_INFO_SET_NAME,
+       };
+       char buf[32];
+       int sz;
+
+       if (bo->dev->version < FD_VERSION_SOFTPIN)
+               return;
+
+       sz = vsnprintf(buf, sizeof(buf), fmt, ap);
+
+       req.value = VOID2U64(buf);
+       req.len = MIN2(sz, sizeof(buf));
+
+       drmCommandWrite(bo->dev->fd, DRM_MSM_GEM_INFO, &req, sizeof(req));
+}
+
 static void msm_bo_destroy(struct fd_bo *bo)
 {
        struct msm_bo *msm_bo = to_msm_bo(bo);
        free(msm_bo);
-
 }
 
 static const struct fd_bo_funcs funcs = {
@@ -130,6 +149,7 @@ static const struct fd_bo_funcs funcs = {
                .cpu_fini = msm_bo_cpu_fini,
                .madvise = msm_bo_madvise,
                .iova = msm_bo_iova,
+               .set_name = msm_bo_set_name,
                .destroy = msm_bo_destroy,
 };
 
index 74d92e1396232d5c1fb683aefa61314bba5909b2..51c7b75ea3873b2185b6d5eddf25d94325aeff6e 100644 (file)
@@ -126,6 +126,7 @@ static void
 assemble_variant(struct ir3_shader_variant *v)
 {
        struct ir3_compiler *compiler = v->shader->compiler;
+       struct shader_info *info = &v->shader->nir->info;
        uint32_t gpu_id = compiler->gpu_id;
        uint32_t sz, *bin;
 
@@ -134,7 +135,8 @@ assemble_variant(struct ir3_shader_variant *v)
 
        v->bo = fd_bo_new(compiler->dev, sz,
                        DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM,
+                       "%s:%s", ir3_shader_stage(v->shader), info->name);
 
        memcpy(fd_bo_map(v->bo), bin, sz);
 
index 9927191ea4f66d11022aab9e2d2867e6e2efdd92..59dcaa4bf6b6e38aaa12cfbfbcc91fee123e5af7 100644 (file)
@@ -101,13 +101,13 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd_hw_query_init(pctx);
 
        fd3_ctx->vs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vs_pvt");
 
        fd3_ctx->fs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "fs_pvt");
 
        fd3_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_size");
 
        fd_context_setup_common_vbos(&fd3_ctx->base);
 
index d01b656b0a2b6674932f95187dbcd6407d37f9a4..7de0a92cdc1e4f58a7c09e8694451009803e318b 100644 (file)
@@ -785,7 +785,7 @@ update_vsc_pipe(struct fd_batch *batch)
 
                if (!pipe->bo) {
                        pipe->bo = fd_bo_new(ctx->dev, 0x40000,
-                                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_pipe[%u]", i);
                }
 
                OUT_PKT0(ring, REG_A3XX_VSC_PIPE(i), 3);
index fc9aad610c0390b22cc6a84d0a399370196376e8..e9730e9c20905e2b710c714e8678c75d95a7c206 100644 (file)
@@ -101,13 +101,13 @@ fd4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd_hw_query_init(pctx);
 
        fd4_ctx->vs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vs_pvt");
 
        fd4_ctx->fs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "fs_pvt");
 
        fd4_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_size");
 
        fd_context_setup_common_vbos(&fd4_ctx->base);
 
index aa6cb81e2f7117a76f1548d62095a91bf403da11..d061c8ac70f53ac753fcd83a00ccf05ab95470fb 100644 (file)
@@ -582,7 +582,7 @@ update_vsc_pipe(struct fd_batch *batch)
                struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[i];
                if (!pipe->bo) {
                        pipe->bo = fd_bo_new(ctx->dev, 0x40000,
-                                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_pipe[%u]", i);
                }
                OUT_RELOCW(ring, pipe->bo, 0, 0, 0);       /* VSC_PIPE_DATA_ADDRESS[i] */
        }
index 985face47ab2784ab1f8f762d1579c3b0f4abb19..37e02c61b1f1d7b53849cad91b79ea77e74f739d 100644 (file)
@@ -104,10 +104,10 @@ fd5_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        util_blitter_set_texture_multisample(fd5_ctx->base.blitter, true);
 
        fd5_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_size");
 
        fd5_ctx->blit_mem = fd_bo_new(screen->dev, 0x1000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "blit");
 
        fd_context_setup_common_vbos(&fd5_ctx->base);
 
index 9d7ebced31dc2286aa1d935439712aa5d0b28e16..d72d36dde3e47a4126554c636c47c9f433b3fb7e 100644 (file)
@@ -290,7 +290,7 @@ update_vsc_pipe(struct fd_batch *batch)
                struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[i];
                if (!pipe->bo) {
                        pipe->bo = fd_bo_new(ctx->dev, 0x20000,
-                                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_pipe[%u]", i);
                }
                OUT_RELOCW(ring, pipe->bo, 0, 0, 0);     /* VSC_PIPE_DATA_ADDRESS[i].LO/HI */
        }
index 083180826258fc6af739a653af45ab83657f2935..b8939b1449c7d30779c401c15fe54670f1a54313 100644 (file)
@@ -111,14 +111,14 @@ fd6_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
 
        fd6_ctx->vsc_data = fd_bo_new(screen->dev,
                        (A6XX_VSC_DATA_PITCH * 32) + 0x100,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_data");
 
        fd6_ctx->vsc_data2 = fd_bo_new(screen->dev,
                        A6XX_VSC_DATA2_PITCH * 32,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_data2");
 
        fd6_ctx->blit_mem = fd_bo_new(screen->dev, 0x1000,
-                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                       DRM_FREEDRENO_GEM_TYPE_KMEM, "blit");
 
        fd_context_setup_common_vbos(&fd6_ctx->base);
 
index 85bbbe271f97506ca48e29cd9fc7fd0a3bb35821..e59dc96ce35d4cc152daa3e3f9ab0e240ec8d76d 100644 (file)
@@ -97,10 +97,11 @@ rebind_resource(struct fd_context *ctx, struct pipe_resource *prsc)
 static void
 realloc_bo(struct fd_resource *rsc, uint32_t size)
 {
+       struct pipe_resource *prsc = &rsc->base;
        struct fd_screen *screen = fd_screen(rsc->base.screen);
        uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
                        DRM_FREEDRENO_GEM_TYPE_KMEM |
-                       COND(rsc->base.bind & PIPE_BIND_SCANOUT, DRM_FREEDRENO_GEM_SCANOUT);
+                       COND(prsc->bind & PIPE_BIND_SCANOUT, DRM_FREEDRENO_GEM_SCANOUT);
                        /* TODO other flags? */
 
        /* if we start using things other than write-combine,
@@ -110,7 +111,8 @@ realloc_bo(struct fd_resource *rsc, uint32_t size)
        if (rsc->bo)
                fd_bo_del(rsc->bo);
 
-       rsc->bo = fd_bo_new(screen->dev, size, flags);
+       rsc->bo = fd_bo_new(screen->dev, size, flags, "%ux%ux%u@%u:%x",
+                       prsc->width0, prsc->height0, prsc->depth0, rsc->cpp, prsc->bind);
        rsc->seqno = p_atomic_inc_return(&screen->rsc_seqno);
        util_range_set_empty(&rsc->valid_buffer_range);
        fd_bc_invalidate_resource(rsc, true);
@@ -869,7 +871,7 @@ fd_resource_create(struct pipe_screen *pscreen,
                rsc->lrz_height = lrz_height;
                rsc->lrz_width = lrz_pitch;
                rsc->lrz_pitch = lrz_pitch;
-               rsc->lrz = fd_bo_new(screen->dev, size, flags);
+               rsc->lrz = fd_bo_new(screen->dev, size, flags, "lrz");
        }
 
        size = screen->setup_slices(rsc);