diff mbox series

[i-g-t,v4,1/2] lib/igt_perf: Add utils to extract PMU event info

Message ID 20250127081402.2587605-2-vinay.belgaumkar@intel.com (mailing list archive)
State New
Headers show
Series tests/intel/xe_pmu: Add PMU tests | expand

Commit Message

Belgaumkar, Vinay Jan. 27, 2025, 8:14 a.m. UTC
Functions to parse event ID and GT bit shift for PMU events.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
---
 lib/igt_perf.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_perf.h |  2 ++
 2 files changed, 70 insertions(+)

Comments

Riana Tauro Jan. 27, 2025, 8:52 a.m. UTC | #1
Hi Vinay

On 1/27/2025 1:44 PM, Vinay Belgaumkar wrote:
> Functions to parse event ID and GT bit shift for PMU events.
> 
> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
> Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
> ---
>   lib/igt_perf.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   lib/igt_perf.h |  2 ++
>   2 files changed, 70 insertions(+)
> 
> diff --git a/lib/igt_perf.c b/lib/igt_perf.c
> index 3866c6d77..e333744bb 100644
> --- a/lib/igt_perf.c
> +++ b/lib/igt_perf.c
> @@ -92,6 +92,74 @@ const char *xe_perf_device(int xe, char *buf, int buflen)
>   	return buf;
>   }
>   
> +/**
> + * perf_xe_event_format_gt: Returns the start position of GT id in the event format
> + * @device: Device string in driver:pci format
> + * Returns: Start bit for GT id
> + *
> + */
> +int perf_xe_event_format_gt(const char *device)
Can remove xe prefix if we have name as parameter
> +{
> +	char buf[150];
%s/150/NAME_MAX
> +	ssize_t ret;
> +	int fd, start, end;
> +
> +	snprintf(buf, sizeof(buf),
> +		 "/sys/bus/event_source/devices/%s/format/gt",
> +		 device);
Can we pass the name as the parameter for this function?
Can be re-used for all formats
> +
> +	fd = open(buf, O_RDONLY);
> +	if (fd < 0)
> +		return -EINVAL;
> +
> +	ret = read(fd, buf, sizeof(buf) - 1);
> +	close(fd);
> +	if (ret < 1)
> +		return ret;
> +
> +	buf[ret] = '\0';
> +	ret = sscanf(buf, "config:%d-%d", &start, &end);
> +	if (ret != 2)
> +		return -EINVAL;
> +
> +	return start;
> +}
> +
> +/**
> + * perf_xe_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_xe_event_config(const char *device, const char *event, uint64_t *config)
xe prefix can be removed here
> +{
> +	char buf[150];
> +	ssize_t ret;
> +	int 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;
> +
> +	ret = read(fd, buf, sizeof(buf) - 1);
> +	close(fd);
> +	if (ret < 1)
> +		return ret;
> +
> +	buf[ret] = '\0';
> +	ret = sscanf(buf, "config=0x%lx", config);
%s/config/event

Thanks
Riana
> +	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..f51c44bb2 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_xe_event_config(const char *device, const char *event, uint64_t *config);
> +int perf_xe_event_format_gt(const char *device);
>   
>   #endif /* I915_PERF_H */
diff mbox series

Patch

diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index 3866c6d77..e333744bb 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -92,6 +92,74 @@  const char *xe_perf_device(int xe, char *buf, int buflen)
 	return buf;
 }
 
+/**
+ * perf_xe_event_format_gt: Returns the start position of GT id in the event format
+ * @device: Device string in driver:pci format
+ * Returns: Start bit for GT id
+ *
+ */
+int perf_xe_event_format_gt(const char *device)
+{
+	char buf[150];
+	ssize_t ret;
+	int fd, start, end;
+
+	snprintf(buf, sizeof(buf),
+		 "/sys/bus/event_source/devices/%s/format/gt",
+		 device);
+
+	fd = open(buf, O_RDONLY);
+	if (fd < 0)
+		return -EINVAL;
+
+	ret = read(fd, buf, sizeof(buf) - 1);
+	close(fd);
+	if (ret < 1)
+		return ret;
+
+	buf[ret] = '\0';
+	ret = sscanf(buf, "config:%d-%d", &start, &end);
+	if (ret != 2)
+		return -EINVAL;
+
+	return start;
+}
+
+/**
+ * perf_xe_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_xe_event_config(const char *device, const char *event, uint64_t *config)
+{
+	char buf[150];
+	ssize_t ret;
+	int 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;
+
+	ret = read(fd, buf, sizeof(buf) - 1);
+	close(fd);
+	if (ret < 1)
+		return ret;
+
+	buf[ret] = '\0';
+	ret = sscanf(buf, "config=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..f51c44bb2 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_xe_event_config(const char *device, const char *event, uint64_t *config);
+int perf_xe_event_format_gt(const char *device);
 
 #endif /* I915_PERF_H */