v3d_priv->v3d = v3d;
for (i = 0; i < V3D_MAX_QUEUES; i++) {
+ v3d_priv->stats[i] = v3d_stats_alloc();
+ if (!v3d_priv->stats[i]) {
+ ret = -ENOMEM;
+ goto err_stats;
+ }
+
sched = &v3d->queue[i].sched;
ret = drm_sched_entity_init(&v3d_priv->sched_entity[i],
DRM_SCHED_PRIORITY_NORMAL, &sched,
1, NULL);
if (ret)
goto err_sched;
-
- memset(&v3d_priv->stats[i], 0, sizeof(v3d_priv->stats[i]));
- seqcount_init(&v3d_priv->stats[i].lock);
}
v3d_perfmon_open_file(v3d_priv);
return 0;
err_sched:
- for (i--; i >= 0; i--)
+ v3d_stats_put(v3d_priv->stats[i]);
+err_stats:
+ for (i--; i >= 0; i--) {
drm_sched_entity_destroy(&v3d_priv->sched_entity[i]);
+ v3d_stats_put(v3d_priv->stats[i]);
+ }
kfree(v3d_priv);
return ret;
}
job->file_priv = NULL;
spin_unlock_irqrestore(&queue->queue_lock, irqflags);
}
+
+ v3d_stats_put(v3d_priv->stats[q]);
}
v3d_perfmon_close_file(v3d_priv);
enum v3d_queue queue;
for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
- struct v3d_stats *stats = &file_priv->stats[queue];
+ struct v3d_stats *stats = file_priv->stats[queue];
u64 active_runtime, jobs_completed;
v3d_get_stats(stats, timestamp, &active_runtime, &jobs_completed);
}
struct v3d_stats {
+ struct kref refcount;
+
u64 start_ns;
u64 enabled_ns;
u64 jobs_completed;
u64 emit_seqno;
/* Stores the GPU stats for this queue in the global context. */
- struct v3d_stats stats;
+ struct v3d_stats *stats;
/* Currently active job for this queue */
struct v3d_job *active_job;
struct drm_sched_entity sched_entity[V3D_MAX_QUEUES];
/* Stores the GPU stats for a specific queue for this fd. */
- struct v3d_stats stats[V3D_MAX_QUEUES];
+ struct v3d_stats *stats[V3D_MAX_QUEUES];
/* Per-fd reset counter, must be incremented when a job submitted
* by this fd causes a GPU reset. It must be protected by
unsigned int count);
void v3d_performance_query_info_free(struct v3d_performance_query_info *query_info,
unsigned int count);
+struct v3d_stats *v3d_stats_alloc(void);
+void v3d_stats_release(struct kref *refcount);
void v3d_job_update_stats(struct v3d_job *job, enum v3d_queue q);
int v3d_sched_init(struct v3d_dev *v3d);
void v3d_sched_fini(struct v3d_dev *v3d);
+static inline struct v3d_stats *v3d_stats_get(struct v3d_stats *stats)
+{
+ kref_get(&stats->refcount);
+ return stats;
+}
+
+static inline void v3d_stats_put(struct v3d_stats *stats)
+{
+ kref_put(&stats->refcount, v3d_stats_release);
+}
+
/* v3d_perfmon.c */
void v3d_perfmon_init(struct v3d_dev *v3d);
void v3d_perfmon_get(struct v3d_perfmon *perfmon);
for (i = 0; i < V3D_MAX_QUEUES; i++) {
struct v3d_queue_state *queue = &v3d->queue[i];
+ queue->stats = v3d_stats_alloc();
+ if (!queue->stats) {
+ ret = -ENOMEM;
+ goto err_stats;
+ }
+
queue->fence_context = dma_fence_context_alloc(1);
- memset(&queue->stats, 0, sizeof(queue->stats));
- seqcount_init(&queue->stats.lock);
spin_lock_init(&queue->queue_lock);
spin_lock_init(&queue->fence_lock);
spin_lock_init(&v3d->mm_lock);
ret = drmm_mutex_init(dev, &v3d->bo_lock);
if (ret)
- return ret;
+ goto err_stats;
ret = drmm_mutex_init(dev, &v3d->reset_lock);
if (ret)
- return ret;
+ goto err_stats;
ret = drmm_mutex_init(dev, &v3d->sched_lock);
if (ret)
- return ret;
+ goto err_stats;
ret = drmm_mutex_init(dev, &v3d->cache_clean_lock);
if (ret)
- return ret;
+ goto err_stats;
/* Note: We don't allocate address 0. Various bits of HW
* treat 0 as special, such as the occlusion query counters
&v3d->pt_paddr,
GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO);
if (!v3d->pt) {
- drm_mm_takedown(&v3d->mm);
dev_err(v3d->drm.dev,
"Failed to allocate page tables. Please ensure you have DMA enabled.\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_dma_alloc;
}
v3d_init_hw_state(v3d);
v3d_huge_mnt_init(v3d);
ret = v3d_sched_init(v3d);
- if (ret) {
- drm_mm_takedown(&v3d->mm);
- dma_free_coherent(v3d->drm.dev, pt_size, (void *)v3d->pt,
- v3d->pt_paddr);
- return ret;
- }
+ if (ret)
+ goto err_sched;
return 0;
+
+err_sched:
+ dma_free_coherent(v3d->drm.dev, pt_size, (void *)v3d->pt, v3d->pt_paddr);
+err_dma_alloc:
+ drm_mm_takedown(&v3d->mm);
+err_stats:
+ for (i--; i >= 0; i--)
+ v3d_stats_put(v3d->queue[i].stats);
+
+ return ret;
}
void
/* Waiting for jobs to finish would need to be done before
* unregistering V3D.
*/
- for (q = 0; q < V3D_MAX_QUEUES; q++)
+ for (q = 0; q < V3D_MAX_QUEUES; q++) {
WARN_ON(v3d->queue[q].active_job);
+ v3d_stats_put(v3d->queue[q].stats);
+ }
drm_mm_takedown(&v3d->mm);
return container_of(sched_job, struct v3d_cpu_job, base.base);
}
+void v3d_stats_release(struct kref *refcount)
+{
+ struct v3d_stats *stats = container_of(refcount, typeof(*stats), refcount);
+
+ kfree(stats);
+}
+
+struct v3d_stats *v3d_stats_alloc(void)
+{
+ struct v3d_stats *stats;
+
+ stats = kzalloc_obj(*stats);
+ if (!stats)
+ return NULL;
+
+ kref_init(&stats->refcount);
+ seqcount_init(&stats->lock);
+
+ return stats;
+}
+
static void
v3d_sched_job_free(struct drm_sched_job *sched_job)
{
{
struct v3d_dev *v3d = job->v3d;
struct v3d_file_priv *file = job->file_priv;
- struct v3d_stats *global_stats = &v3d->queue[queue].stats;
- struct v3d_stats *local_stats = &file->stats[queue];
+ struct v3d_stats *global_stats = v3d->queue[queue].stats;
+ struct v3d_stats *local_stats = file->stats[queue];
u64 now = local_clock();
preempt_disable();
{
struct v3d_dev *v3d = job->v3d;
struct v3d_queue_state *queue = &v3d->queue[q];
- struct v3d_stats *global_stats = &queue->stats;
+ struct v3d_stats *global_stats = queue->stats;
u64 now = local_clock();
preempt_disable();
/* Don't update the local stats if the file context has already closed */
spin_lock(&queue->queue_lock);
if (job->file_priv)
- v3d_stats_update(&job->file_priv->stats[q], now);
+ v3d_stats_update(job->file_priv->stats[q], now);
spin_unlock(&queue->queue_lock);
v3d_stats_update(global_stats, now);
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;
+ struct v3d_stats *stats = v3d->queue[queue].stats;
u64 active_runtime, jobs_completed;
v3d_get_stats(stats, timestamp, &active_runtime, &jobs_completed);