Skip to contentSkip to conversation

Multi-CCS support in IGT

PATCH Superseded [email protected] 2 participants 6 messages Nov 7, 2025

Subsystems (2)

v13 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v13 cover Multi-CCS support in IGT

From: Nishit Sharma <[email protected]>

Revision 1:
Added loop_kernel_duration in available pipelines. loop_kernel_duration holds sleep duration and during sleep GPU will be workng. Patch-1/3: loop_kernel_duration addition in available pipelines in lib/intel_compute.c. igt_skip is called in pipeline which doesn't support loop_kernel shader.
Patch-2/3: Added loop-duration-2s subtest in tests/intel/xe_compute to test if GPU is executing shader when sleep is called. This is verfied using gputop in another terminal. This also tests whether the test executed successfully in >= 2seconds of duration set Patch-3/3: Added eu-busy-10s test which creates multi threads depending on num_slices available and schedules workload on all ccs instances available. This also prints engine utlization in percentage while workload is executing.

v2:
- Addressed review comments from Zbyshek on description in Patch-1.
- Added execution time check in Patch-2 regarding single iteration of scheduling and executing workload on single instance of CCS engine.

v3:
- Added missing code section in Patch-1.
- Modified LOOP_DURATIOn macro to LOOP_DURATION_2s to avoid confusion.
- Used LOOP_DURATION_2s in place of LOOP_DURATION and adjusted sleep durations.

v4:
- Test will skip if sriov is enabled and sriov_numfs > 0.
- Test will continue runing if sriov_numvfs = 0

v5:
- Incorporated review comments (Zbigniew)

v6:
- Simplified logic to capture EU busyness
- Removed header which had pmu counter and engine instance logic
- Moved pthread_data structure to xe_compute file which is used during thread creation

v7:
- collective counters are set per compute engine available in t->eci
- fixed few nits

v8:
- Incorporated review comments (Zbigniew)
- After workload execution set back ccs_mode to default value

v9:
- Moved get_gt_mask() in igt_fixture to avoid build failure

v10:
- Moved sriov enabled check in igt_fixture to skip test if sriov is enabled without initilializing or creation of threads.
- Moved check for loop_kernel support in pipeline in igt_fixture

v11:
- Moved sriov enabled check in subtests which is setting ccs_mode value
- loop_kernel support check moved in subtests which are using loop_kernel

v12:
- Added sriov enable check in subtest eu-busy-10s

v13:
- Incorporated review comments (Zbyshek)

v14:
- Incorporated review comments (Zbyshek)
- Incorporated review comments (Kamil)

v15:
- Incorporated review comments (Zbyshek)

Nishit Sharma (3):
lib/intel_compute: loop_kernel_duration in Pipeline tests/intel/xe_compute: Add loop_duration_2s subtest tests/intel/xe_compute: Add eu-busy-10s test for EU utilization
measurement

 lib/intel_compute.c      |  26 ++-
 lib/intel_compute.h      |   2 +
 tests/intel/xe_compute.c | 362 ++++++++++++++++++++++++++++++++++++++-
 tests/meson.build        |   1 +
 4 files changed, 387 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v13 1/3 lib/intel_compute: loop_kernel_duration in Pipeline

From: Nishit Sharma <[email protected]>

Incase of multi-ccs it is expected that all ccs engines will be busy. There's no existing code which keeps GPU busy for a specified duration, So we need to terminate loop kernel from CPU after the desired time has elapsed.
Introduce the loop_kernel_duration variable to control kernel execution duration in compute pipelines. Currently this is supported in xe2lg and xe3lpg pipelines.

---
 lib/intel_compute.c | 26 +++++++++++++++++++++++++-
 lib/intel_compute.h |  2 ++
 2 files changed, 27 insertions(+), 1 deletion(-)
lib/intel_compute.c +25 -1
index 147dd2916..8d632269c 100644
@@ -849,6 +849,9 @@ static void compute_exec(int fd, const unsigned char *kernel,
 	uint16_t devid = intel_get_drm_devid(fd);
 	int entries = ARRAY_SIZE(bo_dict);
 
+	if (user && (user->kernel || user->loop_kernel_duration))
+		igt_skip("Pipeline doesn't support loop_kernel\n");
+
 	bo_execenv_create(fd, &execenv, eci, user);
 
 	/* Set dynamic sizes */
@@ -1131,6 +1134,9 @@ static void xehp_compute_exec(int fd, const unsigned char *kernel,
 	uint64_t bind_output_addr = (user && user->output_addr) ? user->output_addr : ADDR_OUTPUT;
 	int entries = ARRAY_SIZE(bo_dict);
 
+	if (user && (user->kernel || user->loop_kernel_duration))
+		igt_skip("Pipeline doesn't support loop_kernel\n");
+
 	bo_execenv_create(fd, &execenv, eci, user);
 
 	/* Set dynamic sizes */
@@ -1343,6 +1349,9 @@ static void xehpc_compute_exec(int fd, const unsigned char *kernel,
 	uint64_t bind_output_addr = (user && user->output_addr) ? user->output_addr : ADDR_OUTPUT;
 	int entries = ARRAY_SIZE(bo_dict);
 
+	if (user && (user->kernel || user->loop_kernel_duration))
+		igt_skip("Pipeline doesn't support loop_kernel\n");
+
 	bo_execenv_create(fd, &execenv, eci, user);
 
 	/* Set dynamic sizes */
@@ -1731,6 +1740,9 @@ static void xelpg_compute_exec(int fd, const unsigned char *kernel,
 	uint64_t bind_output_addr = (user && user->output_addr) ? user->output_addr : ADDR_OUTPUT;
 	int entries = ARRAY_SIZE(bo_dict);
 
+	if (user && (user->kernel || user->loop_kernel_duration))
+		igt_skip("Pipeline doesn't support loop_kernel\n");
+
 	bo_execenv_create(fd, &execenv, eci, user);
 
 	/* Set dynamic sizes */
@@ -1818,6 +1830,7 @@ static void xe2lpg_compute_exec(int fd, const unsigned char *kernel,
 	uint64_t bind_input_addr = (user && user->input_addr) ? user->input_addr : ADDR_INPUT;
 	uint64_t bind_output_addr = (user && user->output_addr) ? user->output_addr : ADDR_OUTPUT;
 	int entries = ARRAY_SIZE(bo_dict);
+	int64_t timeout_one_ns = 1;
 
 	bo_execenv_create(fd, &execenv, eci, user);
 
@@ -1849,7 +1862,18 @@ static void xe2lpg_compute_exec(int fd, const unsigned char *kernel,
 				    OFFSET_KERNEL, 0, false,
 				    execenv.array_size);
 
-	bo_execenv_exec(&execenv, ADDR_BATCH);
+	if (user && user->loop_kernel_duration) {
+		bo_execenv_exec_async(&execenv, ADDR_BATCH);
+		igt_measured_usleep(user->loop_kernel_duration);
+		/* Check that the loop kernel has not completed yet */
+		igt_assert_neq(0, __xe_wait_ufence(fd, &execenv.bo_sync->sync, USER_FENCE_VALUE,
+						   execenv.exec_queue, &timeout_one_ns));
+		((int *)bo_dict[4].data)[0] = MAGIC_LOOP_STOP;
+		bo_execenv_sync(&execenv);
+		user->skip_results_check = 1;
+	} else {
+		bo_execenv_exec(&execenv, ADDR_BATCH);
+	}
 
 	if (!user || (user && !user->skip_results_check))
 		bo_check_square(input_data, output_data, execenv.array_size);
lib/intel_compute.h +2 -0
index 412791d07..54a1c7f82 100644
@@ -63,6 +63,8 @@ struct user_execenv {
 	uint64_t input_addr;
 	/** @output_addr: override default address of the output array if provided */
 	uint64_t output_addr;
+	/** @loop_kernel_duration: duration till kernel should execute in gpu **/
+	uint64_t loop_kernel_duration;
 };
 
 enum execenv_alloc_prefs {
Signature · 1 line
2.43.0
#2 lore raw

PATCH v13 2/3 tests/intel/xe_compute: Add loop_duration_2s subtest

In reply to [email protected]

From: Nishit Sharma <[email protected]>

Verify introduced loop_kernel_duration parameter in user_execenv which makes GPU busy for specified duration. Execution should remain within a 0.2 second margin of the requested duration. loop_kernel shader is not supported in xehpc, xehp, xelpg pipelines so test will skip.

---
 tests/intel/xe_compute.c | 65 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
tests/intel/xe_compute.c +65 -0
index 5e9140902..192cbf492 100644
@@ -19,6 +19,9 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 
+#define LOOP_DURATION_2s	(1000000ull * 2)
+#define DURATION_MARGIN		0.2
+
 static int gt_sysfs_open(int gt)
 {
 	int fd, gt_fd;
@@ -186,6 +189,64 @@ test_compute_kernel_with_ccs_mode(void)
 	igt_require(num_gt_with_ccs_mode > 0);
 }
 
+static double elapsed(const struct timeval *start,
+		      const struct timeval *end)
+{
+	return (end->tv_sec - start->tv_sec) + 1e-6*(end->tv_usec - start->tv_usec);
+}
+
+/**
+ * SUBTEST: loop-duration-2s
+ * Functionality: OpenCL kernel
+ * Description:
+ *	Run an openCL loop Kernel that for duration,
+ *	set in loop_kernel_duration ..
+ */
+static void
+test_compute_kernel_loop(uint64_t loop_duration)
+{
+	int fd;
+	unsigned int ip_ver;
+	const struct intel_compute_kernels *kernels;
+	struct user_execenv execenv = { 0 };
+	struct drm_xe_engine_class_instance *hwe;
+	struct timeval start, end;
+	double elapse_time, lower_bound, upper_bound;
+
+	fd = drm_open_driver(DRIVER_XE);
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/* loop_kernel_duration used as sleep to make EU busy for loop_duration */
+	execenv.loop_kernel_duration = loop_duration;
+	execenv.kernel = kernels->loop_kernel;
+	execenv.kernel_size = kernels->loop_kernel_size;
+
+	xe_for_each_engine(fd, hwe) {
+		if (hwe->engine_class != DRM_XE_ENGINE_CLASS_COMPUTE)
+			continue;
+
+		igt_info("Running loop_kernel on ccs engine %d\n", hwe->engine_instance);
+		gettimeofday(&start, NULL);
+		igt_assert_f(xe_run_intel_compute_kernel_on_engine(fd, hwe, &execenv,
+								   EXECENV_PREF_SYSTEM),
+			     "Unable to run compute kernel successfully\n");
+		gettimeofday(&end, NULL);
+		elapse_time = (double)elapsed(&start, &end);
+		lower_bound = (double)(loop_duration / 1e6 - DURATION_MARGIN);
+		upper_bound = (double)(loop_duration / 1e6 + DURATION_MARGIN);
+
+		igt_assert((lower_bound < elapse_time) && (elapse_time < upper_bound));
+	}
+	drm_close_driver(fd);
+}
+
 /**
  * SUBTEST: compute-square
  * Mega feature: WMTP
@@ -223,4 +284,8 @@ igt_main
 
 	igt_subtest("ccs-mode-compute-kernel")
 		test_compute_kernel_with_ccs_mode();
+
+	/* To test compute function stops after loop_kernel_duration */
+	igt_subtest("loop-duration-2s")
+		test_compute_kernel_loop(LOOP_DURATION_2s);
 }
Signature · 1 line
2.43.0
Reviewed-by on v13 2/3
#3 lore raw

Re: [PATCH i-g-t v13 2/3] tests/intel/xe_compute: Add loop_duration_2s subtest

Quoted 9 lines · On Fri, Nov 07, 2025 at 08:32:09AM +0000, [email protected] wrote:

From: Nishit Sharma <[email protected]>

Verify introduced loop_kernel_duration parameter in user_execenv which makes GPU busy for specified duration. Execution should remain within a 0.2 second margin of the requested duration. loop_kernel shader is not supported in xehpc, xehp, xelpg pipelines so test will skip.

I don't know why you're keeping my rb here when you're touching the code. Above should gone when you're resending this altered patch.

Quoted 62 lines
---
 tests/intel/xe_compute.c | 65 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
tests/intel/xe_compute.c +43 -0
index 5e9140902..192cbf492 100644
@@ -19,6 +19,9 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 
+#define LOOP_DURATION_2s	(1000000ull * 2)
+#define DURATION_MARGIN		0.2
+
 static int gt_sysfs_open(int gt)
 {
 	int fd, gt_fd;
@@ -186,6 +189,64 @@ test_compute_kernel_with_ccs_mode(void)
 	igt_require(num_gt_with_ccs_mode > 0);
 }
 
+static double elapsed(const struct timeval *start,
+		      const struct timeval *end)
+{
+	return (end->tv_sec - start->tv_sec) + 1e-6*(end->tv_usec - start->tv_usec);
+}
+
+/**
+ * SUBTEST: loop-duration-2s
+ * Functionality: OpenCL kernel
+ * Description:
+ *	Run an openCL loop Kernel that for duration,
+ *	set in loop_kernel_duration ..
+ */
+static void
+test_compute_kernel_loop(uint64_t loop_duration)
+{
+	int fd;
+	unsigned int ip_ver;
+	const struct intel_compute_kernels *kernels;
+	struct user_execenv execenv = { 0 };
+	struct drm_xe_engine_class_instance *hwe;
+	struct timeval start, end;
+	double elapse_time, lower_bound, upper_bound;
+
+	fd = drm_open_driver(DRIVER_XE);
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/* loop_kernel_duration used as sleep to make EU busy for loop_duration */
+	execenv.loop_kernel_duration = loop_duration;
+	execenv.kernel = kernels->loop_kernel;
+	execenv.kernel_size = kernels->loop_kernel_size;
+
+	xe_for_each_engine(fd, hwe) {

tests/intel/xe_compute.c test_compute_kernel_with_ccs_mode(void) · line 241

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+		if (hwe->engine_class != DRM_XE_ENGINE_CLASS_COMPUTE)
+			continue;
+
+		igt_info("Running loop_kernel on ccs engine %d\n", hwe->engine_instance);
+		gettimeofday(&start, NULL);
+		igt_assert_f(xe_run_intel_compute_kernel_on_engine(fd, hwe, &execenv,
+								   EXECENV_PREF_SYSTEM),
+			     "Unable to run compute kernel successfully\n");
+		gettimeofday(&end, NULL);
+		elapse_time = (double)elapsed(&start, &end);

You don't need to cast here, elapsed already returns double.

tests/intel/xe_compute.c test_compute_kernel_with_ccs_mode(void) · line 242

Quoted 1 line
tests/intel/xe_compute.c +1 -0
+		lower_bound = (double)(loop_duration / 1e6 - DURATION_MARGIN);

Using 1e6 will cause other variables will be casted to double, so writing:

lower_bound = loop_duration / 1e6 - DURATION_MARGIN;

is enough, no need to cast the whole expression.

tests/intel/xe_compute.c test_compute_kernel_with_ccs_mode(void) · line 243

Quoted 1 line
tests/intel/xe_compute.c +1 -0
+		upper_bound = (double)(loop_duration / 1e6 + DURATION_MARGIN);

Ditto.

tests/intel/xe_compute.c test_compute_kernel_with_ccs_mode(void) · line 245

Quoted 2 lines
tests/intel/xe_compute.c +2 -0
+
+		igt_assert((lower_bound < elapse_time) && (elapse_time < upper_bound));

Logical and (&&) has lower prio than < and >, so brackets are not necessary.

With above nits fixed

--
Zbigniew

Quoted 19 lines
tests/intel/xe_compute.c +8 -0
+	}
+	drm_close_driver(fd);
+}
+
 /**
  * SUBTEST: compute-square
  * Mega feature: WMTP
@@ -223,4 +284,8 @@ igt_main
 
 	igt_subtest("ccs-mode-compute-kernel")
 		test_compute_kernel_with_ccs_mode();
+
+	/* To test compute function stops after loop_kernel_duration */
+	igt_subtest("loop-duration-2s")
+		test_compute_kernel_loop(LOOP_DURATION_2s);
 }
Signature · 1 line
2.43.0
#4 lore raw

PATCH v13 3/3 tests/intel/xe_compute: Add eu-busy-10s test for EU utilization measurement

In reply to [email protected]

From: Nishit Sharma <[email protected]>

This test measures the utilization of available CCS instances based on the number of slices reported in /sys/class/drm/cardX/device/tileX/gtX/num_cslices. Compute workload is scheduled on different CCS engines. The test runs workloads for fixed duration using loop_kernel_duration. SR-IOV and CCS mode features are mutually exclusive. This change updates the test to skip execution if SR-IOV is enabled on the platform.

---
 tests/intel/xe_compute.c | 299 ++++++++++++++++++++++++++++++++++++++-
 tests/meson.build        |   1 +
 2 files changed, 296 insertions(+), 4 deletions(-)
tests/intel/xe_compute.c +295 -4
index 192cbf492..95d8ea85d 100644
@@ -19,8 +19,26 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 
+#include "igt_perf.h"
+#include "igt_sriov_device.h"
+
 #define LOOP_DURATION_2s	(1000000ull * 2)
 #define DURATION_MARGIN		0.2
+#define MIN_BUSYNESS		95.0
+
+bool sriov_enabled;
+
+struct thread_data {
+	pthread_t thread;
+	pthread_mutex_t *mutex;
+	pthread_cond_t *cond;
+	int class;
+	int fd;
+	int gt;
+	struct user_execenv *execenv;
+	struct drm_xe_engine_class_instance *eci;
+	bool *go;
+};
 
 static int gt_sysfs_open(int gt)
 {
@@ -247,6 +265,244 @@ test_compute_kernel_loop(uint64_t loop_duration)
 	drm_close_driver(fd);
 }
 
+static void
+*intel_compute_thread(void *data)
+{
+	struct thread_data *t = (struct thread_data *)data;
+	char device[30];
+	uint64_t type;
+	uint32_t engine_class, engine_instance, gt_shift;
+	uint64_t engine_active_config, engine_total_config;
+	int ret, fd1, fd2;
+	uint64_t val[4];
+	uint64_t param_config;
+
+	pthread_mutex_lock(t->mutex);
+	while (*t->go == 0)
+		pthread_cond_wait(t->cond, t->mutex);
+	pthread_mutex_unlock(t->mutex);
+
+	type = igt_perf_type_id(xe_perf_device(t->fd, device, sizeof(device)));
+	igt_debug("type: %lx, device: %s\n", type, device);
+
+	perf_event_format(device, "gt", &gt_shift);
+	perf_event_format(device, "engine_class", &engine_class);
+	perf_event_format(device, "engine_instance", &engine_instance);
+
+	ret = perf_event_config(device, "engine-active-ticks", &engine_active_config);
+	igt_assert_eq(ret, 0);
+	ret = perf_event_config(device, "engine-total-ticks", &engine_total_config);
+	igt_assert_eq(ret, 0);
+
+	igt_debug("gt_id: %x, class: %x, instance: %x\n",
+		  t->eci->gt_id, t->eci->engine_class, t->eci->engine_instance);
+
+	/* Setting collective counters for compute engine available in t->eci */
+	param_config = (uint64_t)t->eci->gt_id << gt_shift |
+		       t->eci->engine_class << engine_class |
+		       t->eci->engine_instance << engine_instance;
+
+	fd1 = igt_perf_open_group(type, engine_active_config | param_config, -1);
+	fd2 = igt_perf_open_group(type, engine_total_config | param_config, fd1);
+
+	ret = read(fd1, val, sizeof(val));
+	igt_assert_eq(ret, sizeof(val));
+	igt_info("start - active: %ld, total: %ld, busyness: %.1f before scheduling on engine_instance :%d\n",
+		 val[2], val[3], (float)val[2] / (float)val[3] * 100.0, t->eci->engine_instance);
+
+	igt_assert_f(xe_run_intel_compute_kernel_on_engine(t->fd, t->eci, t->execenv,
+							   EXECENV_PREF_VRAM_IF_POSSIBLE),
+		     "Unable to run compute kernel successfully\n");
+
+	ret = read(fd1, val, sizeof(val));
+	igt_assert_eq(ret, sizeof(val));
+	igt_info("end - active: %ld, total: %ld, busyness: %.1f after scheduling on engine_instance :%d\n",
+		 val[2], val[3], (float)val[2] / (float)val[3] * 100.0, t->eci->engine_instance);
+
+	igt_assert_f(((float)val[2] / (float)val[3] * 100.0) > MIN_BUSYNESS,
+		     "Engines are under utilizated\n");
+
+	close(fd1);
+	close(fd2);
+	return NULL;
+}
+
+static void
+igt_check_supported_pipeline(void)
+{
+	int fd;
+	unsigned int ip_ver;
+	const struct intel_compute_kernels *kernels;
+
+	fd = drm_open_driver(DRIVER_XE);
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+	drm_close_driver(fd);
+
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/* skip if loop_kernel is not supported by pipeline */
+	if (!kernels->kernel || !kernels->loop_kernel)
+		igt_skip("loop_kernel not supported by pipeline\n");
+}
+
+static bool is_sriov_mode(int fd)
+{
+	bool is_sriov = false;
+
+	if (igt_sriov_is_pf(fd) && igt_sriov_vfs_supported(fd))
+		is_sriov = true;
+
+	return is_sriov;
+}
+
+static void
+igt_store_ccs_mode(int ccs_mode[], int size)
+{
+	int gt_fd, gt;
+	u32 num_slices;
+	uint64_t gt_mask;
+
+	gt_mask = get_gt_mask();
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_sysfs_scanf(gt_fd, "ccs_mode", "%u", &ccs_mode[gt]);
+		close(gt_fd);
+	}
+}
+
+static void
+igt_restore_ccs_mode(int ccs_mode[], int size)
+{
+	uint64_t gt_mask = get_gt_mask();
+	u32 gt, num_slices;
+	int gt_fd;
+
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_assert(igt_sysfs_printf(gt_fd, "ccs_mode", "%u", ccs_mode[gt]) > 0);
+		close(gt_fd);
+	}
+}
+
+/**
+ * SUBTEST: eu-busy-10s
+ * Functionality: OpenCL kernel
+ * Description: Run loop_kernel for duration_sec and observe EU business
+ */
+static void
+test_eu_busy(uint64_t duration_sec)
+{
+	struct user_execenv execenv = { 0 };
+	struct thread_data *threads_data;
+	struct drm_xe_engine_class_instance *hwe;
+	const struct intel_compute_kernels *kernels;
+	pthread_mutex_t mutex;
+	pthread_cond_t cond;
+	u32 gt, n_threads = 0, iterations = 0, n_instances = 0, i;
+	bool go = false;
+	int ccs_mode, gt_fd, fd;
+	u32 num_slices, ip_ver;
+	uint64_t gt_mask = get_gt_mask();
+
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_assert(igt_sysfs_printf(gt_fd, "ccs_mode", "%u", num_slices) > 0);
+		igt_assert(igt_sysfs_scanf(gt_fd, "ccs_mode", "%u", &ccs_mode) > 0);
+		close(gt_fd);
+	}
+
+	igt_skip_on_f(ccs_mode <= 1, "Skipping test as ccs_mode <=1 not matching criteria :%d\n",
+		      ccs_mode);
+
+	fd = drm_open_driver(DRIVER_XE);
+
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/*
+	 * User should use different kernel if loop_kernel_duration not set
+	 * With loop kernel and loop duration it assumes we stop it via memory write
+	 *
+	 */
+
+	execenv.loop_kernel_duration = duration_sec;
+	execenv.kernel = kernels->loop_kernel;
+	execenv.kernel_size = kernels->loop_kernel_size;
+	drm_close_driver(fd);
+
+	gt_mask = get_gt_mask();
+
+	for_each_bit(gt_mask, gt) {
+		fd = drm_open_driver(DRIVER_XE);
+		xe_for_each_engine(fd, hwe) {
+			igt_assert(hwe);
+			if (hwe->engine_class == DRM_XE_ENGINE_CLASS_COMPUTE)
+				++n_instances;
+		}
+		drm_close_driver(fd);
+	}
+
+	threads_data = calloc(n_instances, sizeof(*threads_data));
+	igt_assert(threads_data);
+
+	pthread_mutex_init(&mutex, 0);
+	pthread_cond_init(&cond, 0);
+
+	gt_mask = get_gt_mask();
+	fd = drm_open_driver(DRIVER_XE);
+	for_each_bit(gt_mask, gt) {
+		xe_for_each_engine(fd, hwe) {
+			if (hwe->gt_id != gt ||
+			    hwe->engine_class != DRM_XE_ENGINE_CLASS_COMPUTE)
+				continue;
+
+			threads_data[i].mutex = &mutex;
+			threads_data[i].cond = &cond;
+			threads_data[i].fd = fd;
+			threads_data[i].eci = hwe;
+			threads_data[i].go = &go;
+			threads_data[i].execenv = &execenv;
+			++n_threads;
+			pthread_create(&threads_data[i].thread, 0, intel_compute_thread,
+				       &threads_data[i]);
+			++i;
+			++iterations;
+		}
+		pthread_mutex_lock(&mutex);
+		go = true;
+		pthread_cond_broadcast(&cond);
+		pthread_mutex_unlock(&mutex);
+
+		for (int val = 0; val < i; ++val)
+			pthread_join(threads_data[val].thread, NULL);
+
+		i = 0;
+		n_threads = 0;
+		iterations = 0;
+	}
+	free(threads_data);
+	drm_close_driver(fd);
+}
+
 /**
  * SUBTEST: compute-square
  * Mega feature: WMTP
@@ -266,10 +522,14 @@ test_compute_square(int fd)
 
 igt_main
 {
-	int xe;
+	int xe, ccs_mode[4];
+	unsigned int ip_ver;
 
 	igt_fixture {
 		xe = drm_open_driver(DRIVER_XE);
+		sriov_enabled = is_sriov_mode(xe);
+		ip_ver = intel_graphics_ver(intel_get_drm_devid(xe));
+		igt_store_ccs_mode(ccs_mode, sizeof(ccs_mode));
 	}
 
 	igt_subtest("compute-square")
@@ -279,13 +539,44 @@ igt_main
 		drm_close_driver(xe);
 
 	/* ccs mode tests should be run without open gpu file handles */
-	igt_subtest("ccs-mode-basic")
+	igt_subtest("ccs-mode-basic") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
 		test_ccs_mode();
+	}
 
