Skip to content

Commit

Permalink
drm/v3d: Decouple stats calculation from printing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mairacanal committed Apr 23, 2024
1 parent da483d0 commit 12d1624
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
18 changes: 14 additions & 4 deletions drivers/gpu/drm/v3d/v3d_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/v3d/v3d_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions drivers/gpu/drm/v3d/v3d_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down

0 comments on commit 12d1624

Please sign in to comment.