[PATCH i-g-t v2 1/3] lib/igt_perf: Add utils to extract PMU event info
Kamil Konieczny
kamil.konieczny at linux.intel.com
Wed Feb 19 10:13:28 UTC 2025
Hi Riana,
On 2025-02-17 at 19:50:16 +0530, Riana Tauro wrote:
> From: Vinay Belgaumkar <vinay.belgaumkar at intel.com>
>
> Functions to parse event ID and GT bit shift for PMU events.
>
> v2: Review comments (Riana)
> v3: Review comments (Lucas)
> v4: fix kernel-doc (Kamil)
> remove parameter for end (Umesh)
>
> Reviewed-by: Riana Tauro <riana.tauro at intel.com>
> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar at intel.com>
> ---
> lib/igt_perf.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
> lib/igt_perf.h | 2 ++
> 2 files changed, 74 insertions(+)
>
> diff --git a/lib/igt_perf.c b/lib/igt_perf.c
> index 3866c6d77..c1b8cc629 100644
> --- a/lib/igt_perf.c
> +++ b/lib/igt_perf.c
> @@ -92,6 +92,78 @@ const char *xe_perf_device(int xe, char *buf, int buflen)
> return buf;
> }
>
> +/**
> + * perf_event_format: Returns the shift positions of an event format param
> + * @device: PMU device
> + * @param: parameter to obtain the shiift
> + * @shift: shift bits for the parameter
> + *
> + * Returns: 0 on success or negative error code
> + */
> +int perf_event_format(const char *device, const char *param, uint32_t *shift)
> +{
> + char buf[NAME_MAX];
> + ssize_t bytes;
> + int ret = 0, fd;
> + uint32_t end;
> +
> + snprintf(buf, sizeof(buf),
> + "/sys/bus/event_source/devices/%s/format/%s",
> + device, param);
> +
> + fd = open(buf, O_RDONLY | O_CLOEXEC);
> + if (fd < 0)
> + return -EINVAL;
> +
> + bytes = read(fd, buf, sizeof(buf) - 1);
> + close(fd);
> + if (bytes < 1)
> + return -EINVAL;
> +
> + buf[bytes] = '\0';
> + ret = sscanf(buf, "config:%u-%u", shift, &end);
> + if (ret != 2)
> + return -EINVAL;
> +
> + return ret;
s/return ret/return 0/
with this fixed
Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
> +}
> +
> +/**
> + * perf_event_config:
> + * @device: Device string in driver:pci format
> + * @event: The event name
> + * @config: Pointer to the config
> + *
> + * Returns: 0 for success, negative value on error
> + */
> +int perf_event_config(const char *device, const char *event, uint64_t *config)
> +{
> + char buf[NAME_MAX];
> + ssize_t bytes;
> + int ret = 0, fd;
> +
> + snprintf(buf, sizeof(buf),
> + "/sys/bus/event_source/devices/%s/events/%s",
> + device,
> + event);
> +
> + fd = open(buf, O_RDONLY);
> + if (fd < 0)
> + return -EINVAL;
> +
> + bytes = read(fd, buf, sizeof(buf) - 1);
> + close(fd);
> + if (bytes < 1)
> + return ret;
> +
> + buf[bytes] = '\0';
> + ret = sscanf(buf, "event=0x%lx", config);
> + if (ret != 1)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> uint64_t xe_perf_type_id(int xe)
> {
> char buf[80];
> diff --git a/lib/igt_perf.h b/lib/igt_perf.h
> index 3d9ba2917..58d7d47aa 100644
> --- a/lib/igt_perf.h
> +++ b/lib/igt_perf.h
> @@ -71,5 +71,7 @@ int perf_i915_open(int i915, uint64_t config);
> int perf_i915_open_group(int i915, uint64_t config, int group);
>
> int perf_xe_open(int xe, uint64_t config);
> +int perf_event_config(const char *device, const char *event, uint64_t *config);
> +int perf_event_format(const char *device, const char *param, uint32_t *shift);
>
> #endif /* I915_PERF_H */
> --
> 2.47.1
>
More information about the igt-dev
mailing list