drm/v3d: Decouple stats calculation from printing
authorMaíra Canal <mcanal@igalia.com>
Sat, 20 Apr 2024 21:32:12 +0000 (18:32 -0300)
committerMaíra Canal <mcanal@igalia.com>
Tue, 23 Apr 2024 22:32:48 +0000 (19:32 -0300)
Create a function to decouple the stats calculation from the printing.
This will be useful in the next step when we add a seqcount to protect
the stats.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240420213632.339941-6-mcanal@igalia.com
drivers/gpu/drm/v3d/v3d_drv.c
drivers/gpu/drm/v3d/v3d_drv.h
drivers/gpu/drm/v3d/v3d_sysfs.c

index 52e3ba9df46f233ebda0428c2c6600abc4feebcf..2ec359ed2def020d8cf39beb2ba6a55a365b597f 100644 (file)
@@ -142,6 +142,15 @@ v3d_postclose(struct drm_device *dev, struct drm_file *file)
        kfree(v3d_priv);
 }
 
+void v3d_get_stats(const struct v3d_stats *stats, u64 timestamp,
+                  u64 *active_runtime, u64 *jobs_completed)
+{
+       *active_runtime = stats->enabled_ns;
+       if (stats->start_ns)
+               *active_runtime += timestamp - stats->start_ns;
+       *jobs_completed = stats->jobs_completed;
+}
+
 static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 {
        struct v3d_file_priv *file_priv = file->driver_priv;
@@ -150,20 +159,21 @@ static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 
        for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
                struct v3d_stats *stats = &file_priv->stats[queue];
+               u64 active_runtime, jobs_completed;
+
+               v3d_get_stats(stats, timestamp, &active_runtime, &jobs_completed);
 
                /* Note that, in case of a GPU reset, the time spent during an
                 * attempt of executing the job is not computed in the runtime.
                 */
                drm_printf(p, "drm-engine-%s: \t%llu ns\n",
-                          v3d_queue_to_string(queue),
-                          stats->start_ns ? stats->enabled_ns + timestamp - stats->start_ns
-                                          : stats->enabled_ns);
+                          v3d_queue_to_string(queue), active_runtime);
 
                /* Note that we only count jobs that completed. Therefore, jobs
                 * that were resubmitted due to a GPU reset are not computed.
                 */
                drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n",
-                          v3d_queue_to_string(queue), stats->jobs_completed);
+                          v3d_queue_to_string(queue), jobs_completed);
        }
 }
 
index 5a198924d568abec84f0bc8a51b8c784bdaeae31..ff06dc1cc078a419d9766842e8cb77ac805ab25e 100644 (file)
@@ -510,6 +510,10 @@ struct drm_gem_object *v3d_prime_import_sg_table(struct drm_device *dev,
 /* v3d_debugfs.c */
 void v3d_debugfs_init(struct drm_minor *minor);
 
+/* v3d_drv.c */
+void v3d_get_stats(const struct v3d_stats *stats, u64 timestamp,
+                  u64 *active_runtime, u64 *jobs_completed);
+
 /* v3d_fence.c */
 extern const struct dma_fence_ops v3d_fence_ops;
 struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue queue);
index 6a8e7acc8b82d5e3b731932771d3f8a5a21b65f0..d610e355964ffaf45f7d44e5c667369cedc205dc 100644 (file)
@@ -15,18 +15,15 @@ gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
        struct v3d_dev *v3d = to_v3d_dev(drm);
        enum v3d_queue queue;
        u64 timestamp = local_clock();
-       u64 active_runtime;
        ssize_t len = 0;
 
        len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n");
 
        for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
                struct v3d_stats *stats = &v3d->queue[queue].stats;
+               u64 active_runtime, jobs_completed;
 
-               if (stats->start_ns)
-                       active_runtime = timestamp - stats->start_ns;
-               else
-                       active_runtime = 0;
+               v3d_get_stats(stats, timestamp, &active_runtime, &jobs_completed);
 
                /* Each line will display the queue name, timestamp, the number
                 * of jobs sent to that queue and the runtime, as can be seem here:
@@ -40,9 +37,7 @@ gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
                 */
                len += sysfs_emit_at(buf, len, "%s\t%llu\t%llu\t%llu\n",
                                     v3d_queue_to_string(queue),
-                                    timestamp,
-                                    stats->jobs_completed,
-                                    stats->enabled_ns + active_runtime);
+                                    timestamp, jobs_completed, active_runtime);
        }
 
        return len;