[PATCH v2 3/4] lib/xe: use debugfs info to implement xe_engine_class_supports_multi_queue()

Xin Wang
2026-04-03T07:13:57Z

Update xe_engine_class_supports_multi_queue() to take a device fd and
use the kernel-reported multi_queue_engine_classes bitmask from debugfs
when available, with a fallback to the hardcoded default for older KMD.

Propagate the new fd argument through the xe_for_each_multi_queue_engine
and xe_for_each_multi_queue_engine_class macros and all their call sites.

Signed-off-by: Xin Wang <x.wang@intel.com>
---
lib/xe/xe_query.c | 52 ++++++++++++++++++-------------
lib/xe/xe_query.h | 8 ++---
tests/intel/xe_exec_multi_queue.c | 4 +--
tests/intel/xe_exec_threads.c | 4 +--
4 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index e13d5e143..3286a3b37 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -215,28 +215,6 @@ static uint16_t xe_device_query_engine_class_mask(int fd, const char *key)
return mask;
}

-/**
- * xe_engine_class_supports_multi_queue:
- * @engine_class: engine class
- *
- * Returns true if multi queue supported by engine class or false.
- */
-bool xe_engine_class_supports_multi_queue(uint32_t engine_class)
-{
- switch (engine_class) {
- case DRM_XE_ENGINE_CLASS_COPY:
- case DRM_XE_ENGINE_CLASS_COMPUTE:
- return true;
- case DRM_XE_ENGINE_CLASS_RENDER:
- case DRM_XE_ENGINE_CLASS_VIDEO_DECODE:
- case DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE:
- return false;
- default:
- igt_warn("Engine class 0x%x unknown\n", engine_class);
- return false;
- }
-}
-
/**
* xe_engine_class_string:
* @engine_class: engine class
@@ -338,6 +316,36 @@ bool xe_engine_class_supports_multi_lrc(int fd, uint32_t engine_class)
}
}

+/**
+ * xe_engine_class_supports_multi_queue:
+ * @fd: xe device fd
+ * @engine_class: engine class
+ *
+ * Returns true if multi queue supported by engine class or false.
+ * Uses the kernel-reported bitmask from debugfs when available, otherwise
+ * falls back to the hardcoded per-class default.
+ */
+bool xe_engine_class_supports_multi_queue(int fd, uint32_t engine_class)
+{
+ struct xe_device *xe_dev = find_in_cache(fd);
+
+ if (xe_dev && xe_dev->multi_queue_engine_class_mask != UINT16_MAX)
+ return !!(xe_dev->multi_queue_engine_class_mask & BIT(engine_class));
+
+ switch (engine_class) {
+ case DRM_XE_ENGINE_CLASS_COPY:
+ case DRM_XE_ENGINE_CLASS_COMPUTE:
+ return true;
+ case DRM_XE_ENGINE_CLASS_RENDER:
+ case DRM_XE_ENGINE_CLASS_VIDEO_DECODE:
+ case DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE:
+ return false;
+ default:
+ igt_warn("Engine class 0x%x unknown\n", engine_class);
+ return false;
+ }
+}
+
static void xe_device_free(struct xe_device *xe_dev)
{
free(xe_dev->config);
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index 5c26a3e88..8815c6c66 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -113,10 +113,10 @@ struct xe_device {

#define xe_for_each_multi_queue_engine(__fd, __hwe) \
xe_for_each_engine(__fd, __hwe) \
- for_if(xe_engine_class_supports_multi_queue((__hwe)->engine_class))
-#define xe_for_each_multi_queue_engine_class(__class) \
+ for_if(xe_engine_class_supports_multi_queue(__fd, (__hwe)->engine_class))
+#define xe_for_each_multi_queue_engine_class(__fd, __class) \
xe_for_each_engine_class(__class) \
- for_if(xe_engine_class_supports_multi_queue(__class))
+ for_if(xe_engine_class_supports_multi_queue(__fd, __class))

#define XE_IS_CLASS_SYSMEM(__region) ((__region)->mem_class == DRM_XE_MEM_REGION_CLASS_SYSMEM)
#define XE_IS_CLASS_VRAM(__region) ((__region)->mem_class == DRM_XE_MEM_REGION_CLASS_VRAM)
@@ -161,7 +161,7 @@ uint32_t xe_get_default_alignment(int fd);
uint32_t xe_va_bits(int fd);
uint16_t xe_dev_id(int fd);
int xe_supports_faults(int fd);
-bool xe_engine_class_supports_multi_queue(uint32_t engine_class);
+bool xe_engine_class_supports_multi_queue(int fd, uint32_t engine_class);
bool xe_engine_class_supports_multi_lrc(int fd, uint32_t engine_class);
const char *xe_engine_class_string(uint32_t engine_class);
const char *xe_engine_class_short_string(uint32_t engine_class);
diff --git a/tests/intel/xe_exec_multi_queue.c b/tests/intel/xe_exec_multi_queue.c
index f987f8d6a..b5ded0633 100644
--- a/tests/intel/xe_exec_multi_queue.c
+++ b/tests/intel/xe_exec_multi_queue.c
@@ -1052,7 +1052,7 @@ int igt_main()

igt_subtest_f("sanity")
xe_for_each_gt(fd, gt)
- xe_for_each_multi_queue_engine_class(class)
+ xe_for_each_multi_queue_engine_class(fd, class)
test_sanity(fd, gt, class);

igt_subtest_f("exec-sanity")
@@ -1061,7 +1061,7 @@ int igt_main()

igt_subtest_f("virtual")
xe_for_each_gt(fd, gt)
- xe_for_each_multi_queue_engine_class(class)
+ xe_for_each_multi_queue_engine_class(fd, class)
test_exec_virtual(fd, gt, class);

igt_subtest_f("priority")
diff --git a/tests/intel/xe_exec_threads.c b/tests/intel/xe_exec_threads.c
index f082a0eda..ab9565beb 100644
--- a/tests/intel/xe_exec_threads.c
+++ b/tests/intel/xe_exec_threads.c
@@ -1141,7 +1141,7 @@ static void threads(int fd, int flags)
int gt;

xe_for_each_engine(fd, hwe) {
- if ((flags & MULTI_QUEUE) && !xe_engine_class_supports_multi_queue(hwe->engine_class))
+ if ((flags & MULTI_QUEUE) && !xe_engine_class_supports_multi_queue(fd, hwe->engine_class))
continue;
++n_engines;
}
@@ -1170,7 +1170,7 @@ static void threads(int fd, int flags)
}

xe_for_each_engine(fd, hwe) {
- if ((flags & MULTI_QUEUE) && !xe_engine_class_supports_multi_queue(hwe->engine_class))
+ if ((flags & MULTI_QUEUE) && !xe_engine_class_supports_multi_queue(fd, hwe->engine_class))
continue;
threads_data[i].mutex = &mutex;
threads_data[i].cond = &cond;
--
2.43.0