winsys/amdgpu: use DMA_BUF_SET_NAME_B if available

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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20728>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2023-01-12 17:31:53 +01:00 committed by Marge Bot
parent 3ed75027b7
commit f2ef663d08

View file

@ -25,13 +25,17 @@
* of the Software.
*/
#include <sys/ioctl.h>
#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 <xf86drm.h>
#include <stdio.h>
#include <inttypes.h>
@ -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;