[PATCH i-g-t 2/4] lib: Export xe_engine_class_to_str function

Manszewski, Christoph christoph.manszewski at intel.com
Thu Dec 12 16:36:51 UTC 2024


Hi Dominik,

On 11.12.2024 12:40, Dominik Grzegorzek wrote:
> Define xe_engine_class_to_str as library function in xe_query.h and change its name to
> xe_engine_class_short_string so it matches already defined xe_engine_class_string.
> Replace all uses of xe_engine_class_to_str within igt_sysfs.c.
> 
> Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>

Reviewed-by: Christoph Manszewski <christoph.manszewski at intel.com>

Thanks,
Christoph

> ---
>   lib/igt_sysfs.c   | 30 ++++++++----------------------
>   lib/xe/xe_query.c | 25 +++++++++++++++++++++++++
>   lib/xe/xe_query.h |  1 +
>   3 files changed, 34 insertions(+), 22 deletions(-)
> 
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index eaf8fd882..2e4c2ee63 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -48,6 +48,7 @@
>   #include "igt_device.h"
>   #include "igt_io.h"
>   #include "intel_chipset.h"
> +#include "xe/xe_query.h"
>   
>   /**
>    * SECTION:igt_sysfs
> @@ -291,22 +292,6 @@ bool xe_sysfs_gt_has_node(int xe_device, int gt, const char *node)
>   	return has_node;
>   }
>   
> -static const char *xe_engine_class_to_str(__u16 class)
> -{
> -	static const char * const str[] = {
> -		[DRM_XE_ENGINE_CLASS_RENDER] = "rcs",
> -		[DRM_XE_ENGINE_CLASS_COPY] = "bcs",
> -		[DRM_XE_ENGINE_CLASS_VIDEO_DECODE] = "vcs",
> -		[DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
> -		[DRM_XE_ENGINE_CLASS_COMPUTE] = "ccs",
> -	};
> -
> -	if (class < ARRAY_SIZE(str))
> -		return str[class];
> -
> -	return "unk";
> -}
> -
>   /**
>    * xe_sysfs_engine_path:
>    * @xe_device: fd of the device
> @@ -331,7 +316,8 @@ xe_sysfs_engine_path(int xe_device, int gt, int class, char *path, int pathlen)
>   		return NULL;
>   
>   	snprintf(path, pathlen, "/sys/dev/char/%d:%d/device/tile%d/gt%d/engines/%s",
> -		 major(st.st_rdev), minor(st.st_rdev), tile, gt, xe_engine_class_to_str(class));
> +		 major(st.st_rdev), minor(st.st_rdev), tile, gt,
> +		 xe_engine_class_short_string(class));
>   
>   	if (!access(path, F_OK))
>   		return path;
> @@ -1567,14 +1553,14 @@ bool xe_sysfs_engine_class_get_property(int xe_device, int gt, uint16_t class, c
>   	engines_fd = xe_sysfs_engine_open(xe_device, gt, class);
>   
>   	if (engines_fd == -1) {
> -		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_to_str(class), gt);
> +		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_short_string(class), gt);
>   
>   		return false;
>   	}
>   
>   	if (!__igt_sysfs_get_u32(engines_fd, property, value)) {
>   		igt_debug("Failed to read %s property of %s on gt%d.\n", property,
> -			  xe_engine_class_to_str(class), gt);
> +			  xe_engine_class_short_string(class), gt);
>   		close(engines_fd);
>   
>   		return false;
> @@ -1606,14 +1592,14 @@ bool xe_sysfs_engine_class_set_property(int xe_device, int gt, uint16_t class, c
>   	engines_fd = xe_sysfs_engine_open(xe_device, gt, class);
>   
>   	if (engines_fd == -1) {
> -		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_to_str(class), gt);
> +		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_short_string(class), gt);
>   
>   		return false;
>   	}
>   
>   	if (old_value && !__igt_sysfs_get_u32(engines_fd, property, old_value)) {
>   		igt_debug("Failed to read %s property of %s on gt%d.\n", property,
> -			  xe_engine_class_to_str(class), gt);
> +			  xe_engine_class_short_string(class), gt);
>   		close(engines_fd);
>   
>   		return false;
> @@ -1621,7 +1607,7 @@ bool xe_sysfs_engine_class_set_property(int xe_device, int gt, uint16_t class, c
>   
>   	if (!__igt_sysfs_set_u32(engines_fd, property, new_value)) {
>   		igt_debug("Failed to write %s property of %s on gt%d.\n", property,
> -			  xe_engine_class_to_str(class), gt);
> +			  xe_engine_class_short_string(class), gt);
>   		close(engines_fd);
>   
>   		return false;
> diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
> index 73d2734e2..6a7b08006 100644
> --- a/lib/xe/xe_query.c
> +++ b/lib/xe/xe_query.c
> @@ -241,6 +241,31 @@ const char *xe_engine_class_string(uint32_t engine_class)
>   	}
>   }
>   
> +/**
> + * xe_engine_class_short_string:
> + * @engine_class: engine class
> + *
> + * Returns short name for engine class or 'unknown' otherwise.
> + */
> +const char *xe_engine_class_short_string(uint32_t engine_class)
> +{
> +	switch (engine_class) {
> +	case DRM_XE_ENGINE_CLASS_RENDER:
> +		return "rcs";
> +	case DRM_XE_ENGINE_CLASS_COPY:
> +		return "bcs";
> +	case DRM_XE_ENGINE_CLASS_VIDEO_DECODE:
> +		return "vcs";
> +	case DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE:
> +		return "vecs";
> +	case DRM_XE_ENGINE_CLASS_COMPUTE:
> +		return "ccs";
> +	default:
> +		igt_warn("Engine class 0x%x unknown\n", engine_class);
> +		return "unknown";
> +	}
> +}
> +
>   static struct xe_device_cache {
>   	pthread_mutex_t cache_mutex;
>   	struct igt_map *map;
> diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
> index 30ea5ad41..a84a6bfa5 100644
> --- a/lib/xe/xe_query.h
> +++ b/lib/xe/xe_query.h
> @@ -114,6 +114,7 @@ uint32_t xe_va_bits(int fd);
>   uint16_t xe_dev_id(int fd);
>   int xe_supports_faults(int fd);
>   const char *xe_engine_class_string(uint32_t engine_class);
> +const char *xe_engine_class_short_string(uint32_t engine_class);
>   bool xe_has_engine_class(int fd, uint16_t engine_class);
>   struct drm_xe_engine *xe_find_engine_by_class(int fd, uint16_t engine_class);
>   bool xe_has_media_gt(int fd);


More information about the igt-dev mailing list