Message ID | 20240420213632.339941-6-mcanal@igalia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/v3d: Fix GPU stats inconsistencies and race-condition | expand |
On 20/04/2024 22:32, Maíra Canal wrote: > 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> > --- > drivers/gpu/drm/v3d/v3d_drv.c | 18 ++++++++++++++---- > drivers/gpu/drm/v3d/v3d_drv.h | 4 ++++ > drivers/gpu/drm/v3d/v3d_sysfs.c | 11 +++-------- > 3 files changed, 21 insertions(+), 12 deletions(-) > > diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c > index 52e3ba9df46f..2ec359ed2def 100644 > --- a/drivers/gpu/drm/v3d/v3d_drv.c > +++ b/drivers/gpu/drm/v3d/v3d_drv.c > @@ -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; > @@ -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); > } > } > > diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h > index 5a198924d568..ff06dc1cc078 100644 > --- a/drivers/gpu/drm/v3d/v3d_drv.h > +++ b/drivers/gpu/drm/v3d/v3d_drv.h > @@ -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); > diff --git a/drivers/gpu/drm/v3d/v3d_sysfs.c b/drivers/gpu/drm/v3d/v3d_sysfs.c > index 6a8e7acc8b82..d610e355964f 100644 > --- a/drivers/gpu/drm/v3d/v3d_sysfs.c > +++ b/drivers/gpu/drm/v3d/v3d_sysfs.c > @@ -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: > @@ -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; Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Regards, Tvrtko
diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c index 52e3ba9df46f..2ec359ed2def 100644 --- a/drivers/gpu/drm/v3d/v3d_drv.c +++ b/drivers/gpu/drm/v3d/v3d_drv.c @@ -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; @@ -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); } } diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h index 5a198924d568..ff06dc1cc078 100644 --- a/drivers/gpu/drm/v3d/v3d_drv.h +++ b/drivers/gpu/drm/v3d/v3d_drv.h @@ -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); diff --git a/drivers/gpu/drm/v3d/v3d_sysfs.c b/drivers/gpu/drm/v3d/v3d_sysfs.c index 6a8e7acc8b82..d610e355964f 100644 --- a/drivers/gpu/drm/v3d/v3d_sysfs.c +++ b/drivers/gpu/drm/v3d/v3d_sysfs.c @@ -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: @@ -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;
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> --- drivers/gpu/drm/v3d/v3d_drv.c | 18 ++++++++++++++---- drivers/gpu/drm/v3d/v3d_drv.h | 4 ++++ drivers/gpu/drm/v3d/v3d_sysfs.c | 11 +++-------- 3 files changed, 21 insertions(+), 12 deletions(-)