Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Shuicheng Lin <shuicheng.lin@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Shuicheng Lin" <shuicheng.lin@intel.com>,
	"Nishit Sharma" <nishit.sharma@intel.com>,
	"Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Subject: [PATCH i-g-t] tests/intel/xe_compute: Use monotonic clock in loop-duration-2s
Date: Wed, 18 Nov 2026 17:08:58 -0800	[thread overview]
Message-ID: <20261119010857.377785-2-shuicheng.lin@intel.com> (raw)

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


             reply	other threads:[~2026-11-19  1:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  1:08 Shuicheng Lin [this message]
2026-11-19  3:26 ` [PATCH i-g-t] tests/intel/xe_compute: Use monotonic clock in loop-duration-2s 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

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=20261119010857.377785-2-shuicheng.lin@intel.com \
    --to=shuicheng.lin@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=nishit.sharma@intel.com \
    --cc=zbigniew.kempczynski@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