-	igt_subtest("ccs-mode-compute-kernel")
+	igt_subtest("ccs-mode-compute-kernel") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
 		test_compute_kernel_with_ccs_mode();
+	}
 
 	/* To test compute function stops after loop_kernel_duration */
-	igt_subtest("loop-duration-2s")
+	igt_subtest("loop-duration-2s") {
+		/* skip test if loop_kernel not supported in pipeline */
+		if (ip_ver < IP_VER(20, 0))
+			igt_check_supported_pipeline();
+
 		test_compute_kernel_loop(LOOP_DURATION_2s);
+	}
+
+	/* test to check available EU utilisation in multi-ccs case */
+	igt_subtest("eu-busy-10s") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
+
+		/* skip test if loop_kernel not supported in pipeline */
+		if (ip_ver < IP_VER(20, 0))
+			igt_check_supported_pipeline();
+
+		test_eu_busy(5 * LOOP_DURATION_2s);
+	}
+
+	igt_fixture {
+		if (!sriov_enabled)
+			igt_restore_ccs_mode(ccs_mode, sizeof(ccs_mode));
+	}
 }
tests/meson.build +1 -0
index a7b9375ed..a7ffc6383 100644
@@ -408,6 +408,7 @@ extra_dependencies = {
 	'sw_sync': [ libatomic ],
 	'xe_fault_injection': [ lib_igt_xe_oa ],
 	'xe_oa': [ lib_igt_xe_oa ],
+        'xe_compute': [ igt_deps,lib_igt_perf,lib_igt_profiling,math ],
 }
 
 test_executables = []
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH i-g-t v13 3/3] tests/intel/xe_compute: Add eu-busy-10s test for EU utilization measurement

