drm/v3d: Improve Performance Counters handling
Subsystems (3)
Maíra Canal
maintainercover drm/v3d: Improve Performance Counters handling
This series has the intention to address two issues with Performance Counters on V3D:
1. Update the number of Performance Counters for V3D 7.1
V3D 7.1 has 93 performance counters, while V3D 4.2 has only 87. Although the series [1] enabled support for V3D 7.1, it didn’t replace the maximum number of performance counters. This led to errors in user space as the Vulkan driver updated the maximum number of performance counters, but the kernel didn’t.
Currently, the user space can request values for performance counters that are greater than 87 and the kernel will return an error instead of the values. That’s why dEQP-VK.query_pool.performance_query.* currently fails on Mesa CI [2]. This series intends to fix the dEQP-VK.query_pool.performance_query.* fail.
2. Make the kernel able to provide the Performance Counter descriptions
Although all the management of the Performance Monitors is done through IOCTLs, which means that the code is in the kernel, the performance counter descriptions are in Mesa. This means two things: (#1) only Mesa has access to the descriptions and (#2) we can have inconsistencies between the information provided by Mesa and the kernel, as seen in the first issue addressed by this series.
To minimize the risk of inconsistencies, this series proposes to use the kernel as a “single source of truth”. Therefore, if there are any changes to the performance monitors, all the changes must be done only in the kernel. This means that all information about the maximum number of performance counters and all the descriptions will now be retrieved from the kernel.
This series is coupled with a Mesa series [3] that enabled the use of the new IOCTL. I appreciate any feedback from both the kernel and Mesa implementations.
[1] https://lore.kernel.org/dri-devel/[email protected]/
[2] https://gitlab.freedesktop.org/mesa/mesa/-/commit/ea1f09a5f21839f4f3b93610b58507c4bd9b9b81
[3] https://gitlab.freedesktop.org/mairacanal/mesa/-/tree/v3dv/fix-perfcnt
Best Regards,
- Maíra Canal
Maíra Canal (6):
drm/v3d: Add Performance Counters descriptions for V3D 4.2 and 7.1 drm/v3d: Different V3D versions can have different number of perfcnt drm/v3d: Create a new V3D parameter for the maximum number of perfcnt drm/v3d: Create new IOCTL to expose performance counters information drm/v3d: Use V3D_MAX_COUNTERS instead of V3D_PERFCNT_NUM drm/v3d: Deprecate the use of the Performance Counters enum
drivers/gpu/drm/v3d/v3d_drv.c | 11 + drivers/gpu/drm/v3d/v3d_drv.h | 14 +- drivers/gpu/drm/v3d/v3d_perfmon.c | 36 ++- .../gpu/drm/v3d/v3d_performance_counters.h | 208 ++++++++++++++++++ drivers/gpu/drm/v3d/v3d_sched.c | 2 +- include/uapi/drm/v3d_drm.h | 44 ++++ 6 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/v3d/v3d_performance_counters.h
Signature · 1 line
2.44.0
Maíra Canal
maintainerPATCH 1/6 drm/v3d: Add Performance Counters descriptions for V3D 4.2 and 7.1
Add name, category and description for each one of the 93 performance counters available on V3D.
Note that V3D 4.2 has 87 performance counters, while V3D 7.1 has 93. Therefore, there are two performance counters arrays. The index of the performance counter for each V3D version is represented by its position on the array.
--- drivers/gpu/drm/v3d/v3d_drv.h | 2 + .../gpu/drm/v3d/v3d_performance_counters.h | 208 ++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 drivers/gpu/drm/v3d/v3d_performance_counters.h
drivers/gpu/drm/v3d/v3d_drv.h +2 -0
@@ -11,6 +11,8 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/gpu_scheduler.h> +#include "v3d_performance_counters.h" +#include "uapi/drm/v3d_drm.h" struct clk ;
drivers/gpu/drm/v3d/v3d_performance_counters.h new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.44.0
Maíra Canal
maintainerPATCH 2/6 drm/v3d: Different V3D versions can have different number of perfcnt
In reply to Maíra CanalCurrently, even though V3D 7.1 has 93 performance counters, it is not possible to create counters bigger than 87, as v3d_perfmon_create_ioctl() understands that counters bigger than 87 are invalid.
Therefore, create a device variable to expose the maximum number of counters for a given V3D version and make v3d_perfmon_create_ioctl() check this variable.
This commit fixes CTS failures in the performance queries tests (dEQP-VK.query_pool.performance_query.*) [1]
--- drivers/gpu/drm/v3d/v3d_drv.c | 7 +++++++ drivers/gpu/drm/v3d/v3d_drv.h | 5 +++++ drivers/gpu/drm/v3d/v3d_perfmon.c | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_drv.c +7 -0
@@ -294,6 +294,13 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) v3d->cores =V3D_GET_FIELD (ident1,V3D_HUB_IDENT1_NCORES );WARN_ON (v3d->cores >1 );/* multicore not yet implemented */ +if (v3d->ver >=71 ) + v3d->max_counters =ARRAY_SIZE (v3d_v71_performance_counters); +else if (v3d->ver >=42 ) + v3d->max_counters =ARRAY_SIZE (v3d_v42_performance_counters); +else + v3d->max_counters =0 ; + v3d->reset =devm_reset_control_get_exclusive (dev,NULL );if (IS_ERR (v3d->reset)) { ret =PTR_ERR (v3d->reset);
drivers/gpu/drm/v3d/v3d_drv.h +5 -0
@@ -104,6 +104,11 @@ struct v3d_dev {int ver;bool single_irq_line; +/* Different revisions of V3D have different total number of performance +* counters +*/ +unsigned int max_counters; +void __iomem *hub_regs;void __iomem *core_regs[3 ];void __iomem *bridge_regs;
drivers/gpu/drm/v3d/v3d_perfmon.c +2 -1
@@ -123,6 +123,7 @@ int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data, {struct v3d_file_priv *v3d_priv = file_priv->driver_priv;struct drm_v3d_perfmon_create *req = data; +struct v3d_dev *v3d = v3d_priv->v3d;struct v3d_perfmon *perfmon;unsigned int i;int ret;
@@ -134,7 +135,7 @@ int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data,/* Make sure all counters are valid. */ for (i =0 ; i < req->ncounters; i++) { -if (req->counters[i] >=V3D_PERFCNT_NUM ) +if (req->counters[i] >= v3d->max_counters)return -EINVAL ; }
Signature · 1 line
2.44.0
Maíra Canal
maintainerPATCH 3/6 drm/v3d: Create a new V3D parameter for the maximum number of perfcnt
In reply to Maíra CanalThe maximum number of performance counters can change from version to version and it's important for userspace to know this value, as it needs to use the counters for performance queries. Therefore, expose the maximum number of performance counters to userspace as a parameter.
--- drivers/gpu/drm/v3d/v3d_drv.c | 3 +++ include/uapi/drm/v3d_drm.h | 1 + 2 files changed, 4 insertions(+)
drivers/gpu/drm/v3d/v3d_drv.c +3 -0
@@ -94,6 +94,9 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,case DRM_V3D_PARAM_SUPPORTS_CPU_QUEUE : args->value =1 ;return 0 ; +case DRM_V3D_PARAM_MAX_PERF_COUNTERS : + args->value = v3d->max_counters; +return 0 ;default :DRM_DEBUG ("Unknown parameter %d\n" , args->param);return -EINVAL ;
include/uapi/drm/v3d_drm.h +1 -0
@@ -286,6 +286,7 @@ enum drm_v3d_param {DRM_V3D_PARAM_SUPPORTS_PERFMON ,DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT ,DRM_V3D_PARAM_SUPPORTS_CPU_QUEUE , + DRM_V3D_PARAM_MAX_PERF_COUNTERS, }; struct drm_v3d_get_param {
Signature · 1 line
2.44.0
Maíra Canal
maintainerPATCH 4/6 drm/v3d: Create new IOCTL to expose performance counters information
In reply to Maíra CanalUserspace usually needs some information about the performance counters available. Although we could replicate this information in the kernel and user-space, let's use the kernel as the "single source of truth" to avoid issues in the future (e.g. list of performance counters is updated in user-space, but not in the kernel, generating invalid requests).
Therefore, create a new IOCTL to expose the performance counters information, that is name, category, and description.
--- drivers/gpu/drm/v3d/v3d_drv.c | 1 + drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_perfmon.c | 33 +++++++++++++++++++++++++++ include/uapi/drm/v3d_drm.h | 37 +++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+)
drivers/gpu/drm/v3d/v3d_drv.c +1 -0
@@ -211,6 +211,7 @@ static const struct drm_ioctl_desc v3d_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (V3D_PERFMON_DESTROY , v3d_perfmon_destroy_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (V3D_PERFMON_GET_VALUES , v3d_perfmon_get_values_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (V3D_SUBMIT_CPU , v3d_submit_cpu_ioctl,DRM_RENDER_ALLOW |DRM_AUTH ), + DRM_IOCTL_DEF_DRV(V3D_PERFMON_GET_COUNTER, v3d_perfmon_get_counter_ioctl, DRM_RENDER_ALLOW), }; static const struct drm_driver v3d_drm_driver = {
drivers/gpu/drm/v3d/v3d_drv.h +2 -0
@@ -582,6 +582,8 @@ int v3d_perfmon_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);int v3d_perfmon_get_values_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int v3d_perfmon_get_counter_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);/* v3d_sysfs.c */ int v3d_sysfs_init (struct device *dev);
drivers/gpu/drm/v3d/v3d_perfmon.c +33 -0
@@ -217,3 +217,36 @@ int v3d_perfmon_get_values_ioctl(struct drm_device *dev, void *data,return ret; } + +int v3d_perfmon_get_counter_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_v3d_perfmon_get_counter *req = data; +struct v3d_dev *v3d =to_v3d_dev (dev); +const struct v3d_perf_counter_desc *counter; + +for (int i =0 ; i <ARRAY_SIZE (req->reserved); i++) { +if (req->reserved[i] !=0 ) +return -EINVAL ; + } + +/* Make sure that the counter ID is valid */ +if (req->counter >= v3d->max_counters) +return -EINVAL ; + +if (v3d->ver >=71 ) { +WARN_ON (v3d->max_counters !=ARRAY_SIZE (v3d_v71_performance_counters)); + counter = &v3d_v71_performance_counters[req->counter]; + }else if (v3d->ver >=42 ) { +WARN_ON (v3d->max_counters !=ARRAY_SIZE (v3d_v42_performance_counters)); + counter = &v3d_v42_performance_counters[req->counter]; + }else { +return -EOPNOTSUPP ; + } + +strscpy (req->name, counter->name,sizeof (req->name)); +strscpy (req->category, counter->category,sizeof (req->category)); +strscpy (req->description, counter->description,sizeof (req->description)); + +return 0 ; +}
include/uapi/drm/v3d_drm.h +37 -0
@@ -42,6 +42,7 @@ extern "C" {#define DRM_V3D_PERFMON_DESTROY 0x09#define DRM_V3D_PERFMON_GET_VALUES 0x0a#define DRM_V3D_SUBMIT_CPU 0x0b +#define DRM_V3D_PERFMON_GET_COUNTER 0x0c#define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl)#define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo)
@@ -58,6 +59,8 @@ extern "C" {#define DRM_IOCTL_V3D_PERFMON_GET_VALUES DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_VALUES, \ struct drm_v3d_perfmon_get_values)#define DRM_IOCTL_V3D_SUBMIT_CPU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CPU, struct drm_v3d_submit_cpu) +#define DRM_IOCTL_V3D_PERFMON_GET_COUNTER DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_COUNTER, \ + struct drm_v3d_perfmon_get_counter)#define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01#define DRM_V3D_SUBMIT_EXTENSION 0x02
@@ -718,6 +721,40 @@ struct drm_v3d_perfmon_get_values {__u64 values_ptr; }; +#define DRM_V3D_PERFCNT_MAX_NAME 64 +#define DRM_V3D_PERFCNT_MAX_CATEGORY 32 +#define DRM_V3D_PERFCNT_MAX_DESCRIPTION 256 + +/** +* struct drm_v3d_perfmon_get_counter - ioctl to get the description of a +* performance counter +* +* As userspace needs to retrieve information about the performance counters +* available, this IOCTL allows users to get information about a performance +* counter (name, category and description). +*/ +struct drm_v3d_perfmon_get_counter { +/* +* Counter ID +* +* Must be smaller than the maximum number of performance counters, which +* can be retrieve through DRM_V3D_PARAM_MAX_PERF_COUNTERS. +*/ +__u8 counter; + +/* Name of the counter */ +__u8 name[DRM_V3D_PERFCNT_MAX_NAME ]; + +/* Category of the counter */ +__u8 category[DRM_V3D_PERFCNT_MAX_CATEGORY ]; + +/* Description of the counter */ +__u8 description[DRM_V3D_PERFCNT_MAX_DESCRIPTION ]; + +/* mbz */ +__u8 reserved[7 ]; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.44.0
Maíra Canal
maintainerPATCH 5/6 drm/v3d: Use V3D_MAX_COUNTERS instead of V3D_PERFCNT_NUM
In reply to Maíra CanalV3D_PERFCNT_NUM represents the maximum number of performance counters for V3D 4.2, but not for V3D 7.1. This means that, if we use V3D_PERFCNT_NUM, we might go out-of-bounds on V3D 7.1.
Therefore, use the number of performance counters on V3D 7.1 as the maximum number of counters. This will allow us to create arrays on the stack with reasonable size. Note that userspace must use the value provided by DRM_V3D_PARAM_V3D_MAX_PERF_COUNTERS.
--- drivers/gpu/drm/v3d/v3d_drv.h | 5 ++++- drivers/gpu/drm/v3d/v3d_sched.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +4 -1
@@ -351,8 +351,11 @@ struct v3d_timestamp_query {struct drm_syncobj *syncobj; }; +/* Maximum number of performance counters supported by any version of V3D */ +#define V3D_MAX_COUNTERS ARRAY_SIZE(v3d_v71_performance_counters) +/* Number of perfmons required to handle all supported performance counters */ -#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_PERFCNT_NUM, \ +#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ DRM_V3D_MAX_PERF_COUNTERS)struct v3d_performance_query {
drivers/gpu/drm/v3d/v3d_sched.c +1 -1
@@ -490,7 +490,7 @@ v3d_write_performance_query_result(struct v3d_cpu_job *job, void *data, u32 querstruct v3d_file_priv *v3d_priv = job->base.file->driver_priv;struct v3d_dev *v3d = job->base.v3d;struct v3d_perfmon *perfmon; -u64 counter_values[V3D_PERFCNT_NUM ]; +u64 counter_values[V3D_MAX_COUNTERS ];for (int i =0 ; i < performance_query->nperfmons; i++) { perfmon = v3d_perfmon_find(v3d_priv,
Signature · 1 line
2.44.0
Re: [PATCH 5/6] drm/v3d: Use V3D_MAX_COUNTERS instead of V3D_PERFCNT_NUM
Quoted 9 lines · Maíra Canal
V3D_PERFCNT_NUMrepresents the maximum number of performance counters for V3D 4.2, but not for V3D 7.1. This means that, if we useV3D_PERFCNT_NUM, we might go out-of-bounds on V3D 7.1.Therefore, use the number of performance counters on V3D 7.1 as the maximum number of counters. This will allow us to create arrays on the
stack with reasonable size. Note that userspace must use the value provided byDRM_V3D_PARAM_V3D_MAX_PERF_COUNTERS.
This should be DRM_V3D_PARAM_MAX_PERF_COUNTERS.
Iago
Maíra Canal
maintainerPATCH 6/6 drm/v3d: Deprecate the use of the Performance Counters enum
In reply to Maíra CanalThe Performance Counters enum used to identify the index of each performance counter and provide the total number of performance counters (V3D_PERFCNT_NUM). But, this enum is only valid for V3D 4.2, not for V3D 7.1.
As we implemented a new flexible structure to retrieve performance counters information, we can deprecate this enum.
--- include/uapi/drm/v3d_drm.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/drm/v3d_drm.h +6 -0
@@ -603,6 +603,12 @@ struct drm_v3d_submit_cpu {__u64 extensions; }; +/* The performance counters index represented by this enum are deprecated and +* must no longer be used. These counters are only valid for V3D 4.2. +* +* In order to check for performance counter information, +* use DRM_IOCTL_V3D_PERFMON_GET_COUNTER. +*/ enum {V3D_PERFCNT_FEP_VALID_PRIMTS_NO_PIXELS ,V3D_PERFCNT_FEP_VALID_PRIMS ,
Signature · 1 line
2.44.0
Re: [PATCH 6/6] drm/v3d: Deprecate the use of the Performance Counters enum
Quoted 20 lines · Maíra Canal
The Performance Counters enum used to identify the index of each performance counter and provide the total number of performance counters (
V3D_PERFCNT_NUM). But, this enum is only valid for V3D 4.2, not for V3D 7.1.As we implemented a new flexible structure to retrieve performance counters information, we can deprecate this enum.
Signed-off-by Maíra Canal <[email protected]>---
include/uapi/drm/v3d_drm.h | 6 ++++++1 file changed, 6 insertions(+)include/uapi/drm/v3d_drm.h +0
-0@@ -603,6 +603,12 @@ struct drm_v3d_submit_cpu { __u64 extensions; };
Quoted 8 lines
+/* The performance counters index represented by this enum are deprecated and
+ * must no longer be used. These counters are only valid for V3D 4.2.
+ *
+ * In order to check for performance counter information,
+ * useDRM_IOCTL_V3D_PERFMON_GET_COUNTER.
We should probably also include a reference to the new DRM_V3D_PARAM_MAX_PERF_COUNTERS param here as well to retrieve the total number of counters available.
Iago
Quoted 4 lines
+ */
enum {
V3D_PERFCNT_FEP_VALID_PRIMTS_NO_PIXELS,
V3D_PERFCNT_FEP_VALID_PRIMS,
Hi Maíra,
I made a couple of minor comments, with those addressed the series is:
Thanks a lot for this!,
Iago
Quoted 84 lines · Maíra Canal
This series has the intention to address two issues with Performance Counters
on V3D:1. Update the number of Performance Counters for V3D 7.1
V3D 7.1 has 93 performance counters, while V3D 4.2 has only 87. Although the
series [1] enabled support for V3D 7.1, it didn’t replace the maximum number of
performance counters. This led to errors in user space as the Vulkan driver
updated the maximum number of performance counters, but the kernel didn’t.
Currently, the user space can request values for performance counters that
are greater than 87 and the kernel will return an error instead of the values.
That’s whydEQP-VK.query_pool.performance_query.*currently fails on Mesa
CI [2]. This series intends to fix thedEQP- VK.query_pool.performance_query.*
fail.
2. Make the kernel able to provide the Performance Counter descriptions
Although all the management of the Performance Monitors is done through IOCTLs,
which means that the code is in the kernel, the performance counter descriptions
are in Mesa. This means two things: (#1) only Mesa has access to the descriptions
and (#2) we can have inconsistencies between the information provided by Mesa
and the kernel, as seen in the first issue addressed by this series.To minimize the risk of inconsistencies, this series proposes to use the kernel
as a “single source of truth”. Therefore, if there are any changes to the
performance monitors, all the changes must be done only in the kernel. This
means that all information about the maximum number of performance counters and
all the descriptions will now be retrieved from the kernel.This series is coupled with a Mesa series [3] that enabled the use of the new
IOCTL. I appreciate any feedback from both the kernel and Mesa implementations.[1]
https://lore.kernel.org/dri-devel/[email protected]/
[2]
https://gitlab.freedesktop.org/mesa/mesa/-/commit/ea1f09a5f21839f4f3b93610b58507c4bd9b9b81
[3]
https://gitlab.freedesktop.org/mairacanal/mesa/-/tree/v3dv/fix-perfcntBest Regards,
- Maíra CanalMaíra Canal (6):
drm/v3d: Add Performance Counters descriptions for V3D 4.2 and 7.1 drm/v3d: Different V3D versions can have different number of perfcnt
drm/v3d: Create a new V3D parameter for the maximum number of perfcnt
drm/v3d: Create new IOCTL to expose performance counters information
drm/v3d: UseV3D_MAX_COUNTERSinstead ofV3D_PERFCNT_NUMdrm/v3d: Deprecate the use of the Performance Counters enumdrivers/gpu/drm/v3d/v3d_drv.c | 11 + drivers/gpu/drm/v3d/v3d_drv.h | 14 +- drivers/gpu/drm/v3d/v3d_perfmon.c | 36 ++- .../gpu/drm/v3d/v3d_performance_counters.h | 208
++++++++++++++++++
drivers/gpu/drm/v3d/v3d_sched.c | 2 +- include/uapi/drm/v3d_drm.h | 44 ++++6 files changed, 312 insertions(+), 3 deletions(-)create mode 100644
drivers/gpu/drm/v3d/v3d_performance_counters.h