From f2ef663d08b88489cc0484737a5c9bbbf31b35ec Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 12 Jan 2023 17:31:53 +0100 Subject: [PATCH] winsys/amdgpu: use DMA_BUF_SET_NAME_B if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give a name to dma-buf. This name appears in /sys/kernel/debug/dma_buf/bufinfo and could be useful to debug dma-buf: Dma-buf Objects: size flags mode count exp_name ino name 00606208 00000002 00080007 00000003 drm 00192014 2321705-glxgears The name is only added to non-shared buffer, to avoid overwriting an existing name when exporting an imported buffer (otherwise all dma-buf will pretend to be created by XWayland). Reviewed-by: Marek Olšák Part-of: --- src/gallium/winsys/amdgpu/drm/amdgpu_bo.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c index 1b53bcc61b0..d39ef610ed6 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c @@ -25,13 +25,17 @@ * of the Software. */ +#include + #include "amdgpu_cs.h" #include "util/hash_table.h" #include "util/os_time.h" #include "util/u_hash_table.h" +#include "util/u_process.h" #include "frontend/drm_driver.h" #include "drm-uapi/amdgpu_drm.h" +#include "drm-uapi/dma-buf.h" #include #include #include @@ -1636,6 +1640,15 @@ static bool amdgpu_bo_get_handle(struct radeon_winsys *rws, if (r) return false; +#if defined(DMA_BUF_SET_NAME_B) + if (whandle->type == WINSYS_HANDLE_TYPE_FD && + !bo->u.real.is_shared) { + char dmabufname[32]; + snprintf(dmabufname, 32, "%d-%s", getpid(), util_get_process_name()); + r = ioctl(whandle->handle, DMA_BUF_SET_NAME_B, (uint64_t)(uintptr_t)dmabufname); + } +#endif + if (whandle->type == WINSYS_HANDLE_TYPE_KMS) { int dma_fd = whandle->handle;