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 v4 6/6] xe/treewide: use xe_query helpers for query GT topology
Date: Thu, 20 Nov 2025 15:25:43 +0100 [thread overview]
Message-ID: <20251120-xe_query_helpers-v4-6-2ed6dc04dd94@intel.com> (raw)
In-Reply-To: <20251120-xe_query_helpers-v4-0-2ed6dc04dd94@intel.com>
Using xe_query_device and xe_for_each_topology_mask simplifies the code.
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
lib/xe/xe_oa.c | 37 ++++++----------------
tests/intel/xe_eudebug_online.c | 30 +++---------------
tests/intel/xe_query.c | 69 ++++++++++-------------------------------
3 files changed, 30 insertions(+), 106 deletions(-)
diff --git a/lib/xe/xe_oa.c b/lib/xe/xe_oa.c
index 428e7d0a2980dba1106d62a4bf20e56af5b9997a..229deafa7132fd7d4992d419146c3620314abe3e 100644
--- a/lib/xe/xe_oa.c
+++ b/lib/xe/xe_oa.c
@@ -450,15 +450,9 @@ xe_fill_topology_info(int drm_fd, uint32_t device_id, uint32_t *topology_size)
const struct intel_device_info *devinfo = intel_get_device_info(device_id);
struct intel_xe_topology_info topinfo = {};
struct intel_xe_topology_info *ptopo;
- struct drm_xe_query_topology_mask *xe_topo;
- int pos = 0;
+ struct drm_xe_query_topology_mask *xe_topo, *topo;
+ uint32_t size;
u8 *ptr;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_GT_TOPOLOGY,
- .size = 0,
- .data = 0,
- };
/* Only ADL-P, DG2 and newer ip support hwconfig, use hardcoded values for previous */
if (intel_graphics_ver(device_id) >= IP_VER(12, 55) || devinfo->is_alderlake_p) {
@@ -485,31 +479,21 @@ xe_fill_topology_info(int drm_fd, uint32_t device_id, uint32_t *topology_size)
ptr = (u8 *)ptopo + sizeof(topinfo);
*ptr++ = 0x1; /* slice mask */
- /* Get xe topology masks */
- igt_assert_eq(igt_ioctl(drm_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- igt_assert_neq(query.size, 0);
-
- xe_topo = malloc(query.size);
- igt_assert(xe_topo);
+ xe_topo = xe_query_device(drm_fd, DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, &size);
+ igt_debug("Topology size: %d\n", size);
- query.data = to_user_pointer(xe_topo);
- igt_assert_eq(igt_ioctl(drm_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- igt_debug("Topology size: %d\n", query.size);
-
- while (query.size >= sizeof(struct drm_xe_query_topology_mask)) {
- struct drm_xe_query_topology_mask *topo =
- (struct drm_xe_query_topology_mask*)((unsigned char*)xe_topo + pos);
- int i, sz = sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes;
+ xe_for_each_topology_mask(xe_topo, size, topo) {
u64 geom_mask, compute_mask;
- igt_debug(" gt_id: %d type: %d n:%d [%d] ", topo->gt_id, topo->type, topo->num_bytes, sz);
+ igt_debug(" gt_id: %d type: %d n:%d [%zd] ", topo->gt_id, topo->type, topo->num_bytes,
+ sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes);
for (int j=0; j< topo->num_bytes; j++)
igt_debug(" %02x", topo->mask[j]);
igt_debug("\n");
/* i915 only returns topology for gt 0, do the same here */
if (topo->gt_id)
- goto next;
+ continue;
/* Follow the same order as in xe query_gt_topology() */
switch (topo->type) {
@@ -525,7 +509,7 @@ xe_fill_topology_info(int drm_fd, uint32_t device_id, uint32_t *topology_size)
break;
case DRM_XE_TOPO_EU_PER_DSS:
case DRM_XE_TOPO_SIMD16_EU_PER_DSS:
- for (i = 0; i < ptopo->max_subslices; i++) {
+ for (int i = 0; i < ptopo->max_subslices; i++) {
memcpy(ptr, topo->mask, ptopo->eu_stride);
ptr += ptopo->eu_stride;
}
@@ -535,9 +519,6 @@ xe_fill_topology_info(int drm_fd, uint32_t device_id, uint32_t *topology_size)
default:
igt_assert(0);
}
-next:
- query.size -= sz;
- pos += sz;
}
free(xe_topo);
diff --git a/tests/intel/xe_eudebug_online.c b/tests/intel/xe_eudebug_online.c
index ef700c2591291f9a22849c2995c83cc5ec0ac6d9..90bc4361a4c75da6b630ff60e812d785dbf6bead 100644
--- a/tests/intel/xe_eudebug_online.c
+++ b/tests/intel/xe_eudebug_online.c
@@ -1184,36 +1184,14 @@ static int query_attention_bitmask_size(int fd, int gt)
{
uint32_t threads_per_eu = xe_hwconfig_get_u32(fd, INTEL_HWCONFIG_NUM_THREADS_PER_EU, 8);
struct drm_xe_query_topology_mask *c_dss = NULL, *g_dss = NULL, *eu_per_dss = NULL;
- struct drm_xe_query_topology_mask *topology;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_GT_TOPOLOGY,
- .size = 0,
- .data = 0,
- };
+ struct drm_xe_query_topology_mask *topology, *topo;
uint8_t dss_mask, last_dss;
- int pos = 0;
+ uint32_t size;
int i, last_dss_idx;
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- igt_assert_neq(query.size, 0);
-
- topology = malloc(query.size);
- igt_assert(topology);
-
- query.data = to_user_pointer(topology);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- while (query.size >= sizeof(struct drm_xe_query_topology_mask)) {
- struct drm_xe_query_topology_mask *topo;
- int sz;
-
- topo = (struct drm_xe_query_topology_mask *)((unsigned char *)topology + pos);
- sz = sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes;
-
- query.size -= sz;
- pos += sz;
+ topology = xe_query_device(fd, DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, &size);
+ xe_for_each_topology_mask(topology, size, topo) {
if (topo->gt_id != gt)
continue;
diff --git a/tests/intel/xe_query.c b/tests/intel/xe_query.c
index 928daaf5875d8e62888f8b994e31d5d6315afe73..36f9d87002d50ff3f4973657def65e282e53c899 100644
--- a/tests/intel/xe_query.c
+++ b/tests/intel/xe_query.c
@@ -358,42 +358,25 @@ static void
test_query_gt_topology(int fd)
{
uint16_t dev_id = intel_get_drm_devid(fd);
- struct drm_xe_query_topology_mask *topology;
- int pos = 0;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_GT_TOPOLOGY,
- .size = 0,
- .data = 0,
- };
- uint32_t topo_types = 0;
+ struct drm_xe_query_topology_mask *topology, *topo;
+ uint32_t topo_types = 0, size;
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- igt_assert_neq(query.size, 0);
-
- topology = malloc(query.size);
- igt_assert(topology);
+ topology = xe_query_device(fd, DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, &size);
- query.data = to_user_pointer(topology);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+ igt_info("size: %d\n", size);
- igt_info("size: %d\n", query.size);
- dump_hex_debug(topology, query.size);
+ dump_hex_debug(topology, size);
- while (query.size >= sizeof(struct drm_xe_query_topology_mask)) {
- struct drm_xe_query_topology_mask *topo = (struct drm_xe_query_topology_mask*)((unsigned char*)topology + pos);
- int sz = sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes;
-
- igt_info(" gt_id: %2d type: %-12s (%d) n:%d [%d] ", topo->gt_id,
- get_topo_name(topo->type), topo->type, topo->num_bytes, sz);
+ xe_for_each_topology_mask(topology, size, topo) {
+ igt_info(" gt_id: %2d type: %-12s (%d) n:%d [%zd] ", topo->gt_id,
+ get_topo_name(topo->type), topo->type, topo->num_bytes,
+ sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes);
for (int j=0; j< topo->num_bytes; j++)
igt_info(" %02x", topo->mask[j]);
topo_types = 1 << topo->type;
igt_info("\n");
- query.size -= sz;
- pos += sz;
}
/* sanity check EU type */
@@ -422,35 +405,20 @@ static void
test_query_gt_topology_l3_bank_mask(int fd)
{
uint16_t dev_id = intel_get_drm_devid(fd);
- struct drm_xe_query_topology_mask *topology;
- int pos = 0;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_GT_TOPOLOGY,
- .size = 0,
- .data = 0,
- };
+ struct drm_xe_query_topology_mask *topology, *topo;
+ uint32_t size;
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
- igt_assert_neq(query.size, 0);
+ topology = xe_query_device(fd, DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, &size);
- topology = malloc(query.size);
- igt_assert(topology);
-
- query.data = to_user_pointer(topology);
- igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
-
- igt_info("size: %d\n", query.size);
-
- while (query.size >= sizeof(struct drm_xe_query_topology_mask)) {
- struct drm_xe_query_topology_mask *topo = (struct drm_xe_query_topology_mask *)((unsigned char *)topology + pos);
- int sz = sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes;
+ igt_info("size: %d\n", size);
+ xe_for_each_topology_mask(topology, size, topo) {
if (topo->type == DRM_XE_TOPO_L3_BANK) {
int count = 0;
- igt_info(" gt_id: %2d type: %-12s (%d) n:%d [%d] ", topo->gt_id,
- get_topo_name(topo->type), topo->type, topo->num_bytes, sz);
+ igt_info(" gt_id: %2d type: %-12s (%d) n:%d [%zd] ", topo->gt_id,
+ get_topo_name(topo->type), topo->type, topo->num_bytes,
+ sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes);
for (int j = 0; j < topo->num_bytes; j++)
igt_info(" %02x", topo->mask[j]);
@@ -471,9 +439,6 @@ test_query_gt_topology_l3_bank_mask(int fd)
else if (IS_DG2(dev_id))
igt_assert_eq((count % 8), 0);
}
-
- query.size -= sz;
- pos += sz;
}
free(topology);
--
2.43.0
next prev parent reply other threads:[~2025-11-20 14:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 14:25 [PATCH v4 0/6] lib/xe/xe_query: implement few query helpers Andrzej Hajda
2025-11-20 14:25 ` [PATCH v4 1/6] lib/xe_query: add helper to get first value of hwconfig Andrzej Hajda
2025-11-20 14:25 ` [PATCH v4 2/6] tests/intel/xe_eudebug_online: use helper to get hwconfig value Andrzej Hajda
2025-11-20 14:25 ` [PATCH v4 3/6] lib/xe/xe_query: introduce helpers for device query Andrzej Hajda
2025-11-20 14:25 ` [PATCH v4 4/6] lib/xe/xe_query: use recently introduced helper to query device Andrzej Hajda
2025-11-20 14:25 ` [PATCH v4 5/6] lib/xe/xe_query: introduce iterator for GT topology masks Andrzej Hajda
2025-11-20 14:25 ` Andrzej Hajda [this message]
2025-11-20 15:44 ` ✗ Fi.CI.BUILD: failure for lib/xe/xe_query: implement few query helpers (rev4) 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=20251120-xe_query_helpers-v4-6-2ed6dc04dd94@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).