drm/scheduler: track GPU active time per entity
authorLucas Stach <l.stach@pengutronix.de>
Wed, 1 Feb 2023 15:26:07 +0000 (16:26 +0100)
committerLucas Stach <l.stach@pengutronix.de>
Tue, 7 Feb 2023 19:49:20 +0000 (20:49 +0100)
Track the accumulated time that jobs from this entity were active
on the GPU. This allows drivers using the scheduler to trivially
implement the DRM fdinfo when the hardware doesn't provide more
specific information than signalling job completion anyways.

[Bagas: Append missing colon to @elapsed_ns]
Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
drivers/gpu/drm/scheduler/sched_main.c
include/drm/gpu_scheduler.h

index 31f3a12..cc5e77a 100644 (file)
@@ -895,6 +895,12 @@ drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched)
 
        spin_unlock(&sched->job_list_lock);
 
+       if (job) {
+               job->entity->elapsed_ns += ktime_to_ns(
+                       ktime_sub(job->s_fence->finished.timestamp,
+                                 job->s_fence->scheduled.timestamp));
+       }
+
        return job;
 }
 
index ca857ec..aa771e0 100644 (file)
@@ -228,6 +228,13 @@ struct drm_sched_entity {
         */
        struct rb_node                  rb_tree_node;
 
+       /**
+        * @elapsed_ns:
+        *
+        * Records the amount of time where jobs from this entity were active
+        * on the GPU.
+        */
+       uint64_t elapsed_ns;
 };
 
 /**