[igt-dev] [PATCH i-g-t v7 1/4] lib/igt_sysfs: Add support to query number of tiles

Dixit, Ashutosh ashutosh.dixit at intel.com
Thu Jul 6 23:46:27 UTC 2023


On Thu, 06 Jul 2023 03:44:57 -0700, Himal Prasad Ghimiray wrote:
>
> With tile and GT seperation in KMD, we need to know
> number of tiles supported by platform.
> We will need to access tile associated properties from IGT.
> Hence adding iterator for all supported tiles.
>
> v2:
> - Calculate number of tiles once within iterator. (Rahul)
> - Use snprintf instead of sprintf.
>
> v3:
> - Remove unrequired for_each_sysfs_tile_dirfd (Ashutosh)
>
> v4:
> - Implement tiles related functions in lib.
>
> Cc: Ashutosh Dixit <ashutosh.dixit at intel.com>
> Cc: Aravind Iddamsetty <aravind.iddamsetty at intel.com>
> Cc: Upadhyay <tejas.upadhyay at intel.com>
> Cc: Janga Rahul Kumar <janga.rahul.kumar at intel.com>
> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray at intel.com>
> ---
>  lib/igt_sysfs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_sysfs.h | 10 +++++++
>  2 files changed, 87 insertions(+)
>
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index 0876f4c6b..dcb38cfc9 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -903,3 +903,80 @@ void igt_sysfs_engines(int xe, int engines, const char **property,
>		close(engine_fd);
>	}
>  }
> +
> +/**
> + * xe_sysfs_tile_path:
> + * @device: fd of the device

xe_device

> + * @tile: tile number
> + * @path: buffer to fill with the sysfs tile path to the device
> + * @pathlen: length of @path buffer
> + *
> + * This finds the sysfs directory corresponding to @device and @tile. If the tile
> + * specific directory is not available and tile is 0, path is filled with sysfs
> + * base directory.
> + *
> + * Returns:
> + * The directory path, or NULL on failure.
> + */
> +char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen)
> +{
> +	struct stat st;
> +
> +	if (xe_device < 0)
> +		return NULL;
> +
> +	if (igt_debug_on(fstat(xe_device, &st)) || igt_debug_on(!S_ISCHR(st.st_mode)))
> +		return NULL;
> +
> +	snprintf(path, pathlen, "/sys/dev/char/%d:%d/device/tile%d",
> +		 major(st.st_rdev), minor(st.st_rdev), tile);
> +
> +	if (!access(path, F_OK))
> +		return path;
> +	if (!tile)
> +		return igt_sysfs_path(xe_device, path, pathlen);

This if () is in igt_sysfs_gt_path to take care of the legacy case. There
is no such thing for xe, so let's remove this if ().

Fix the comment above the function too.

> +	return NULL;
> +}
> +
> +/**
> + * xe_sysfs_tile_open:
> + * @xe_device: fd of the device
> + * @tile: tile number
> + *
> + * This opens the sysfs tile directory corresponding to device and tile for use
> + *
> + * Returns:
> + * The directory fd, or -1 on failure.
> + */
> +int xe_sysfs_tile_open(int xe_device, int tile)
> +{
> +	char path[96];
> +
> +	if (!xe_sysfs_tile_path(xe_device, tile, path, sizeof(path)))
> +		return -1;
> +
> +	return open(path, O_RDONLY);
> +}
> +
> +/**
> + * xe_sysfs_get_num_tiles:
> + * @xe_device: fd of the device
> + *
> + * Reads number of tile sysfs entries.
> + * Asserts for at least one tile entry.
> + * (see xe_sysfs_tile_path).
> + *
> + * Returns: Number of tiles.
> + */
> +int xe_sysfs_get_num_tiles(int xe_device)
> +{
> +	int num_tiles = 0;
> +	char path[96];
> +
> +	while (xe_sysfs_tile_path(xe_device, num_tiles, path, sizeof(path)))
> +		++num_tiles;
> +
> +	igt_assert_f(num_tiles > 0, "No GT sysfs entry is found.");
> +
> +	return num_tiles;
> +}
> diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
> index 5635fc690..5d584b1c7 100644
> --- a/lib/igt_sysfs.h
> +++ b/lib/igt_sysfs.h
> @@ -38,6 +38,11 @@
>	     (dirfd__ = igt_sysfs_gt_open(i915__, gt__)) != -1; \
>	     close(dirfd__), gt__++)
>
> +#define for_each_sysfs_tile_dirfd(xe__, dirfd__, tile__) \
> +	for (tile__ = 0; \
> +	     (dirfd__ = xe_sysfs_tile_open(xe__, tile__)) != -1; \
> +	     close(dirfd__), tile__++)
> +
>  #define i915_for_each_gt for_each_sysfs_gt_dirfd
>
>  #define igt_sysfs_rps_write(dir, id, data, len) \
> @@ -73,6 +78,8 @@
>  #define igt_sysfs_rps_set_boolean(dir, id, value) \
>	igt_sysfs_set_boolean(dir, igt_sysfs_dir_id_to_name(dir, id), value)
>
> +#define xe_for_each_tile for_each_sysfs_tile_dirfd
> +
>  enum i915_attr_id {
>	RPS_ACT_FREQ_MHZ,
>	RPS_CUR_FREQ_MHZ,
> @@ -150,4 +157,7 @@ void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw);
>  void igt_sysfs_engines(int xe, int engines, const char **property,
>		       void (*test)(int, int, const char **));
>
> +char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen);
> +int xe_sysfs_tile_open(int xe_device, int tile);
> +int xe_sysfs_get_num_tiles(int xe_device);
>  #endif /* __IGT_SYSFS_H__ */
> --
> 2.25.1
>


More information about the igt-dev mailing list