On 12/11/2026 17:11, Sidong Yang wrote:
The scheduler accumulates the time each entity's jobs spend on the
hardware for the fair policy, but drivers cannot read it. Export it so
drivers can report per-client engine time through fdinfo without
keeping their own counter.

The stats object is refcounted and held by the entity and its jobs, so
unlike commit df622729ddbf ("drm/scheduler: track GPU active time per
entity"), which was reverted, accounting a job does not touch the
entity.

Suggested-by: Tvrtko Ursulin <[email protected]>
Signed-off-by: Sidong Yang <[email protected]>
---
  drivers/gpu/drm/scheduler/sched_entity.c | 25 ++++++++++++++++++++++++
  include/drm/gpu_scheduler.h              |  1 +
  2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c 
b/drivers/gpu/drm/scheduler/sched_entity.c
index 03e68b4102d5..ac040f95876a 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -238,6 +238,31 @@ int drm_sched_entity_error(struct drm_sched_entity *entity)
  }
  EXPORT_SYMBOL(drm_sched_entity_error);
+/**
+ * drm_sched_entity_get_runtime - Get the time an entity's jobs have run
+ * @entity: scheduler entity
+ *
+ * Returns the time the jobs of @entity have spent on the hardware, measured
+ * from the scheduled to the finished fence of each job. A job is accounted
+ * when the scheduler frees it.
+ *
+ * The caller must ensure @entity has not been finalized.
+ *
+ * Return: Accumulated runtime in nanoseconds.
+ */
+u64 drm_sched_entity_get_runtime(struct drm_sched_entity *entity)
+{
+       struct drm_sched_entity_stats *stats = entity->stats;
+       ktime_t runtime;
+
+       spin_lock(&stats->lock);
+       runtime = stats->runtime;
+       spin_unlock(&stats->lock);
+
+       return ktime_to_ns(runtime);
+}
+EXPORT_SYMBOL(drm_sched_entity_get_runtime);
+
  static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f,
                                          struct dma_fence_cb *cb);
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index 3b0978fa8cf0..96a3401d4c88 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -730,6 +730,7 @@ void drm_sched_entity_destroy(struct drm_sched_entity 
*entity);
  void drm_sched_entity_set_priority(struct drm_sched_entity *entity,
                                   enum drm_sched_priority priority);
  int drm_sched_entity_error(struct drm_sched_entity *entity);
+u64 drm_sched_entity_get_runtime(struct drm_sched_entity *entity);
  void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
                                   struct drm_gpu_scheduler **sched_list,
                                   unsigned int num_sched_list);

LGTM.

Reviewed-by: Tvrtko Ursulin <[email protected]>

Regards,

Tvrtko

Reply via email to