Quoted 138 lines · On Fri, Nov 07, 2025 at 08:32:10AM +0000, [email protected] wrote:

From: Nishit Sharma <[email protected]>

This test measures the utilization of available CCS instances based on the number of slices reported in /sys/class/drm/cardX/device/tileX/gtX/num_cslices. Compute workload is scheduled on different CCS engines. The test runs workloads for fixed duration using loop_kernel_duration. SR-IOV and CCS mode features are mutually exclusive. This change updates the test to skip execution if SR-IOV is enabled on the platform.

---
 tests/intel/xe_compute.c | 299 ++++++++++++++++++++++++++++++++++++++-
 tests/meson.build        |   1 +
 2 files changed, 296 insertions(+), 4 deletions(-)
tests/intel/xe_compute.c +105 -0
index 192cbf492..95d8ea85d 100644
@@ -19,8 +19,26 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 
+#include "igt_perf.h"
+#include "igt_sriov_device.h"
+
 #define LOOP_DURATION_2s	(1000000ull * 2)
 #define DURATION_MARGIN		0.2
+#define MIN_BUSYNESS		95.0
+
+bool sriov_enabled;
+
+struct thread_data {
+	pthread_t thread;
+	pthread_mutex_t *mutex;
+	pthread_cond_t *cond;
+	int class;
+	int fd;
+	int gt;
+	struct user_execenv *execenv;
+	struct drm_xe_engine_class_instance *eci;
+	bool *go;
+};
 
 static int gt_sysfs_open(int gt)
 {
@@ -247,6 +265,244 @@ test_compute_kernel_loop(uint64_t loop_duration)
 	drm_close_driver(fd);
 }
 
