Re: [PATCH v5 1/2] drm/sched: Add drm_sched_entity_get_runtime()

From: Philipp Stanner

Date: Wed Nov 18 2026 - 12:14:04 EST


On Fri, 2026-11-13 at 02:11 +0900, 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.

In general looks good to me, no objections.

But a question below:

>
> Suggested-by: Tvrtko Ursulin <tursulin@xxxxxxxxxxx>
> Signed-off-by: Sidong Yang <sidong.yang@xxxxxxxxxx>


> +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);

Why not return it as ktime_t?

ktime_t, I suppose, is the universal time unit in the kernel, and the
user can use one of the converters to turn it into whatever is desired.

With ns you would have to write the converters yourself.

P.