[PATCH i-g-t 1/2] lib/xe/xe_util: introduce helper for enabling ccs mode

Manszewski, Christoph christoph.manszewski at intel.com
Fri Jan 17 13:07:48 UTC 2025


Hi Dominik,

On 16.12.2024 14:11, Dominik Grzegorzek wrote:
> From: Andrzej Hajda <andrzej.hajda at intel.com>
> 
> Multiple tests will require enabled ccs mode. Add special helper to
> avoid code duplication.
> 
> Signed-off-by: Andrzej Hajda <andrzej.hajda at intel.com>
> ---
>   lib/xe/xe_util.c | 31 +++++++++++++++++++++++++++++++
>   lib/xe/xe_util.h |  1 +
>   2 files changed, 32 insertions(+)
> 
> diff --git a/lib/xe/xe_util.c b/lib/xe/xe_util.c
> index 9482819c2..f7ae19f08 100644
> --- a/lib/xe/xe_util.c
> +++ b/lib/xe/xe_util.c
> @@ -302,3 +302,34 @@ int xe_gt_count_engines_by_class(int fd, int gt, int class)
>   
>   	return n;
>   }
> +
> +/**
> + * xe_sysfs_enable_ccs_mode:
> + * @fd: pointer to xe drm fd, can reopened multiple times
> + *
> + * Enables ccs_mode on all GTs, it must succeed for at least one GT.
> + * Since function requires the driver to be closed during ccs_mode change
> + * @fd will be closed then re-opened.
> + */
> +void xe_sysfs_enable_ccs_mode(int *fd)
> +{
> +	int gt, gt_fd, num_slices, ccs_mode, num_gt, enabled_count = 0;
> +
> +	num_gt = xe_number_gt(*fd);
> +
> +	for (gt = 0; gt < num_gt; gt++) {
> +		gt_fd = xe_sysfs_gt_open(*fd, gt);
> +		drm_close_driver(*fd);

Why not outside the loop?

Thanks,
Christoph

> +
> +		if (!igt_debug_on(igt_sysfs_scanf(gt_fd, "num_cslices", "%u", &num_slices) <= 0) &&
> +		    !igt_debug_on(igt_sysfs_printf(gt_fd, "ccs_mode", "%u", num_slices) <= 0) &&
> +		    !igt_debug_on(igt_sysfs_scanf(gt_fd, "ccs_mode", "%u", &ccs_mode) <= 0) &&
> +		    !igt_debug_on(num_slices != ccs_mode))
> +			enabled_count++;
> +		close(gt_fd);
> +		*fd = drm_open_driver(DRIVER_XE);
> +	}
> +
> +	if (!enabled_count)
> +		igt_require_f(0, "Cannot enable ccs mode for any GT\n");
> +}
> diff --git a/lib/xe/xe_util.h b/lib/xe/xe_util.h
> index b9fbfc5cd..a82c44a2a 100644
> --- a/lib/xe/xe_util.h
> +++ b/lib/xe/xe_util.h
> @@ -53,5 +53,6 @@ int xe_gt_fill_engines_by_class(int fd, int gt, int class,
>   				struct drm_xe_engine_class_instance eci[static XE_MAX_ENGINE_INSTANCE]);
>   int xe_gt_count_engines_by_class(int fd, int gt, int class);
>   
> +void xe_sysfs_enable_ccs_mode(int *fd);
>   
>   #endif /* XE_UTIL_H */


More information about the igt-dev mailing list