On 03/09/2026 23:00, Thadeu Lima de Souza Cascardo wrote:
The amdgpu dmem region name uses its PCI address, just like the one from
Xe, but there is only a single VRAM region.
Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]>
---
lib/amdgpu/amd_memory.c | 25 +++++++++++++++++++++++++
lib/amdgpu/amd_memory.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/lib/amdgpu/amd_memory.c b/lib/amdgpu/amd_memory.c
index 12fe23c65ab2..2da4a8a4baee 100644
--- a/lib/amdgpu/amd_memory.c
+++ b/lib/amdgpu/amd_memory.c
@@ -30,9 +30,11 @@
#include <amdgpu_drm.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include <unistd.h>
#include <sys/mman.h>
#include <inttypes.h>
+#include "igt_device.h"
/**
*
@@ -679,6 +681,29 @@ bool virtual_free_memory(void *address, unsigned int size)
}
}
+/**
+ * amdgpu_cgroup_region_name() - Build the dmem cgroup region name for an
amdgpu.
+ * @fd: amdgpu device fd.
+ *
+ * Constructs the full dmem cgroup region path for VRAM on the device
+ * identified by @fd. The returned string has the form
+ * ``drm/<pci-slot>/vram`` (e.g. ``drm/0000:03:00.0/vram``), matching
+ * the name registered by the kernel driver via drmm_cgroup_register_region().
+ *
+ * Return: A newly allocated string that the caller must free(), or %NULL if
+ * @region is not tracked by the dmem cgroup controller.
+ */
+char *amdgpu_cgroup_region_name(int fd)
+{
+ char pci_slot[NAME_MAX];
+ char *name;
+
+ igt_device_get_pci_slot_name(fd, pci_slot);
+
+ igt_assert(asprintf(&name, "drm/%s/vram", pci_slot) > 0);
+ return name;
+}
+
/**
* Wait for specific value in memory with timeout
*/
diff --git a/lib/amdgpu/amd_memory.h b/lib/amdgpu/amd_memory.h
index e26c85bc4b0a..de169e580c1b 100644
--- a/lib/amdgpu/amd_memory.h
+++ b/lib/amdgpu/amd_memory.h
@@ -105,6 +105,8 @@ void
bool
virtual_free_memory(void *address, unsigned int size);
+char *amdgpu_cgroup_region_name(int fd);
+
bool
wait_on_value(unsigned int *ptr, unsigned int expected);
#endif
Reviewed-by: Tvrtko Ursulin <[email protected]>
Regards,
Tvrtko