[PATCH i-g-t 2/3] tests/intel/xe_compute: Added loop_duration_2s subtest
nishit.sharma at intel.com
nishit.sharma at intel.com
Mon Aug 18 07:54:45 UTC 2025
From: Nishit Sharma <nishit.sharma at intel.com>
Added loop_duration_2s subtest which fills kernel and loop_kernel_duration
members of structure user_execenv and passed as member in
xe_run_intel_compute_kernel_on_engine() to schedule Job on CCS engine.
This also verifies GPU is executing loop_kernel shader when sleep for
loop_kernel_duration is called. loop_kernel shader is available on
xe2lpg and xe3lpg pipeline. Verified GPU is working during sleep using
gputop. Test will skip for xehpc, xehp, xelpg pipeline as they don't have
loop_kernel shader. This checks whether the test executed successfully
in elapsed_duration >= loop_kernel_duration + 0.2 seconds or failed in
duration - 0.2 < elapsed_duration. elapsed_duration is time taken on
scheduling and execution of workload in single iteration on single
single instance of CCS.
Signed-off-by: Nishit Sharma <nishit.sharma at intel.com>
---
lib/intel_compute.c | 6 +++-
tests/intel/xe_compute.c | 59 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/lib/intel_compute.c b/lib/intel_compute.c
index 125331c53..51caacfa6 100644
--- a/lib/intel_compute.c
+++ b/lib/intel_compute.c
@@ -1830,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);
@@ -1861,11 +1862,14 @@ static void xe2lpg_compute_exec(int fd, const unsigned char *kernel,
OFFSET_KERNEL, 0, false,
execenv.array_size);
+ /* To make GPU run Kernel for specific duration, loo_kernel_duration added */
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);
diff --git a/tests/intel/xe_compute.c b/tests/intel/xe_compute.c
index 5e9140902..eec5fe37f 100644
--- a/tests/intel/xe_compute.c
+++ b/tests/intel/xe_compute.c
@@ -19,6 +19,8 @@
#include "xe/xe_ioctl.h"
#include "xe/xe_query.h"
+#define LOOP_DURATION (1000000ull)
+
static int gt_sysfs_open(int gt)
{
int fd, gt_fd;
@@ -186,6 +188,59 @@ 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;
+
+ 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);
+ igt_assert((double)(loop_duration/LOOP_DURATION - 0.2) < elapsed(&start, &end) &&
+ (double)(loop_duration/LOOP_DURATION + 0.2));
+ }
+ drm_close_driver(fd);
+}
+
/**
* SUBTEST: compute-square
* Mega feature: WMTP
@@ -223,4 +278,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(2 * LOOP_DURATION);
}
--
2.43.0
More information about the igt-dev
mailing list