+static void
+*intel_compute_thread(void *data)
+{
+	struct thread_data *t = (struct thread_data *)data;
+	char device[30];
+	uint64_t type;
+	uint32_t engine_class, engine_instance, gt_shift;
+	uint64_t engine_active_config, engine_total_config;
+	int ret, fd1, fd2;
+	uint64_t val[4];
+	uint64_t param_config;
+
+	pthread_mutex_lock(t->mutex);
+	while (*t->go == 0)
+		pthread_cond_wait(t->cond, t->mutex);
+	pthread_mutex_unlock(t->mutex);
+
+	type = igt_perf_type_id(xe_perf_device(t->fd, device, sizeof(device)));
+	igt_debug("type: %lx, device: %s\n", type, device);
+
+	perf_event_format(device, "gt", &gt_shift);
+	perf_event_format(device, "engine_class", &engine_class);
+	perf_event_format(device, "engine_instance", &engine_instance);
+
+	ret = perf_event_config(device, "engine-active-ticks", &engine_active_config);
+	igt_assert_eq(ret, 0);
+	ret = perf_event_config(device, "engine-total-ticks", &engine_total_config);
+	igt_assert_eq(ret, 0);
+
+	igt_debug("gt_id: %x, class: %x, instance: %x\n",
+		  t->eci->gt_id, t->eci->engine_class, t->eci->engine_instance);
+
+	/* Setting collective counters for compute engine available in t->eci */
+	param_config = (uint64_t)t->eci->gt_id << gt_shift |
+		       t->eci->engine_class << engine_class |
+		       t->eci->engine_instance << engine_instance;
+
+	fd1 = igt_perf_open_group(type, engine_active_config | param_config, -1);
+	fd2 = igt_perf_open_group(type, engine_total_config | param_config, fd1);
+
+	ret = read(fd1, val, sizeof(val));
+	igt_assert_eq(ret, sizeof(val));
+	igt_info("start - active: %ld, total: %ld, busyness: %.1f before scheduling on engine_instance :%d\n",
+		 val[2], val[3], (float)val[2] / (float)val[3] * 100.0, t->eci->engine_instance);
+
+	igt_assert_f(xe_run_intel_compute_kernel_on_engine(t->fd, t->eci, t->execenv,
+							   EXECENV_PREF_VRAM_IF_POSSIBLE),
+		     "Unable to run compute kernel successfully\n");
+
+	ret = read(fd1, val, sizeof(val));
+	igt_assert_eq(ret, sizeof(val));
+	igt_info("end - active: %ld, total: %ld, busyness: %.1f after scheduling on engine_instance :%d\n",
+		 val[2], val[3], (float)val[2] / (float)val[3] * 100.0, t->eci->engine_instance);
+
+	igt_assert_f(((float)val[2] / (float)val[3] * 100.0) > MIN_BUSYNESS,
+		     "Engines are under utilizated\n");
+
+	close(fd1);
+	close(fd2);
+	return NULL;
+}
+
+static void
+igt_check_supported_pipeline(void)
+{
+	int fd;
+	unsigned int ip_ver;
+	const struct intel_compute_kernels *kernels;
+
+	fd = drm_open_driver(DRIVER_XE);
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+	drm_close_driver(fd);
+
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/* skip if loop_kernel is not supported by pipeline */
+	if (!kernels->kernel || !kernels->loop_kernel)
+		igt_skip("loop_kernel not supported by pipeline\n");
+}
+
+static bool is_sriov_mode(int fd)
+{

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 364

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+	bool is_sriov = false;
+
+	if (igt_sriov_is_pf(fd) && igt_sriov_vfs_supported(fd))
+		is_sriov = true;
+
+	return is_sriov;
+}
+
+static void
+igt_store_ccs_mode(int ccs_mode[], int size)

