From b9b1c5438e44a57f1d2a23e32bb65d5067eafbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= Date: Thu, 12 Jun 2025 01:37:43 +0100 Subject: [PATCH] panfrost: Label kernel BO's for newly created objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To this end, provide a helper that passes the label to the kmod layer upon demand. Helper returns the old label, in preparation for future commits in which the label might not be in static RO memory, but dynamically alocated instead, and its lifetime managed by the resource layer. Signed-off-by: Adrián Larumbe Reviewed-by: Boris Brezillon Part-of: --- src/gallium/drivers/panfrost/pan_bo.c | 21 ++++++++++++++++++--- src/gallium/drivers/panfrost/pan_bo.h | 8 ++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_bo.c b/src/gallium/drivers/panfrost/pan_bo.c index c37b3b868ff..0aeca6bce6a 100644 --- a/src/gallium/drivers/panfrost/pan_bo.c +++ b/src/gallium/drivers/panfrost/pan_bo.c @@ -112,8 +112,8 @@ panfrost_bo_alloc(struct panfrost_device *dev, size_t size, uint32_t flags, bo->ptr.gpu = vm_op.va.start; bo->flags = flags; bo->dev = dev; - bo->label = label; return bo; + err_bind: pan_kmod_bo_put(kmod_bo); /* BO will be freed with the sparse array, but zero to indicate free */ @@ -243,7 +243,6 @@ panfrost_bo_cache_fetch(struct panfrost_device *dev, size_t size, } /* Let's go! */ bo = entry; - bo->label = label; break; } pthread_mutex_unlock(&dev->bo_cache.lock); @@ -309,7 +308,7 @@ panfrost_bo_cache_put(struct panfrost_bo *bo) panfrost_bo_cache_evict_stale_bos(dev); /* Update the label to help debug BO cache memory usage issues */ - bo->label = "Unused (BO cache)"; + panfrost_bo_set_label(bo, "Unused (BO cache)"); /* Must be last */ pthread_mutex_unlock(&dev->bo_cache.lock); @@ -439,6 +438,8 @@ panfrost_bo_create(struct panfrost_device *dev, size_t size, uint32_t flags, panfrost_bo_size(bo), NULL); } + panfrost_bo_set_label(bo, label); + return bo; } @@ -571,3 +572,17 @@ panfrost_bo_from_kmod_bo(struct panfrost_device *dev, return bo; } + +const char * +panfrost_bo_replace_label(struct panfrost_bo *bo, const char *label, + bool set_kernel_label) +{ + const char *old_label = bo->label; + + bo->label = label; + + if (set_kernel_label) + pan_kmod_set_bo_label(bo->dev->kmod.dev, bo->kmod_bo, label); + + return old_label; +} diff --git a/src/gallium/drivers/panfrost/pan_bo.h b/src/gallium/drivers/panfrost/pan_bo.h index 36874103ffe..a3e7f87b337 100644 --- a/src/gallium/drivers/panfrost/pan_bo.h +++ b/src/gallium/drivers/panfrost/pan_bo.h @@ -140,4 +140,12 @@ struct panfrost_bo *panfrost_bo_import(struct panfrost_device *dev, int fd); int panfrost_bo_export(struct panfrost_bo *bo); void panfrost_bo_cache_evict_all(struct panfrost_device *dev); +const char *panfrost_bo_replace_label(struct panfrost_bo *bo, const char *label, + bool set_kernel_label); +static inline const char * +panfrost_bo_set_label(struct panfrost_bo *bo, const char *label) +{ + return panfrost_bo_replace_label(bo, label, true); +} + #endif /* __PAN_BO_H__ */