]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/v3d: Add DRM_IOCTL_V3D_PERFMON_SET_GLOBAL
authorChristian Gmeiner <cgmeiner@igalia.com>
Mon, 2 Dec 2024 14:06:13 +0000 (15:06 +0100)
committerMaíra Canal <mcanal@igalia.com>
Wed, 4 Dec 2024 11:44:27 +0000 (08:44 -0300)
Add a new ioctl, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL, to allow
configuration of a global performance monitor (perfmon).
Use the global perfmon for all jobs to ensure consistent
performance tracking across submissions. This feature is
needed to implement a Perfetto datasources in user-space.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241202140615.74802-1-christian.gmeiner@gmail.com
drivers/gpu/drm/v3d/v3d_drv.c
drivers/gpu/drm/v3d/v3d_drv.h
drivers/gpu/drm/v3d/v3d_perfmon.c
drivers/gpu/drm/v3d/v3d_sched.c
drivers/gpu/drm/v3d/v3d_submit.c
include/uapi/drm/v3d_drm.h

index fb35c5c3f1a7a8728b653c63aff3270043357a05..8e5cacfa38d3fe6ec9357999caa5d7b0c858d945 100644 (file)
@@ -224,6 +224,7 @@ static const struct drm_ioctl_desc v3d_drm_ioctls[] = {
        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),
+       DRM_IOCTL_DEF_DRV(V3D_PERFMON_SET_GLOBAL, v3d_perfmon_set_global_ioctl, DRM_RENDER_ALLOW),
 };
 
 static const struct drm_driver v3d_drm_driver = {
index de73eefff9ac163a3a570b62c3c809ac730adf61..dc1cfe2e14beb6a826350ab6d9c024379afad2af 100644 (file)
@@ -183,6 +183,12 @@ struct v3d_dev {
                u32 num_allocated;
                u32 pages_allocated;
        } bo_stats;
+
+       /* To support a performance analysis tool in user space, we require
+        * a single, globally configured performance monitor (perfmon) for
+        * all jobs.
+        */
+       struct v3d_perfmon *global_perfmon;
 };
 
 static inline struct v3d_dev *
@@ -594,6 +600,8 @@ 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);
+int v3d_perfmon_set_global_ioctl(struct drm_device *dev, void *data,
+                                struct drm_file *file_priv);
 
 /* v3d_sysfs.c */
 int v3d_sysfs_init(struct device *dev);
index b4c3708ea781ced4f31e5f84c3c6c55a14ed080d..a1429b9684e09d5d2bdf5dd71f80785688091a02 100644 (file)
@@ -313,6 +313,9 @@ static int v3d_perfmon_idr_del(int id, void *elem, void *data)
        if (perfmon == v3d->active_perfmon)
                v3d_perfmon_stop(v3d, perfmon, false);
 
+       /* If the global perfmon is being destroyed, set it to NULL */
+       cmpxchg(&v3d->global_perfmon, perfmon, NULL);
+
        v3d_perfmon_put(perfmon);
 
        return 0;
@@ -398,6 +401,9 @@ int v3d_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
        if (perfmon == v3d->active_perfmon)
                v3d_perfmon_stop(v3d, perfmon, false);
 
+       /* If the global perfmon is being destroyed, set it to NULL */
+       cmpxchg(&v3d->global_perfmon, perfmon, NULL);
+
        v3d_perfmon_put(perfmon);
 
        return 0;
@@ -457,3 +463,34 @@ int v3d_perfmon_get_counter_ioctl(struct drm_device *dev, void *data,
 
        return 0;
 }
