Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Miszczak <adam.miszczak@linux.intel.com>
To: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>,
	igt-dev@lists.freedesktop.org
Cc: jakub1.kolakowski@intel.com, lukasz.laguna@intel.com,
	michal.wajdeczko@intel.com, michal.winiarski@intel.com,
	narasimha.c.v@intel.com, piotr.piorkowski@intel.com,
	satyanarayana.k.v.p@intel.com, tomasz.lis@intel.com
Subject: Re: [PATCH i-g-t 3/5] lib/xe/xe_sriov_debugfs: Add function to read provisioned ranges
Date: Tue, 5 Nov 2024 12:39:51 +0100	[thread overview]
Message-ID: <5b26294b-d305-4424-af70-49e39ab96782@linux.intel.com> (raw)
In-Reply-To: <20241030193629.1238637-4-marcin.bernatowicz@linux.intel.com>

On 30.10.2024 20:36, Marcin Bernatowicz wrote:
> Implement xe_sriov_pf_debugfs_read_provisioned_ranges() to read and
> parse VFs provisioned ranges from the debug filesystem. Introduce
> xe_sriov_debugfs_provisioned_attr_name() to get the debugfs attribute
> name for a given shared resource type.
>
> Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
> Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
> Cc: Jakub Kolakowski <jakub1.kolakowski@intel.com>
> Cc: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
> Cc: Michał Wajdeczko <michal.wajdeczko@intel.com>
> Cc: Michał Winiarski <michal.winiarski@intel.com>
> Cc: Narasimha C V <narasimha.c.v@intel.com>
> Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
> Cc: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>
> Cc: Tomasz Lis <tomasz.lis@intel.com>
> ---
>   lib/xe/xe_sriov_debugfs.c | 139 +++++++++++++++++++++++++++++++++++++-
>   lib/xe/xe_sriov_debugfs.h |   8 ++-
>   2 files changed, 145 insertions(+), 2 deletions(-)
>
> diff --git a/lib/xe/xe_sriov_debugfs.c b/lib/xe/xe_sriov_debugfs.c
> index dc6ef9da3..84fd08c3c 100644
> --- a/lib/xe/xe_sriov_debugfs.c
> +++ b/lib/xe/xe_sriov_debugfs.c
> @@ -9,8 +9,9 @@
>   #include "drmtest.h"
>   #include "igt_debugfs.h"
>   #include "igt_sriov_device.h"
> -#include "xe/xe_sriov_debugfs.h"
>   #include "xe/xe_query.h"
> +#include "xe/xe_sriov_debugfs.h"
> +#include "xe/xe_sriov_provisioning.h"
>   
>   #define SRIOV_DEBUGFS_PATH_MAX 96
>   
> @@ -67,3 +68,139 @@ int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_n
>   
>   	return debugfs;
>   }
> +
> +/**
> + * xe_sriov_debugfs_provisioned_attr_name:
> + * @res: The shared resource type
> + *
> + * Returns the name of the debugfs provisioned attribute corresponding
> + * to the given shared resource type.
> + *
> + * Return: A string representing the debugfs provisioned attribute name if the
> + *         resource type is valid, otherwise NULL.
> + */
> +const char *xe_sriov_debugfs_provisioned_attr_name(enum xe_sriov_shared_res res)
> +{
> +	switch (res) {
> +	case XE_SRIOV_SHARED_RES_CONTEXTS:
> +		return "contexts_provisioned";
> +	case XE_SRIOV_SHARED_RES_DOORBELLS:
> +		return "doorbells_provisioned";
> +	case XE_SRIOV_SHARED_RES_GGTT:
> +		return "ggtt_provisioned";
> +	case XE_SRIOV_SHARED_RES_LMEM:
> +		return "lmem_provisioned";
> +	}
> +
> +	return NULL;
> +}
> +
> +static int parse_provisioned_range(const char *line,
> +				   struct xe_sriov_provisioned_range *range,
> +				   enum xe_sriov_shared_res res)
> +{
> +	int ret = -1;
> +
> +	switch (res) {
> +	case XE_SRIOV_SHARED_RES_CONTEXTS:
> +	case XE_SRIOV_SHARED_RES_DOORBELLS:
> +		if (sscanf(line, "VF%u: %lu-%lu", &range->vf_id, &range->start, &range->end) == 3)
> +			ret = 0;
> +		break;
> +	case XE_SRIOV_SHARED_RES_GGTT:
> +		if (sscanf(line, "VF%u: %lx-%lx", &range->vf_id, &range->start, &range->end) == 3)
> +			ret = 0;
> +		break;
> +	case XE_SRIOV_SHARED_RES_LMEM:
> +		/* Convert to an inclusive range as is the case for other resources.
> +		 * The start is always 0 and the end is the value read - 1.
> +		 */
> +		if (sscanf(line, "VF%u: %lu", &range->vf_id, &range->end) == 2)
> +			ret = 0;
> +		if (!range->end)
> +			return -1;
> +		range->end -= 1;
> +		range->start = 0;
> +		break;
> +	}
> +
> +	return ret;
> +}
> +
> +/**
> + * xe_sriov_debugfs_pf_read_provisioned_ranges:
> + * @pf_fd: PF device file descriptor
> + * @res: resource
> + * @gt_id: GT number
> + * @ranges: pointer to array of provisioned ranges
> + * @nr_ranges: pointer to number of read provisioned VFs
> + *
> + * Read provisioned ranges of shared resources.
Nit: in the other descriptions, I see conjugation in the 3rd person - so 
"Reads" for consistency?
> + * Allocates the space for ranges and updates
> + * the nr_ranges to the number of read ranges.
> + * The caller should free the allocated space.
> + *
> + * Return: 0 if successful in reading ranges, otherwise negative error code.
> + */
> +int xe_sriov_pf_debugfs_read_provisioned_ranges(int pf_fd, enum xe_sriov_shared_res res,
> +						unsigned int gt_id,
> +						struct xe_sriov_provisioned_range **ranges,
> +						unsigned int *nr_ranges)
> +{
> +	struct xe_sriov_provisioned_range *new_ranges;
> +	struct xe_sriov_provisioned_range range;
> +	FILE *file;
> +	size_t n = 0;
> +	const char *fname;
> +	char *line = NULL;
> +	int fd, ret = 0;
> +	ssize_t nread;
> +
> +	*nr_ranges = 0;
> +	*ranges = NULL;
> +
> +	fname = xe_sriov_debugfs_provisioned_attr_name(res);
> +	if (!fname)
> +		return -EINVAL;
> +
> +	fd = xe_sriov_pf_debugfs_attr_open(pf_fd, 0, gt_id, fname, O_RDONLY);
> +	if (fd < 0)
> +		return -ENOENT;
> +	file = fdopen(fd, "r");
> +	if (!file) {
> +		close(fd);
> +		return -errno;
> +	}
> +
> +	while ((nread = getline(&line, &n, file)) != -1) {
> +		ret = parse_provisioned_range(line, &range, res);
> +		if (ret) {
> +			igt_debug("Failed to parse line: %s\n", line);
> +			goto cleanup;
> +		}
> +
> +		new_ranges = realloc(*ranges, sizeof(range) * (*nr_ranges + 1));
> +		if (!new_ranges) {
> +			ret = -ENOMEM;
> +			goto cleanup;
> +		}
> +		*ranges = new_ranges;
> +		memcpy(&(*ranges)[*nr_ranges], &range, sizeof(range));
> +		(*nr_ranges)++;
> +	}
> +
> +	if (ferror(file))
> +		ret = -EIO;
> +
> +cleanup:
> +	free(line);
> +	fclose(file);
> +
> +	if (ret < 0) {
> +		free(*ranges);
> +		*ranges = NULL;
> +		*nr_ranges = 0;
> +	}
> +
> +	return ret;
> +}
> diff --git a/lib/xe/xe_sriov_debugfs.h b/lib/xe/xe_sriov_debugfs.h
> index e859ff5b2..856445e76 100644
> --- a/lib/xe/xe_sriov_debugfs.h
> +++ b/lib/xe/xe_sriov_debugfs.h
> @@ -6,9 +6,15 @@
>   #ifndef __XE_SRIOV_DEBUGFS_H__
>   #define __XE_SRIOV_DEBUGFS_H__
>   
> -#include <stdint.h>
> +enum xe_sriov_shared_res;
> +struct xe_sriov_provisioned_range;
>   
>   int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_num,
>   				  const char *attr, int mode);
> +const char *xe_sriov_debugfs_provisioned_attr_name(enum xe_sriov_shared_res res);
> +int xe_sriov_pf_debugfs_read_provisioned_ranges(int pf_fd, enum xe_sriov_shared_res res,
> +						unsigned int gt_id,
> +						struct xe_sriov_provisioned_range **ranges,
> +						unsigned int *nr_ranges);
>   
>   #endif /* __XE_SRIOV_DEBUGFS_H__ */
LGTM,
Reviewed-by: Adam Miszczak <adam.miszczak@linux.intel.com>

  reply	other threads:[~2024-11-05 11:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 19:36 [PATCH i-g-t 0/5] Add debugfs SR-IOV helpers; Improve clear-lmem check Marcin Bernatowicz
2024-10-30 19:36 ` [PATCH i-g-t 1/5] lib/xe_sriov_debugfs: add helper for opening attributes Marcin Bernatowicz
2024-10-31 10:28   ` Kamil Konieczny
2024-11-05  8:45   ` Adam Miszczak
2024-10-30 19:36 ` [PATCH i-g-t 2/5] lib/xe/xe_sriov_provisioning: Define resource types and provisioned range structure Marcin Bernatowicz
2024-11-05 11:21   ` Adam Miszczak
2024-11-06  9:09     ` Bernatowicz, Marcin
2024-10-30 19:36 ` [PATCH i-g-t 3/5] lib/xe/xe_sriov_debugfs: Add function to read provisioned ranges Marcin Bernatowicz
2024-11-05 11:39   ` Adam Miszczak [this message]
2024-10-30 19:36 ` [PATCH i-g-t 4/5] tests/intel/xe_sriov_flr: Verify full LMEM range Marcin Bernatowicz
2024-11-06  8:31   ` Adam Miszczak
2024-10-30 19:36 ` [PATCH i-g-t 5/5] lib/xe/xe_sriov_provisioning: Extract function to search provisioned PTE ranges Marcin Bernatowicz
2024-11-06  8:08   ` Adam Miszczak
2024-10-30 21:41 ` ✓ Fi.CI.BAT: success for Add debugfs SR-IOV helpers; Improve clear-lmem check Patchwork
2024-10-30 21:42 ` ✓ CI.xeBAT: " Patchwork
2024-10-30 23:20 ` ✗ CI.xeFULL: failure " Patchwork
2024-10-31  7:15 ` ✗ Fi.CI.IGT: " 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=5b26294b-d305-4424-af70-49e39ab96782@linux.intel.com \
    --to=adam.miszczak@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jakub1.kolakowski@intel.com \
    --cc=lukasz.laguna@intel.com \
    --cc=marcin.bernatowicz@linux.intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=narasimha.c.v@intel.com \
    --cc=piotr.piorkowski@intel.com \
    --cc=satyanarayana.k.v.p@intel.com \
    --cc=tomasz.lis@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