Signed-off-by: Tarel Ethridge <[email protected]>
---
drivers/gpu/drm/v3d/v3d_drv.h | 7 ++++++
drivers/gpu/drm/v3d/v3d_sched.c | 38 ++++++++++++++++++++++++-----
drivers/gpu/drm/v3d/v3d_submit.c | 42 +++++++++++++++++++++++++++++---
3 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/
v3d_drv.h
index 3bccb35ed..d5502b895 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.h
+++ b/drivers/gpu/drm/v3d/v3d_drv.h
@@ -367,6 +367,13 @@ struct v3d_job {
*/
struct dma_fence *done_fence;
+ /* Done fence of the previous job of the submission, if any. */
+ struct dma_fence *prev_fence;
+
+ /* Fences of the syncobjs this job waits on, as found at submit. */
+ struct dma_fence **dep_fences;
+ u32 dep_count;
+
/* Pointer to a performance monitor object if the user requested
it,
* NULL otherwise.
*/
diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/
v3d_sched.c
index f29d79b15..62b7b8987 100644
--- a/drivers/gpu/drm/v3d/v3d_sched.c
+++ b/drivers/gpu/drm/v3d/v3d_sched.c
@@ -165,6 +165,32 @@ v3d_job_update_stats(struct v3d_job *job)
preempt_enable();
}
+/*
+ * drm_sched does not propagate a failed dependency to the job that
waits on
+ * it, and the jobs of a submission run on different queues. Take the
error of
+ * the previous job of the submission, or of a syncobj it waited on,
so that
+ * this job is skipped and the fence userspace waits for reports the
failure.
+ */
+static bool v3d_job_failed(struct v3d_job *job)
+{
+ struct dma_fence *finished = &job->base.s_fence->finished;
+ int err, i;
+
+ for (i = 0; i < job->dep_count && !finished->error; i++) {
+ err = dma_fence_get_status(job->dep_fences[i]);
+ if (err < 0)
+ dma_fence_set_error(finished, err);
+ }
+
+ if (job->prev_fence) {
+ err = dma_fence_get_status(job->prev_fence);
+ if (err < 0)
+ dma_fence_set_error(finished, err);
+ }
+
+ return finished->error;
+}
+
static struct dma_fence *v3d_bin_job_run(struct drm_sched_job
*sched_job)
{
struct v3d_bin_job *job = to_bin_job(sched_job);
@@ -174,7 +200,7 @@ static struct dma_fence *v3d_bin_job_run(struct
drm_sched_job *sched_job)
struct dma_fence *fence = NULL;
unsigned long irqflags;
- if (unlikely(job->base.base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(&job->base)))
goto out_clean_job;
/* Lock required around bin_job update vs
@@ -235,7 +261,7 @@ static struct dma_fence *v3d_render_job_run(struct
drm_sched_job *sched_job)
struct drm_device *dev = &v3d->drm;
struct dma_fence *fence = NULL;
- if (unlikely(job->base.base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(&job->base)))
goto out_clean_job;
v3d->queue[V3D_RENDER].active_job = &job->base;
@@ -285,7 +311,7 @@ v3d_tfu_job_run(struct drm_sched_job *sched_job)
struct drm_device *dev = &v3d->drm;
struct dma_fence *fence = NULL;
- if (unlikely(job->base.base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(&job->base)))
goto out_clean_job;
v3d->queue[V3D_TFU].active_job = &job->base;
@@ -351,7 +377,7 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)
struct dma_fence *fence = NULL;
int i, csd_cfg0_reg;
- if (unlikely(job->base.base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(&job->base)))
goto out_clean_job;
/* The HW interprets a workgroup size of 0 as 65536; however, the
@@ -662,7 +688,7 @@ v3d_cpu_job_run(struct drm_sched_job *sched_job)
struct v3d_cpu_job *job = to_cpu_job(sched_job);
struct v3d_dev *v3d = job->base.v3d;
- if (unlikely(job->base.base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(&job->base)))
return NULL;
if (job->job_type >= ARRAY_SIZE(cpu_job_function)) {
@@ -688,7 +714,7 @@ v3d_cache_clean_job_run(struct drm_sched_job
*sched_job)
struct v3d_job *job = to_v3d_job(sched_job);
struct v3d_dev *v3d = job->v3d;
- if (unlikely(job->base.s_fence->finished.error))
+ if (unlikely(v3d_job_failed(job)))
return NULL;
v3d_job_start_stats(job);
diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/
v3d_submit.c
index eada30a31..3f464128c 100644
--- a/drivers/gpu/drm/v3d/v3d_submit.c
+++ b/drivers/gpu/drm/v3d/v3d_submit.c
@@ -141,6 +141,10 @@ v3d_job_free(struct kref *ref)
dma_fence_put(job->irq_fence);
dma_fence_put(job->done_fence);
+ dma_fence_put(job->prev_fence);
+ for (i = 0; i < job->dep_count; i++)
+ dma_fence_put(job->dep_fences[i]);
+ kfree(job->dep_fences);
if (job->perfmon)
v3d_perfmon_put(job->perfmon);
@@ -203,6 +207,34 @@ void v3d_job_put(struct v3d_job *job)
kref_put(&job->refcount, job->free);
}
+/* Remember the fence a syncobj dependency waits on, so that
run_job() can
+ * tell whether the work this job depends on failed.
+ */
+static int
+v3d_job_add_syncobj_dep(struct v3d_job *job, struct drm_file *file_priv,
+ u32 handle, u32 max_deps)
+{
+ struct dma_fence *fence = NULL;
+ int ret;
+
+ ret = drm_sched_job_add_syncobj_dependency(&job->base, file_priv,
handle, 0);
+ if (ret)
+ return ret;
+
+ if (!job->dep_fences) {
+ job->dep_fences = kcalloc(max_deps, sizeof(*job->dep_fences),
+ GFP_KERNEL);
+ if (!job->dep_fences)
+ return -ENOMEM;
+ }
+
+ if (job->dep_count < max_deps &&
+ !drm_syncobj_find_fence(file_priv, handle, 0, 0, &fence) &&
fence)
+ job->dep_fences[job->dep_count++] = fence;
+
+ return 0;
+}
+
static int
v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv,
u32 in_sync, struct v3d_submit_ext *se)
@@ -214,8 +246,7 @@ v3d_job_add_syncobjs(struct v3d_job *job, struct
drm_file *file_priv,
if (!has_multisync) {
/* Ignore syncobj if its handle is zero */
if (in_sync)
- ret = drm_sched_job_add_syncobj_dependency(&job->base,
file_priv,
- in_sync, 0);
+ ret = v3d_job_add_syncobj_dep(job, file_priv, in_sync, 1);
return ret;
}
@@ -232,8 +263,8 @@ v3d_job_add_syncobjs(struct v3d_job *job, struct
drm_file *file_priv,
/* Ignore syncobj if its handle is zero */
if (in.handle) {
- ret = drm_sched_job_add_syncobj_dependency(&job->base,
- file_priv, in.handle, 0);
+ ret = v3d_job_add_syncobj_dep(job, file_priv, in.handle,
+ se->in_sync_count);
if (ret)
return ret;
}
@@ -494,6 +525,9 @@ v3d_submit_jobs(struct v3d_submit *submit, struct
drm_syncobj *sync_out,
dma_fence_get(submit->jobs[i - 1]-
>done_fence));
if (ret)
goto err;
+
+ submit->jobs[i]->prev_fence =
+ dma_fence_get(submit->jobs[i - 1]->done_fence);
}
for (int i = 0; i < submit->job_count; i++) {