+
+int v3d_perfmon_set_global_ioctl(struct drm_device *dev, void *data,
+                                struct drm_file *file_priv)
+{
+       struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
+       struct drm_v3d_perfmon_set_global *req = data;
+       struct v3d_dev *v3d = to_v3d_dev(dev);
+       struct v3d_perfmon *perfmon;
+
+       if (req->flags & ~DRM_V3D_PERFMON_CLEAR_GLOBAL)
+               return -EINVAL;
+
+       perfmon = v3d_perfmon_find(v3d_priv, req->id);
+       if (!perfmon)
+               return -EINVAL;
+
+       /* If the request is to clear the global performance monitor */
+       if (req->flags & DRM_V3D_PERFMON_CLEAR_GLOBAL) {
+               if (!v3d->global_perfmon)
+                       return -EINVAL;
+
+               xchg(&v3d->global_perfmon, NULL);
+
+               return 0;
+       }
+
+       if (cmpxchg(&v3d->global_perfmon, NULL, perfmon))
+               return -EBUSY;
+
+       return 0;
+}
index 99ac4995b5a1e0b7ad22d06dd6935bb8710d9d6f..a6c3760da6ed24a43dff17aee85aeaa65a6d9625 100644 (file)
@@ -120,11 +120,19 @@ v3d_cpu_job_free(struct drm_sched_job *sched_job)
 static void
 v3d_switch_perfmon(struct v3d_dev *v3d, struct v3d_job *job)
 {
-       if (job->perfmon != v3d->active_perfmon)
+       struct v3d_perfmon *perfmon = v3d->global_perfmon;
+
+       if (!perfmon)
+               perfmon = job->perfmon;
+
+       if (perfmon == v3d->active_perfmon)
+               return;
+
+       if (perfmon != v3d->active_perfmon)
                v3d_perfmon_stop(v3d, v3d->active_perfmon, true);
 
-       if (job->perfmon && v3d->active_perfmon != job->perfmon)
-               v3d_perfmon_start(v3d, job->perfmon);
+       if (perfmon && v3d->active_perfmon != perfmon)
+               v3d_perfmon_start(v3d, perfmon);
 }
 
 static void
index d607aa9c4ec210eeb54e4126e728b0806f9d017b..9e439c9f0a937d16338e992bc938944111fb1cbe 100644 (file)
@@ -981,6 +981,11 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
                goto fail;
 
        if (args->perfmon_id) {
+               if (v3d->global_perfmon) {
+                       ret = -EAGAIN;
+                       goto fail_perfmon;
+               }
+
                render->base.perfmon = v3d_perfmon_find(v3d_priv,
                                                        args->perfmon_id);
 
@@ -1196,6 +1201,11 @@ v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
                goto fail;
 
        if (args->perfmon_id) {
+               if (v3d->global_perfmon) {
+                       ret = -EAGAIN;
+                       goto fail_perfmon;
+               }
+
                job->base.perfmon = v3d_perfmon_find(v3d_priv,
                                                     args->perfmon_id);
                if (!job->base.perfmon) {
index 2376c73abca1ef966a1939a505f94ad57a3eac14..dbbc404d2b3dd6c8b8e3969b0b76b7d8b371dddb 100644 (file)
@@ -43,6 +43,7 @@ extern "C" {
 #define DRM_V3D_PERFMON_GET_VALUES                0x0a
 #define DRM_V3D_SUBMIT_CPU                        0x0b
 #define DRM_V3D_PERFMON_GET_COUNTER               0x0c
+#define DRM_V3D_PERFMON_SET_GLOBAL                0x0d
 
 #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)
@@ -61,6 +62,8 @@ extern "C" {
 #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_IOCTL_V3D_PERFMON_SET_GLOBAL  DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_PERFMON_SET_GLOBAL, \
+                                                  struct drm_v3d_perfmon_set_global)
 
 #define DRM_V3D_SUBMIT_CL_FLUSH_CACHE             0x01
 #define DRM_V3D_SUBMIT_EXTENSION                 0x02
@@ -766,6 +769,21 @@ struct drm_v3d_perfmon_get_counter {
        __u8 reserved[7];
 };
 
+#define DRM_V3D_PERFMON_CLEAR_GLOBAL    0x0001
+
+/**
+ * struct drm_v3d_perfmon_set_global - ioctl to define a global performance
+ * monitor
+ *
+ * The global performance monitor will be used for all jobs. If a global
+ * performance monitor is defined, jobs with a self-defined performance
+ * monitor won't be allowed.
+ */
+struct drm_v3d_perfmon_set_global {
+       __u32 flags;
+       __u32 id;
+};
+
 #if defined(__cplusplus)
 }
 #endif