From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BBC44C61DD3 for ; Thu, 3 Sep 2026 22:01:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6DF8510F7C4; Thu, 3 Sep 2026 22:01:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="aSxDm6g7"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id E664F10F7BA; Thu, 3 Sep 2026 22:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=4EQ8gvxRbCPbIFotssW6TchhXQMqXAy0oofRn+lPc6s=; b=aSxDm6g7IbEZwkA9r0Kn86KXU6 SCi9LSNvVtHvvT9+dnjHsN833vAVi+YTZig2iwmXHVDFVIMzA/1gQ/sIL0D55dLU9q+ShWtnsBx1G 7neuqOvkG/v3rALMwn4f6JErPfVewv6Yddnloo515ehIZv3/1M2xWk3faOUPOHsMQ1iY7sbjHjXTd BqZ201wCehsb968DCfKggUf+w56DPUagiX+T4ZRh/Q5/BoHH6kADnIDTHfC2Vj7OC0F2Sl3sIaj0W roxCIcpJqVYYvTp25CWkVDnBIYAREgrgfr7MN+RgdWcQiD8cdQe9f3Xv6X0BAJ78c8Y6R7KKUVCZj 7QkTsIMA==; Received: from [187.43.152.48] (helo=[127.0.0.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1x2FUR-00EbUz-QR; Fri, 04 Sep 2026 00:01:00 +0200 From: Thadeu Lima de Souza Cascardo Date: Thu, 03 Sep 2026 19:00:25 -0300 Subject: [PATCH i-g-t v6 3/9] lib/xe: add xe_cgroup_region_name() helper MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260903-dmem_max-v6-3-61dc62970fae@igalia.com> References: <20260903-dmem_max-v6-0-61dc62970fae@igalia.com> In-Reply-To: <20260903-dmem_max-v6-0-61dc62970fae@igalia.com> To: igt-dev@lists.freedesktop.org Cc: siqueira@igalia.com, Thadeu Lima de Souza Cascardo , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Christian Koenig , maarten.lankhorst@linux.intel.com, =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Kamil Konieczny , Janusz Krzysztofik , Vitaly Prosyak , Natalie Vock , Tvrtko Ursulin , kernel-dev@igalia.com X-Mailer: b4 0.16-dev-62088 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" From: Thomas Hellström 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//" (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 --- 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 68e60ddc75a2..e2b25be21140 100644 --- a/lib/xe/xe_query.c +++ b/lib/xe/xe_query.c @@ -7,6 +7,7 @@ */ #include +#include #include #include @@ -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_common.h" @@ -1304,6 +1306,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//`` (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 59330d80fd1b..a6ef9cab9aa1 100644 --- a/lib/xe/xe_query.h +++ b/lib/xe/xe_query.h @@ -206,4 +206,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