From: Thomas Hellström <[email protected]> Add xe_cgroup_region_name(fd, region) which constructs the dmem cgroup region path for a given xe memory region. The returned string has the form "drm/<pci-slot>/<region>" (e.g. "drm/0000:03:00.0/vram0"), matching the name registered by the kernel via drmm_cgroup_register_region().
Only VRAM regions are tracked by the dmem controller; system and stolen memory regions return NULL. Assisted-by: GitHub Copilot:claude-sonnet-4.6 Signed-off-by: Thomas Hellström <[email protected]> --- lib/xe/xe_query.c | 32 ++++++++++++++++++++++++++++++++ lib/xe/xe_query.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c index f0799f268cf4..192d9566178a 100644 --- a/lib/xe/xe_query.c +++ b/lib/xe/xe_query.c @@ -7,6 +7,7 @@ */ #include <fcntl.h> +#include <limits.h> #include <stdlib.h> #include <pthread.h> @@ -21,6 +22,7 @@ #include "drmtest.h" #include "igt_debugfs.h" +#include "igt_device.h" #include "ioctl_wrappers.h" #include "igt_map.h" #include "intel_pat.h" @@ -1290,6 +1292,36 @@ int xe_query_eu_thread_count(int fd, int gt) xe_hwconfig_lookup_value_u32(fd, INTEL_HWCONFIG_NUM_THREADS_PER_EU); } +/** + * xe_cgroup_region_name() - Build the dmem cgroup region name for an xe memory region. + * @fd: xe device fd. + * @region: Region mask (as used by xe_mem_region(), xe_region_name(), etc.). + * + * Constructs the full dmem cgroup region path for @region on the device + * identified by @fd. The returned string has the form + * ``drm/<pci-slot>/<region>`` (e.g. ``drm/0000:03:00.0/vram0``), matching + * the name registered by the kernel driver via drmm_cgroup_register_region(). + * + * Only VRAM regions are registered with the dmem controller; passing a + * system-memory region returns %NULL. + * + * Return: A newly allocated string that the caller must free(), or %NULL if + * @region is not tracked by the dmem cgroup controller. + */ +char *xe_cgroup_region_name(int fd, uint64_t region) +{ + char pci_slot[NAME_MAX]; + char *name; + + if (xe_region_class(fd, region) != DRM_XE_MEM_REGION_CLASS_VRAM) + return NULL; + + igt_device_get_pci_slot_name(fd, pci_slot); + + igt_assert(asprintf(&name, "drm/%s/%s", pci_slot, xe_region_name(region)) > 0); + return name; +} + igt_constructor { xe_device_cache_init(); diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h index 9f04a7422042..a34e9a6592b9 100644 --- a/lib/xe/xe_query.h +++ b/lib/xe/xe_query.h @@ -205,4 +205,6 @@ void xe_device_put(int fd); int xe_query_eu_count(int fd, int gt); int xe_query_eu_thread_count(int fd, int gt); +char *xe_cgroup_region_name(int fd, uint64_t region); + #endif /* XE_QUERY_H */ -- 2.47.3