Currently size is not used, but I guess you planned to check array bounds?

Quoted 8 lines
tests/intel/xe_compute.c +8 -0
+{
+	int gt_fd, gt;
+	u32 num_slices;
+	uint64_t gt_mask;
+
+	gt_mask = get_gt_mask();
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 382

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_sysfs_scanf(gt_fd, "ccs_mode", "%u", &ccs_mode[gt]);
+		close(gt_fd);
+	}
+}
+
+static void
+igt_restore_ccs_mode(int ccs_mode[], int size)

Same here.

Quoted 60 lines
tests/intel/xe_compute.c +60 -0
+{
+	uint64_t gt_mask = get_gt_mask();
+	u32 gt, num_slices;
+	int gt_fd;
+
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_assert(igt_sysfs_printf(gt_fd, "ccs_mode", "%u", ccs_mode[gt]) > 0);
+		close(gt_fd);
+	}
+}
+
+/**
+ * SUBTEST: eu-busy-10s
+ * Functionality: OpenCL kernel
+ * Description: Run loop_kernel for duration_sec and observe EU business
+ */
+static void
+test_eu_busy(uint64_t duration_sec)
+{
+	struct user_execenv execenv = { 0 };
+	struct thread_data *threads_data;
+	struct drm_xe_engine_class_instance *hwe;
+	const struct intel_compute_kernels *kernels;
+	pthread_mutex_t mutex;
+	pthread_cond_t cond;
+	u32 gt, n_threads = 0, iterations = 0, n_instances = 0, i;
+	bool go = false;
+	int ccs_mode, gt_fd, fd;
+	u32 num_slices, ip_ver;
+	uint64_t gt_mask = get_gt_mask();
+
+	for_each_bit(gt_mask, gt) {
+		if (!get_num_cslices(gt, &num_slices))
+			continue;
+
+		gt_fd = gt_sysfs_open(gt);
+		igt_assert(igt_sysfs_printf(gt_fd, "ccs_mode", "%u", num_slices) > 0);
+		igt_assert(igt_sysfs_scanf(gt_fd, "ccs_mode", "%u", &ccs_mode) > 0);
+		close(gt_fd);
+	}
+
+	igt_skip_on_f(ccs_mode <= 1, "Skipping test as ccs_mode <=1 not matching criteria :%d\n",
+		      ccs_mode);
+
+	fd = drm_open_driver(DRIVER_XE);
+
+	ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
+	kernels = intel_compute_square_kernels;
+	while (kernels->kernel) {
+		if (ip_ver == kernels->ip_ver)
+			break;
+		kernels++;
+	}
+
+	/*
+	 * User should use different kernel if loop_kernel_duration not set

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 452

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+	 * With loop kernel and loop duration it assumes we stop it via memory write
+	 *
+	 */
+
+	execenv.loop_kernel_duration = duration_sec;
+	execenv.kernel = kernels->loop_kernel;
+	execenv.kernel_size = kernels->loop_kernel_size;
+	drm_close_driver(fd);
+
+	gt_mask = get_gt_mask();

You don't need to reopen the device over and over again.

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 462

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+
+	for_each_bit(gt_mask, gt) {
+		fd = drm_open_driver(DRIVER_XE);
+		xe_for_each_engine(fd, hwe) {
+			igt_assert(hwe);
+			if (hwe->engine_class == DRM_XE_ENGINE_CLASS_COMPUTE)
+				++n_instances;
+		}
+		drm_close_driver(fd);
+	}

There's no need to iterate over gt_mask here.

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 472

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+
+	threads_data = calloc(n_instances, sizeof(*threads_data));
+	igt_assert(threads_data);
+
+	pthread_mutex_init(&mutex, 0);
+	pthread_cond_init(&cond, 0);
+
+	gt_mask = get_gt_mask();
+	fd = drm_open_driver(DRIVER_XE);
+	for_each_bit(gt_mask, gt) {

And here.

Quoted 18 lines
tests/intel/xe_compute.c +18 -0
+		xe_for_each_engine(fd, hwe) {
+			if (hwe->gt_id != gt ||
+			    hwe->engine_class != DRM_XE_ENGINE_CLASS_COMPUTE)
+				continue;
+
+			threads_data[i].mutex = &mutex;
+			threads_data[i].cond = &cond;
+			threads_data[i].fd = fd;
+			threads_data[i].eci = hwe;
+			threads_data[i].go = &go;
+			threads_data[i].execenv = &execenv;
+			++n_threads;
+			pthread_create(&threads_data[i].thread, 0, intel_compute_thread,
+				       &threads_data[i]);
+			++i;
+			++iterations;
+		}
+		pthread_mutex_lock(&mutex);

tests/intel/xe_compute.c test_compute_kernel_loop(uint64_t loop_duration) · line 500

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+		go = true;
+		pthread_cond_broadcast(&cond);
+		pthread_mutex_unlock(&mutex);
+
+		for (int val = 0; val < i; ++val)
+			pthread_join(threads_data[val].thread, NULL);
+
+		i = 0;
+		n_threads = 0;
+		iterations = 0;

n_threads and iterations may be removed, just initialize i to = before xe_for_each_engine().

Quoted 11 lines
tests/intel/xe_compute.c +5 -0
+	}
+	free(threads_data);
+	drm_close_driver(fd);
+}
+
 /**
  * SUBTEST: compute-square
  * Mega feature: WMTP
@@ -266,10 +522,14 @@ test_compute_square(int fd)
 
 igt_main

tests/intel/xe_compute.c test_compute_square(int fd) · line 532

Quoted 10 lines
tests/intel/xe_compute.c +5 -1
 {
-	int xe;
+	int xe, ccs_mode[4];
+	unsigned int ip_ver;
 
 	igt_fixture {
 		xe = drm_open_driver(DRIVER_XE);
+		sriov_enabled = is_sriov_mode(xe);
+		ip_ver = intel_graphics_ver(intel_get_drm_devid(xe));
+		igt_store_ccs_mode(ccs_mode, sizeof(ccs_mode));

This is invalid. sizeof(ccs_mode) will return you 16, not 4 as you expect. Use ARRAY_SIZE().

Quoted 39 lines
tests/intel/xe_compute.c +23 -3
 	}
 
 	igt_subtest("compute-square")
@@ -279,13 +539,44 @@ igt_main
 		drm_close_driver(xe);
 
 	/* ccs mode tests should be run without open gpu file handles */
