Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] tests/intel/xe_compute: Use monotonic clock in loop-duration-2s
@ 2026-11-19  1:08 Shuicheng Lin
  2026-11-19  3:26 ` Sharma, Nishit
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Shuicheng Lin @ 2026-11-19  1:08 UTC (permalink / raw)
  To: igt-dev; +Cc: Shuicheng Lin, Nishit Sharma, Zbigniew Kempczyński

The subtest times the loop kernel with gettimeofday(), which follows
CLOCK_REALTIME. If the system time is stepped (e.g. by NTP) during the
run, the measured time falls outside (1.8s, 2.2s) and the test fails,
even though the kernel ran for about 2s.

Use igt_nsec_elapsed(), which is monotonic, and print the measured
time and bounds on failure.

Reproduced on PTL by stepping the clock with date -s during the test:
the old code fails every time, the fixed code passes.

Closes: https://gitlab.freedesktop.org/drm/xe/kernel/issues/9795
Cc: Nishit Sharma <nishit.sharma@intel.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
---
 tests/intel/xe_compute.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/tests/intel/xe_compute.c b/tests/intel/xe_compute.c
index e738c9dab..ee376fd88 100644
--- a/tests/intel/xe_compute.c
+++ b/tests/intel/xe_compute.c
@@ -207,12 +207,6 @@ 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
@@ -228,7 +222,6 @@ test_compute_kernel_loop(uint64_t loop_duration)
 	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);
@@ -247,20 +240,23 @@ test_compute_kernel_loop(uint64_t loop_duration)
 	execenv.kernel_size = kernels->loop_kernel_size;
 
 	xe_for_each_engine(fd, hwe) {
+		struct timespec start = {};
+
 		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_nsec_elapsed(&start);
 		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 = elapsed(&start, &end);
+		elapse_time = igt_nsec_elapsed(&start) / 1e9;
 		lower_bound = loop_duration / 1e6 - DURATION_MARGIN;
 		upper_bound = loop_duration / 1e6 + DURATION_MARGIN;
 
-		igt_assert(lower_bound < elapse_time && elapse_time < upper_bound);
+		igt_assert_f(lower_bound < elapse_time && elapse_time < upper_bound,
+			     "Elapsed time %.3fs out of range (%.3fs, %.3fs)\n",
+			     elapse_time, lower_bound, upper_bound);
 	}
 	drm_close_driver(fd);
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-20 12:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  1:08 [PATCH i-g-t] tests/intel/xe_compute: Use monotonic clock in loop-duration-2s Shuicheng Lin
2026-11-19  3:26 ` Sharma, Nishit
2026-11-19  8:46 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-11-19 13:12 ` ✓ i915.CI.BAT: " Patchwork
2026-11-19 19:49 ` ✓ i915.CI.Full: " Patchwork
2026-11-20 12:35 ` ✗ Xe.CI.FULL: failure " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox