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 EF8EDC531CC for ; Thu, 23 Jul 2026 19:45:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9ED5C10E5FD; Thu, 23 Jul 2026 19:45:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="h346eplR"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76DC910E5F6; Thu, 23 Jul 2026 19:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:From:Reply-To; bh=ANM+eSpahzqvwTWIXh7CuP5Wcj+NwCM3k9v5P8p6HW0=; b=h346eplRPhHoYuGW8wVYekjxMu QghtysnX7QdBNz76NJWqgX1UieBEchDa1n4Ewbmj8kA2K7ANCrkH3j9Id6wWcld1FERJJMfsEo0Ww vyU1hzzCtw+vWSvdGkDZbhsG1ZNfhe2F4WNoRqxOIJdVu9UADC8Ckf/qu3rIfbpinrQ3+SBDB1SFd it2pmEC++g4RIOkFY3bTQIGyxDzVJibzpNd5ThjLmOn7TdGPeXZKBjurV5YGVgAWeE/lPltISN2rf kHnYVByUKevjr+MqUxJwKwXdvDFXUlaNzrr4yXHRqtHdlSjNl3HpG8Uq9Czlc8vLnroNZTylrq1aB BVXPXryQ==; Received: from 179-125-91-91-dinamico.pombonet.net.br ([179.125.91.91] helo=quatroqueijos.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wmzL4-003a1P-U0; Thu, 23 Jul 2026 21:44:15 +0200 From: Thadeu Lima de Souza Cascardo 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=20Hellstr=C3=B6m?= , Kamil Konieczny , Janusz Krzysztofik , Vitaly Prosyak , Natalie Vock , Tvrtko Ursulin , kernel-dev@igalia.com Subject: [PATCH i-g-t v5 3/7] lib/xe: add xe_cgroup_region_name() helper Date: Thu, 23 Jul 2026 16:43:09 -0300 Message-ID: <20260723194313.2748143-4-cascardo@igalia.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260723194313.2748143-1-cascardo@igalia.com> References: <20260723194313.2748143-1-cascardo@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" 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