-	igt_subtest("ccs-mode-basic")
+	igt_subtest("ccs-mode-basic") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
 		test_ccs_mode();
+	}
 
-	igt_subtest("ccs-mode-compute-kernel")
+	igt_subtest("ccs-mode-compute-kernel") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
 		test_compute_kernel_with_ccs_mode();
+	}
 
 	/* To test compute function stops after loop_kernel_duration */
-	igt_subtest("loop-duration-2s")
+	igt_subtest("loop-duration-2s") {
+		/* skip test if loop_kernel not supported in pipeline */
+		if (ip_ver < IP_VER(20, 0))
+			igt_check_supported_pipeline();
+
 		test_compute_kernel_loop(LOOP_DURATION_2s);
+	}
+
+	/* test to check available EU utilisation in multi-ccs case */
+	igt_subtest("eu-busy-10s") {
+		/* skip if sriov enabled */
+		if (sriov_enabled)
+			igt_skip("Skipping test when SRIOV is enabled\n");
+

tests/intel/xe_compute.c igt_main · line 580

Quoted 10 lines
tests/intel/xe_compute.c +10 -0
+		/* skip test if loop_kernel not supported in pipeline */
+		if (ip_ver < IP_VER(20, 0))
+			igt_check_supported_pipeline();
+
+		test_eu_busy(5 * LOOP_DURATION_2s);
+	}
+
+	igt_fixture {
+		if (!sriov_enabled)
+			igt_restore_ccs_mode(ccs_mode, sizeof(ccs_mode));

Ditto.

--
Zbigniew

Quoted 17 lines
tests/intel/xe_compute.c +1 -0
+	}
 }
tests/meson.build +1 -0
index a7b9375ed..a7ffc6383 100644
@@ -408,6 +408,7 @@ extra_dependencies = {
 	'sw_sync': [ libatomic ],
 	'xe_fault_injection': [ lib_igt_xe_oa ],
 	'xe_oa': [ lib_igt_xe_oa ],
+        'xe_compute': [ igt_deps,lib_igt_perf,lib_igt_profiling,math ],
 }
 
 test_executables = []
Signature · 1 line
2.43.0