[PATCH i-g-t 2/2] tests/intel/xe_oa: Remove hardcoded time heuristics

Cavitt, Jonathan jonathan.cavitt at intel.com
Wed Dec 18 21:17:48 UTC 2024


-----Original Message-----
From: igt-dev <igt-dev-bounces at lists.freedesktop.org> On Behalf Of Sai Teja Pottumuttu
Sent: Wednesday, December 18, 2024 12:42 AM
To: igt-dev at lists.freedesktop.org
Cc: Dixit, Ashutosh <ashutosh.dixit at intel.com>; Pottumuttu, Sai Teja <sai.teja.pottumuttu at intel.com>
Subject: [PATCH i-g-t 2/2] tests/intel/xe_oa: Remove hardcoded time heuristics
> 
> Some tests in xe_oa tests have hardcoded timing heuristics. Refactor it to
> make it more robust and reliable.
> 
> Signed-off-by: Sai Teja Pottumuttu <sai.teja.pottumuttu at intel.com>
> ---
>  tests/intel/xe_oa.c | 29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/intel/xe_oa.c b/tests/intel/xe_oa.c
> index ad3526406..2cae56b47 100644
> --- a/tests/intel/xe_oa.c
> +++ b/tests/intel/xe_oa.c
> @@ -4367,6 +4367,28 @@ static void map_oa_buffer_forked_access(const struct drm_xe_engine_class_instanc
>  	munmap(vaddr, size);
>  }
>  
> +static void wait_for_20_periodic_reports(void *oa_vaddr,
> +					 const struct drm_xe_engine_class_instance *hwe)
> +{
> +	uint32_t period_us = oa_exponent_to_ns(oa_exp_1_millisec) / 1000;
> +	struct intel_xe_perf_metric_set *test_set = metric_set(hwe);
> +	uint64_t fmt = test_set->perf_oa_format;
> +	struct oa_format format = get_oa_format(fmt);
> +	uint32_t num_periodic_reports = 0;
> +	uint32_t *reports;
> +
> +	while (num_periodic_reports < 20) {
> +		usleep(100 * period_us);
> +		num_periodic_reports = 0;
> +		for (reports = (uint32_t *)oa_vaddr;
> +		     reports[0] && oa_timestamp(reports, fmt);
> +		     reports += format.size) {
> +			if (oa_report_is_periodic(reports))
> +				num_periodic_reports++;
> +		}
> +	}

It might be worthwhile to have an early escape in case num_periodic_reports
never reaches 20.  Something like:
"""
	struct timespec ts = { };

	igt_nsec_elapsed(&ts);
	while (num_periodic_reports < 20 &&
	       igt_nsec_elapsed(&ts) < 30 * NSEC_PER_SEC) {
		...
"""
Though, I guess the test itself will time out and escape if it runs for too long anyways,
and I can't think of any circumstances where we'd hit this exit case.  So I won't block
on it.
Reviewed-by: Jonathan Cavitt <jonathan.cavitt at intel.com>
-Jonathan Cavitt

> +}
> +
>  static void check_reports(void *oa_vaddr, uint32_t oa_size,
>  			  const struct drm_xe_engine_class_instance *hwe)
>  {
> @@ -4396,12 +4418,10 @@ static void check_reports_from_mapped_buffer(const struct drm_xe_engine_class_in
>  {
>  	void *vaddr;
>  	uint32_t size;
> -	uint32_t period_us = oa_exponent_to_ns(oa_exp_1_millisec) / 1000;
>  
>  	vaddr = map_oa_buffer(&size);
>  
> -	/* wait for approx 100 reports */
> -	usleep(100 * period_us);
> +	wait_for_20_periodic_reports(vaddr, hwe);
>  	check_reports(vaddr, size, hwe);
>  
>  	munmap(vaddr, size);
> @@ -4426,12 +4446,11 @@ static void closed_fd_and_unmapped_access(const struct drm_xe_engine_class_insta
>  	};
>  	void *vaddr;
>  	uint32_t size;
> -	uint32_t period_us = oa_exponent_to_ns(oa_exp_1_millisec) / 1000;
>  
>  	stream_fd = __perf_open(drm_fd, &param, false);
>  	vaddr = map_oa_buffer(&size);
>  
> -	usleep(100 * period_us);
> +	wait_for_20_periodic_reports(vaddr, hwe);
>  	check_reports(vaddr, size, hwe);
>  
>  	munmap(vaddr, size);
> -- 
> 2.34.1
> 
> 


More information about the igt-dev mailing list