2018-05-08 14:20:54 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-12-04 17:41:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Etnaviv Project
|
|
|
|
*/
|
|
|
|
|
2019-07-04 10:43:37 +00:00
|
|
|
#include <linux/moduleparam.h>
|
2017-12-04 17:41:58 +00:00
|
|
|
|
|
|
|
#include "etnaviv_drv.h"
|
2017-12-06 09:53:27 +00:00
|
|
|
#include "etnaviv_dump.h"
|
2017-12-04 17:41:58 +00:00
|
|
|
#include "etnaviv_gem.h"
|
|
|
|
#include "etnaviv_gpu.h"
|
2017-12-06 09:53:27 +00:00
|
|
|
#include "etnaviv_sched.h"
|
2018-06-27 13:58:13 +00:00
|
|
|
#include "state.xml.h"
|
2017-12-04 17:41:58 +00:00
|
|
|
|
|
|
|
static int etnaviv_job_hang_limit = 0;
|
|
|
|
module_param_named(job_hang_limit, etnaviv_job_hang_limit, int , 0444);
|
2018-03-09 13:29:26 +00:00
|
|
|
static int etnaviv_hw_jobs_limit = 4;
|
2017-12-04 17:41:58 +00:00
|
|
|
module_param_named(hw_job_limit, etnaviv_hw_jobs_limit, int , 0444);
|
|
|
|
|
2018-02-13 18:36:49 +00:00
|
|
|
static struct dma_fence *etnaviv_sched_run_job(struct drm_sched_job *sched_job)
|
2017-12-04 17:41:58 +00:00
|
|
|
{
|
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
2017-12-06 09:53:27 +00:00
|
|
|
struct dma_fence *fence = NULL;
|
2017-12-04 17:41:58 +00:00
|
|
|
|
2017-12-06 09:53:27 +00:00
|
|
|
if (likely(!sched_job->s_fence->finished.error))
|
|
|
|
fence = etnaviv_gpu_submit(submit);
|
|
|
|
else
|
|
|
|
dev_dbg(submit->gpu->dev, "skipping bad job\n");
|
2017-12-04 17:41:58 +00:00
|
|
|
|
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
2021-01-20 20:09:59 +00:00
|
|
|
static enum drm_gpu_sched_stat etnaviv_sched_timedout_job(struct drm_sched_job
|
|
|
|
*sched_job)
|
2017-12-04 17:41:58 +00:00
|
|
|
{
|
2017-12-06 09:53:27 +00:00
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
|
|
|
struct etnaviv_gpu *gpu = submit->gpu;
|
2018-06-27 13:58:13 +00:00
|
|
|
u32 dma_addr;
|
|
|
|
int change;
|
|
|
|
|
2020-08-24 10:55:37 +00:00
|
|
|
/* block scheduler */
|
|
|
|
drm_sched_stop(&gpu->sched, sched_job);
|
|
|
|
|
2018-06-27 13:58:13 +00:00
|
|
|
/*
|
|
|
|
* If the GPU managed to complete this jobs fence, the timout is
|
|
|
|
* spurious. Bail out.
|
|
|
|
*/
|
2018-10-04 09:37:00 +00:00
|
|
|
if (dma_fence_is_signaled(submit->out_fence))
|
2020-08-24 10:55:37 +00:00
|
|
|
goto out_no_timeout;
|
2018-06-27 13:58:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the GPU is still making forward progress on the front-end (which
|
|
|
|
* should never loop) we shift out the timeout to give it a chance to
|
|
|
|
* finish the job.
|
|
|
|
*/
|
|
|
|
dma_addr = gpu_read(gpu, VIVS_FE_DMA_ADDRESS);
|
|
|
|
change = dma_addr - gpu->hangcheck_dma_addr;
|
2021-12-22 00:17:28 +00:00
|
|
|
if (gpu->completed_fence != gpu->hangcheck_fence ||
|
|
|
|
change < 0 || change > 16) {
|
2018-06-27 13:58:13 +00:00
|
|
|
gpu->hangcheck_dma_addr = dma_addr;
|
2021-12-22 00:17:28 +00:00
|
|
|
gpu->hangcheck_fence = gpu->completed_fence;
|
2020-08-24 10:55:37 +00:00
|
|
|
goto out_no_timeout;
|
2018-06-27 13:58:13 +00:00
|
|
|
}
|
2017-12-06 09:53:27 +00:00
|
|
|
|
2018-12-04 21:56:14 +00:00
|
|
|
if(sched_job)
|
|
|
|
drm_sched_increase_karma(sched_job);
|
2017-12-06 09:53:27 +00:00
|
|
|
|
|
|
|
/* get the GPU back into the init state */
|
2019-08-09 11:58:02 +00:00
|
|
|
etnaviv_core_dump(submit);
|
2022-06-03 12:37:05 +00:00
|
|
|
etnaviv_gpu_recover_hang(submit);
|
2017-12-06 09:53:27 +00:00
|
|
|
|
2018-12-04 21:56:14 +00:00
|
|
|
drm_sched_resubmit_jobs(&gpu->sched);
|
|
|
|
|
2021-01-20 20:09:59 +00:00
|
|
|
drm_sched_start(&gpu->sched, true);
|
|
|
|
return DRM_GPU_SCHED_STAT_NOMINAL;
|
|
|
|
|
2020-08-24 10:55:37 +00:00
|
|
|
out_no_timeout:
|
2017-12-06 09:53:27 +00:00
|
|
|
/* restart scheduler after GPU is usable again */
|
2018-12-04 21:56:14 +00:00
|
|
|
drm_sched_start(&gpu->sched, true);
|
2021-01-20 20:09:59 +00:00
|
|
|
return DRM_GPU_SCHED_STAT_NOMINAL;
|
2017-12-04 17:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void etnaviv_sched_free_job(struct drm_sched_job *sched_job)
|
|
|
|
{
|
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
|
|
|
|
2018-10-29 09:32:28 +00:00
|
|
|
drm_sched_job_cleanup(sched_job);
|
|
|
|
|
2017-12-04 17:41:58 +00:00
|
|
|
etnaviv_submit_put(submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_sched_backend_ops etnaviv_sched_ops = {
|
|
|
|
.run_job = etnaviv_sched_run_job,
|
|
|
|
.timedout_job = etnaviv_sched_timedout_job,
|
|
|
|
.free_job = etnaviv_sched_free_job,
|
|
|
|
};
|
|
|
|
|
2022-03-31 20:46:48 +00:00
|
|
|
int etnaviv_sched_push_job(struct etnaviv_gem_submit *submit)
|
2017-12-04 17:41:58 +00:00
|
|
|
{
|
2018-05-25 14:51:25 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hold the fence lock across the whole operation to avoid jobs being
|
|
|
|
* pushed out of order with regard to their sched fence seqnos as
|
2022-03-31 20:46:48 +00:00
|
|
|
* allocated in drm_sched_job_arm.
|
2018-05-25 14:51:25 +00:00
|
|
|
*/
|
|
|
|
mutex_lock(&submit->gpu->fence_lock);
|
2017-12-04 17:41:58 +00:00
|
|
|
|
drm/sched: Split drm_sched_job_init
This is a very confusingly named function, because not just does it
init an object, it arms it and provides a point of no return for
pushing a job into the scheduler. It would be nice if that's a bit
clearer in the interface.
But the real reason is that I want to push the dependency tracking
helpers into the scheduler code, and that means drm_sched_job_init
must be called a lot earlier, without arming the job.
v2:
- don't change .gitignore (Steven)
- don't forget v3d (Emma)
v3: Emma noticed that I leak the memory allocated in
drm_sched_job_init if we bail out before the point of no return in
subsequent driver patches. To be able to fix this change
drm_sched_job_cleanup() so it can handle being called both before and
after drm_sched_job_arm().
Also improve the kerneldoc for this.
v4:
- Fix the drm_sched_job_cleanup logic, I inverted the booleans, as
usual (Melissa)
- Christian pointed out that drm_sched_entity_select_rq() also needs
to be moved into drm_sched_job_arm, which made me realize that the
job->id definitely needs to be moved too.
Shuffle things to fit between job_init and job_arm.
v5:
Reshuffle the split between init/arm once more, amdgpu abuses
drm_sched.ready to signal gpu reset failures. Also document this
somewhat. (Christian)
v6:
Rebase on top of the msm drm/sched support. Note that the
drm_sched_job_init() call is completely misplaced, and hence also the
split-out drm_sched_entity_push_job(). I've put in a FIXME which the next
patch will address.
v7: Drop the FIXME in msm, after discussions with Rob I agree it shouldn't
be a problem where it is now.
Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Melissa Wen <mwen@igalia.com>
Cc: Melissa Wen <melissa.srw@gmail.com>
Acked-by: Emma Anholt <emma@anholt.net>
Acked-by: Steven Price <steven.price@arm.com> (v2)
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> (v5)
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Russell King <linux+etnaviv@armlinux.org.uk>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Qiang Yu <yuq825@gmail.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Adam Borowski <kilobyte@angband.pl>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Paul Menzel <pmenzel@molgen.mpg.de>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Nirmoy Das <nirmoy.das@amd.com>
Cc: Deepak R Varma <mh12gx2825@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Kevin Wang <kevin1.wang@amd.com>
Cc: Chen Li <chenli@uniontech.com>
Cc: Luben Tuikov <luben.tuikov@amd.com>
Cc: "Marek Olšák" <marek.olsak@amd.com>
Cc: Dennis Li <Dennis.Li@amd.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Cc: Sonny Jiang <sonny.jiang@amd.com>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Tian Tao <tiantao6@hisilicon.com>
Cc: etnaviv@lists.freedesktop.org
Cc: lima@lists.freedesktop.org
Cc: linux-media@vger.kernel.org
Cc: linaro-mm-sig@lists.linaro.org
Cc: Emma Anholt <emma@anholt.net>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <sean@poorly.run>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Link: https://patchwork.freedesktop.org/patch/msgid/20210817084917.3555822-1-daniel.vetter@ffwll.ch
2021-08-17 08:49:16 +00:00
|
|
|
drm_sched_job_arm(&submit->sched_job);
|
|
|
|
|
2017-12-04 17:41:58 +00:00
|
|
|
submit->out_fence = dma_fence_get(&submit->sched_job.s_fence->finished);
|
|
|
|
submit->out_fence_id = idr_alloc_cyclic(&submit->gpu->fence_idr,
|
|
|
|
submit->out_fence, 0,
|
|
|
|
INT_MAX, GFP_KERNEL);
|
2018-05-25 14:51:25 +00:00
|
|
|
if (submit->out_fence_id < 0) {
|
2018-10-29 09:32:28 +00:00
|
|
|
drm_sched_job_cleanup(&submit->sched_job);
|
2018-05-25 14:51:25 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2017-12-04 17:41:58 +00:00
|
|
|
|
|
|
|
/* the scheduler holds on to the job now */
|
|
|
|
kref_get(&submit->refcount);
|
|
|
|
|
2021-08-05 10:46:50 +00:00
|
|
|
drm_sched_entity_push_job(&submit->sched_job);
|
2017-12-04 17:41:58 +00:00
|
|
|
|
2018-05-25 14:51:25 +00:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&submit->gpu->fence_lock);
|
|
|
|
|
|
|
|
return ret;
|
2017-12-04 17:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int etnaviv_sched_init(struct etnaviv_gpu *gpu)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_sched_init(&gpu->sched, &etnaviv_sched_ops,
|
|
|
|
etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,
|
2021-06-30 06:27:37 +00:00
|
|
|
msecs_to_jiffies(500), NULL, NULL,
|
2022-02-22 09:42:52 +00:00
|
|
|
dev_name(gpu->dev), gpu->dev);
|
2017-12-04 17:41:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void etnaviv_sched_fini(struct etnaviv_gpu *gpu)
|
|
|
|
{
|
|
|
|
drm_sched_fini(&gpu->sched);
|
|
|
|
}
|