Commit b136b195 authored by Maíra Canal's avatar Maíra Canal

drm/v3d: Create a struct to store the GPU stats

This will make it easier to instantiate the GPU stats variables and it
will create a structure where we can store all the variables that refer
to GPU stats.

Note that, when we created the struct `v3d_stats`, we renamed
`jobs_sent` to `jobs_completed`. This better express the semantics of
the variable, as we are only accounting jobs that have been completed.
Signed-off-by: default avatarMaíra Canal <mcanal@igalia.com>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: default avatarJose Maria Casanova Crespo <jmcasanova@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240420213632.339941-4-mcanal@igalia.com
parent 52ce9776
...@@ -115,14 +115,12 @@ v3d_open(struct drm_device *dev, struct drm_file *file) ...@@ -115,14 +115,12 @@ v3d_open(struct drm_device *dev, struct drm_file *file)
v3d_priv->v3d = v3d; v3d_priv->v3d = v3d;
for (i = 0; i < V3D_MAX_QUEUES; i++) { for (i = 0; i < V3D_MAX_QUEUES; i++) {
v3d_priv->enabled_ns[i] = 0;
v3d_priv->start_ns[i] = 0;
v3d_priv->jobs_sent[i] = 0;
sched = &v3d->queue[i].sched; sched = &v3d->queue[i].sched;
drm_sched_entity_init(&v3d_priv->sched_entity[i], drm_sched_entity_init(&v3d_priv->sched_entity[i],
DRM_SCHED_PRIORITY_NORMAL, &sched, DRM_SCHED_PRIORITY_NORMAL, &sched,
1, NULL); 1, NULL);
memset(&v3d_priv->stats[i], 0, sizeof(v3d_priv->stats[i]));
} }
v3d_perfmon_open_file(v3d_priv); v3d_perfmon_open_file(v3d_priv);
...@@ -151,20 +149,21 @@ static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file) ...@@ -151,20 +149,21 @@ static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
enum v3d_queue queue; enum v3d_queue queue;
for (queue = 0; queue < V3D_MAX_QUEUES; queue++) { for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
struct v3d_stats *stats = &file_priv->stats[queue];
/* Note that, in case of a GPU reset, the time spent during an /* Note that, in case of a GPU reset, the time spent during an
* attempt of executing the job is not computed in the runtime. * attempt of executing the job is not computed in the runtime.
*/ */
drm_printf(p, "drm-engine-%s: \t%llu ns\n", drm_printf(p, "drm-engine-%s: \t%llu ns\n",
v3d_queue_to_string(queue), v3d_queue_to_string(queue),
file_priv->start_ns[queue] ? file_priv->enabled_ns[queue] stats->start_ns ? stats->enabled_ns + timestamp - stats->start_ns
+ timestamp - file_priv->start_ns[queue] : stats->enabled_ns);
: file_priv->enabled_ns[queue]);
/* Note that we only count jobs that completed. Therefore, jobs /* Note that we only count jobs that completed. Therefore, jobs
* that were resubmitted due to a GPU reset are not computed. * that were resubmitted due to a GPU reset are not computed.
*/ */
drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n", drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n",
v3d_queue_to_string(queue), file_priv->jobs_sent[queue]); v3d_queue_to_string(queue), stats->jobs_completed);
} }
} }
......
...@@ -36,15 +36,20 @@ static inline char *v3d_queue_to_string(enum v3d_queue queue) ...@@ -36,15 +36,20 @@ static inline char *v3d_queue_to_string(enum v3d_queue queue)
return "UNKNOWN"; return "UNKNOWN";
} }
struct v3d_stats {
u64 start_ns;
u64 enabled_ns;
u64 jobs_completed;
};
struct v3d_queue_state { struct v3d_queue_state {
struct drm_gpu_scheduler sched; struct drm_gpu_scheduler sched;
u64 fence_context; u64 fence_context;
u64 emit_seqno; u64 emit_seqno;
u64 start_ns; /* Stores the GPU stats for this queue in the global context. */
u64 enabled_ns; struct v3d_stats stats;
u64 jobs_sent;
}; };
/* Performance monitor object. The perform lifetime is controlled by userspace /* Performance monitor object. The perform lifetime is controlled by userspace
...@@ -188,11 +193,8 @@ struct v3d_file_priv { ...@@ -188,11 +193,8 @@ struct v3d_file_priv {
struct drm_sched_entity sched_entity[V3D_MAX_QUEUES]; struct drm_sched_entity sched_entity[V3D_MAX_QUEUES];
u64 start_ns[V3D_MAX_QUEUES]; /* Stores the GPU stats for a specific queue for this fd. */
struct v3d_stats stats[V3D_MAX_QUEUES];
u64 enabled_ns[V3D_MAX_QUEUES];
u64 jobs_sent[V3D_MAX_QUEUES];
}; };
struct v3d_bo { struct v3d_bo {
......
...@@ -247,10 +247,10 @@ v3d_gem_init(struct drm_device *dev) ...@@ -247,10 +247,10 @@ v3d_gem_init(struct drm_device *dev)
int ret, i; int ret, i;
for (i = 0; i < V3D_MAX_QUEUES; i++) { for (i = 0; i < V3D_MAX_QUEUES; i++) {
v3d->queue[i].fence_context = dma_fence_context_alloc(1); struct v3d_queue_state *queue = &v3d->queue[i];
v3d->queue[i].start_ns = 0;
v3d->queue[i].enabled_ns = 0; queue->fence_context = dma_fence_context_alloc(1);
v3d->queue[i].jobs_sent = 0; memset(&queue->stats, 0, sizeof(queue->stats));
} }
spin_lock_init(&v3d->mm_lock); spin_lock_init(&v3d->mm_lock);
......
...@@ -110,10 +110,12 @@ v3d_job_start_stats(struct v3d_job *job, enum v3d_queue queue) ...@@ -110,10 +110,12 @@ v3d_job_start_stats(struct v3d_job *job, enum v3d_queue queue)
{ {
struct v3d_dev *v3d = job->v3d; struct v3d_dev *v3d = job->v3d;
struct v3d_file_priv *file = job->file->driver_priv; struct v3d_file_priv *file = job->file->driver_priv;
struct v3d_stats *global_stats = &v3d->queue[queue].stats;
struct v3d_stats *local_stats = &file->stats[queue];
u64 now = local_clock(); u64 now = local_clock();
file->start_ns[queue] = now; local_stats->start_ns = now;
v3d->queue[queue].start_ns = now; global_stats->start_ns = now;
} }
void void
...@@ -121,15 +123,17 @@ v3d_job_update_stats(struct v3d_job *job, enum v3d_queue queue) ...@@ -121,15 +123,17 @@ v3d_job_update_stats(struct v3d_job *job, enum v3d_queue queue)
{ {
struct v3d_dev *v3d = job->v3d; struct v3d_dev *v3d = job->v3d;
struct v3d_file_priv *file = job->file->driver_priv; struct v3d_file_priv *file = job->file->driver_priv;
struct v3d_stats *global_stats = &v3d->queue[queue].stats;
struct v3d_stats *local_stats = &file->stats[queue];
u64 now = local_clock(); u64 now = local_clock();
file->enabled_ns[queue] += now - file->start_ns[queue]; local_stats->enabled_ns += now - local_stats->start_ns;
file->jobs_sent[queue]++; local_stats->jobs_completed++;
file->start_ns[queue] = 0; local_stats->start_ns = 0;
v3d->queue[queue].enabled_ns += now - v3d->queue[queue].start_ns; global_stats->enabled_ns += now - global_stats->start_ns;
v3d->queue[queue].jobs_sent++; global_stats->jobs_completed++;
v3d->queue[queue].start_ns = 0; global_stats->start_ns = 0;
} }
static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job) static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)
......
...@@ -21,8 +21,10 @@ gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -21,8 +21,10 @@ gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n"); len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n");
for (queue = 0; queue < V3D_MAX_QUEUES; queue++) { for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
if (v3d->queue[queue].start_ns) struct v3d_stats *stats = &v3d->queue[queue].stats;
active_runtime = timestamp - v3d->queue[queue].start_ns;
if (stats->start_ns)
active_runtime = timestamp - stats->start_ns;
else else
active_runtime = 0; active_runtime = 0;
...@@ -39,8 +41,8 @@ gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -39,8 +41,8 @@ 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", len += sysfs_emit_at(buf, len, "%s\t%llu\t%llu\t%llu\n",
v3d_queue_to_string(queue), v3d_queue_to_string(queue),
timestamp, timestamp,
v3d->queue[queue].jobs_sent, stats->jobs_completed,
v3d->queue[queue].enabled_ns + active_runtime); stats->enabled_ns + active_runtime);
} }
return len; return len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment