Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Sharma, Nishit" <nishit.sharma@intel.com>
To: Shuicheng Lin <shuicheng.lin@intel.com>, <igt-dev@lists.freedesktop.org>
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Subject: Re: [PATCH i-g-t] tests/intel/xe_compute: Use monotonic clock in loop-duration-2s
Date: Thu, 19 Nov 2026 08:56:25 +0530	[thread overview]
Message-ID: <bdae5fbd-eb7c-4d18-96f2-2bd53aed2e4a@intel.com> (raw)
In-Reply-To: <20261119010857.377785-2-shuicheng.lin@intel.com>


On 11/19/2026 6:38 AM, Shuicheng Lin wrote:
> 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);
>   }


LGTM:

Reviewed-by: Nishit Sharma <nishit.sharma@intel.com>


  reply	other threads:[~2026-11-19  3:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=bdae5fbd-eb7c-4d18-96f2-2bd53aed2e4a@intel.com \
    --to=nishit.sharma@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=shuicheng.lin@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