From: Andrzej Hajda <andrzej.hajda@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Priyanka Dandamudi" <priyanka.dandamudi@intel.com>,
"Gwan-gyeong Mun" <gwan-gyeong.mun@intel.com>,
"Piotr Piórkowski" <piotr.piorkowski@intel.com>,
"Christoph Manszewski" <christoph.manszewski@intel.com>,
"Andrzej Hajda" <andrzej.hajda@intel.com>
Subject: [PATCH v5 3/5] lib/xe/xe_query: use recently introduced helper to query device
Date: Fri, 21 Nov 2025 11:59:02 +0100 [thread overview]
Message-ID: <20251121-xe_query_helpers-v5-3-d69c1c160e96@intel.com> (raw)
In-Reply-To: <20251121-xe_query_helpers-v5-0-d69c1c160e96@intel.com>
It simplifies the code.
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
lib/xe/xe_query.c | 190 +++---------------------------------------------------
1 file changed, 8 insertions(+), 182 deletions(-)
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index a185b852e19b87e393f4bc6edbf9e0952439d518..3f3ee9b965949c2d0b821c9346183021db8338a9 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -68,83 +68,6 @@ skip_query:
return data;
}
-static struct drm_xe_query_config *xe_query_config_new(int fd)
-{
- struct drm_xe_query_config *config;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_CONFIG,
- .size = 0,
- .data = 0,
- };
-
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- config = malloc(query.size);
- igt_assert(config);
-
- query.data = to_user_pointer(config);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(config, query.size));
-
- igt_assert(config->num_params > 0);
-
- return config;
-}
-
-static uint32_t *xe_query_hwconfig_new(int fd, uint32_t *hwconfig_size)
-{
- uint32_t *hwconfig;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_HWCONFIG,
- .size = 0,
- .data = 0,
- };
-
- /* Perform the initial query to get the size */
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- if (!query.size)
- return NULL;
-
- hwconfig = malloc(query.size);
- igt_assert(hwconfig);
-
- query.data = to_user_pointer(hwconfig);
-
- /* Perform the query to get the actual data */
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(hwconfig, query.size));
-
- *hwconfig_size = query.size;
- return hwconfig;
-}
-
-static struct drm_xe_query_gt_list *xe_query_gt_list_new(int fd)
-{
- struct drm_xe_query_gt_list *gt_list;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_GT_LIST,
- .size = 0,
- .data = 0,
- };
-
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- gt_list = malloc(query.size);
- igt_assert(gt_list);
-
- query.data = to_user_pointer(gt_list);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(gt_list, query.size));
-
- return gt_list;
-}
-
static uint64_t __memory_regions(const struct drm_xe_query_gt_list *gt_list)
{
uint64_t regions = 0;
@@ -157,103 +80,6 @@ static uint64_t __memory_regions(const struct drm_xe_query_gt_list *gt_list)
return regions;
}
-static struct drm_xe_query_engines *xe_query_engines(int fd)
-{
- struct drm_xe_query_engines *engines;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_ENGINES,
- .size = 0,
- .data = 0,
- };
-
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- engines = malloc(query.size);
- igt_assert(engines);
-
- query.data = to_user_pointer(engines);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(engines, query.size));
-
- return engines;
-}
-
-static struct drm_xe_query_mem_regions *xe_query_mem_regions_new(int fd)
-{
- struct drm_xe_query_mem_regions *mem_regions;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_MEM_REGIONS,
- .size = 0,
- .data = 0,
- };
-
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- mem_regions = malloc(query.size);
- igt_assert(mem_regions);
-
- query.data = to_user_pointer(mem_regions);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(mem_regions, query.size));
-
- return mem_regions;
-}
-
-static struct drm_xe_query_eu_stall *xe_query_eu_stall_new(int fd)
-{
- struct drm_xe_query_eu_stall *query_eu_stall;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_EU_STALL,
- .size = 0,
- .data = 0,
- };
-
- /* Support older kernels where this uapi is not yet available */
- if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
- return NULL;
- igt_assert_neq(query.size, 0);
-
- query_eu_stall = malloc(query.size);
- igt_assert(query_eu_stall);
-
- query.data = to_user_pointer(query_eu_stall);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(query_eu_stall, query.size));
-
- return query_eu_stall;
-}
-
-static struct drm_xe_query_oa_units *xe_query_oa_units_new(int fd)
-{
- struct drm_xe_query_oa_units *oa_units;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_OA_UNITS,
- .size = 0,
- .data = 0,
- };
-
- /* Support older kernels where this uapi is not yet available */
- if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
- return NULL;
-
- oa_units = malloc(query.size);
- igt_assert(oa_units);
-
- query.data = to_user_pointer(oa_units);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- VG(VALGRIND_MAKE_MEM_DEFINED(oa_units, query.size));
-
- return oa_units;
-}
-
static uint64_t native_region_for_gt(const struct drm_xe_gt *gt)
{
uint64_t region;
@@ -412,11 +238,11 @@ struct xe_device *xe_device_get(int fd)
igt_assert(xe_dev);
xe_dev->fd = fd;
- xe_dev->config = xe_query_config_new(fd);
- xe_dev->hwconfig = xe_query_hwconfig_new(fd, &xe_dev->hwconfig_size);
+ xe_dev->config = xe_query_device(fd, DRM_XE_DEVICE_QUERY_CONFIG, NULL);
+ xe_dev->hwconfig = xe_query_device_may_fail(fd, DRM_XE_DEVICE_QUERY_HWCONFIG, &xe_dev->hwconfig_size);
xe_dev->va_bits = xe_dev->config->info[DRM_XE_QUERY_CONFIG_VA_BITS];
xe_dev->dev_id = xe_dev->config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] & 0xffff;
- xe_dev->gt_list = xe_query_gt_list_new(fd);
+ xe_dev->gt_list = xe_query_device(fd, DRM_XE_DEVICE_QUERY_GT_LIST, NULL);
/* GT IDs may be non-consecutive; keep a mask of valid IDs */
for (int gt = 0; gt < xe_dev->gt_list->num_gt; gt++)
@@ -427,10 +253,10 @@ struct xe_device *xe_device_get(int fd)
xe_dev->tile_mask |= (1ull << xe_dev->gt_list->gt_list[gt].tile_id);
xe_dev->memory_regions = __memory_regions(xe_dev->gt_list);
- xe_dev->engines = xe_query_engines(fd);
- xe_dev->mem_regions = xe_query_mem_regions_new(fd);
- xe_dev->eu_stall = xe_query_eu_stall_new(fd);
- xe_dev->oa_units = xe_query_oa_units_new(fd);
+ xe_dev->engines = xe_query_device(fd, DRM_XE_DEVICE_QUERY_ENGINES, NULL);
+ xe_dev->mem_regions = xe_query_device(fd, DRM_XE_DEVICE_QUERY_MEM_REGIONS, NULL);
+ xe_dev->eu_stall = xe_query_device_may_fail(fd, DRM_XE_DEVICE_QUERY_EU_STALL, NULL);
+ xe_dev->oa_units = xe_query_device_may_fail(fd, DRM_XE_DEVICE_QUERY_OA_UNITS, NULL);
/*
* vram_size[] and visible_vram_size[] are indexed by uapi ID; ensure
@@ -860,7 +686,7 @@ static void __available_vram_size_snapshot(int fd, int gt, struct __available_vr
mem_region = &xe_dev->mem_regions->mem_regions[region_idx];
if (XE_IS_CLASS_VRAM(mem_region)) {
- mem_regions = xe_query_mem_regions_new(fd);
+ mem_regions = xe_query_device(fd, DRM_XE_DEVICE_QUERY_MEM_REGIONS, NULL);
pthread_mutex_lock(&cache.cache_mutex);
mem_region->used = mem_regions->mem_regions[region_idx].used;
mem_region->cpu_visible_used =
--
2.43.0
next prev parent reply other threads:[~2025-11-21 11:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 10:58 [PATCH v5 0/5] lib/xe/xe_query: implement few query helpers Andrzej Hajda
2025-11-21 10:59 ` [PATCH v5 1/5] tests/intel/xe_eudebug_online: use helper to get hwconfig value Andrzej Hajda
2025-11-21 10:59 ` [PATCH v5 2/5] lib/xe/xe_query: introduce helpers for device query Andrzej Hajda
2025-11-24 8:13 ` Dandamudi, Priyanka
2025-11-24 8:55 ` Dandamudi, Priyanka
2025-11-24 9:29 ` Kamil Konieczny
2025-11-24 9:41 ` Kamil Konieczny
2025-11-21 10:59 ` Andrzej Hajda [this message]
2025-11-24 11:01 ` [PATCH v5 3/5] lib/xe/xe_query: use recently introduced helper to query device Kamil Konieczny
2025-11-21 10:59 ` [PATCH v5 4/5] lib/xe/xe_query: introduce iterator for GT topology masks Andrzej Hajda
2025-11-21 10:59 ` [PATCH v5 5/5] xe/treewide: use xe_query helpers for query GT topology Andrzej Hajda
2025-11-24 11:16 ` Kamil Konieczny
2025-11-25 3:47 ` ✓ i915.CI.BAT: success for lib/xe/xe_query: implement few query helpers (rev5) Patchwork
2025-11-25 3:48 ` ✓ Xe.CI.BAT: " Patchwork
2025-11-25 5:44 ` ✗ Xe.CI.Full: failure " Patchwork
2025-11-25 9:48 ` ✗ i915.CI.Full: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251121-xe_query_helpers-v5-3-d69c1c160e96@intel.com \
--to=andrzej.hajda@intel.com \
--cc=christoph.manszewski@intel.com \
--cc=gwan-gyeong.mun@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=piotr.piorkowski@intel.com \
--cc=priyanka.dandamudi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).