2018-05-08 21:20:54 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-12-05 00:41:58 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Etnaviv Project
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
|
|
|
|
#include "etnaviv_drv.h"
|
2017-12-06 16:53:27 +07:00
|
|
|
#include "etnaviv_dump.h"
|
2017-12-05 00:41:58 +07:00
|
|
|
#include "etnaviv_gem.h"
|
|
|
|
#include "etnaviv_gpu.h"
|
2017-12-06 16:53:27 +07:00
|
|
|
#include "etnaviv_sched.h"
|
2018-06-27 20:58:13 +07:00
|
|
|
#include "state.xml.h"
|
2017-12-05 00:41:58 +07:00
|
|
|
|
|
|
|
static int etnaviv_job_hang_limit = 0;
|
|
|
|
module_param_named(job_hang_limit, etnaviv_job_hang_limit, int , 0444);
|
2018-03-09 20:29:26 +07:00
|
|
|
static int etnaviv_hw_jobs_limit = 4;
|
2017-12-05 00:41:58 +07:00
|
|
|
module_param_named(hw_job_limit, etnaviv_hw_jobs_limit, int , 0444);
|
|
|
|
|
2018-02-14 01:36:49 +07:00
|
|
|
static struct dma_fence *
|
|
|
|
etnaviv_sched_dependency(struct drm_sched_job *sched_job,
|
|
|
|
struct drm_sched_entity *entity)
|
2017-12-05 00:41:58 +07:00
|
|
|
{
|
2017-12-05 01:24:06 +07:00
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
|
|
|
struct dma_fence *fence;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (unlikely(submit->in_fence)) {
|
|
|
|
fence = submit->in_fence;
|
|
|
|
submit->in_fence = NULL;
|
|
|
|
|
|
|
|
if (!dma_fence_is_signaled(fence))
|
|
|
|
return fence;
|
|
|
|
|
|
|
|
dma_fence_put(fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < submit->nr_bos; i++) {
|
|
|
|
struct etnaviv_gem_submit_bo *bo = &submit->bos[i];
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (bo->excl) {
|
|
|
|
fence = bo->excl;
|
|
|
|
bo->excl = NULL;
|
|
|
|
|
|
|
|
if (!dma_fence_is_signaled(fence))
|
|
|
|
return fence;
|
|
|
|
|
|
|
|
dma_fence_put(fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < bo->nr_shared; j++) {
|
|
|
|
if (!bo->shared[j])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fence = bo->shared[j];
|
|
|
|
bo->shared[j] = NULL;
|
|
|
|
|
|
|
|
if (!dma_fence_is_signaled(fence))
|
|
|
|
return fence;
|
|
|
|
|
|
|
|
dma_fence_put(fence);
|
|
|
|
}
|
|
|
|
kfree(bo->shared);
|
|
|
|
bo->nr_shared = 0;
|
|
|
|
bo->shared = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-05 00:41:58 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-14 01:36:49 +07:00
|
|
|
static struct dma_fence *etnaviv_sched_run_job(struct drm_sched_job *sched_job)
|
2017-12-05 00:41:58 +07:00
|
|
|
{
|
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
2017-12-06 16:53:27 +07:00
|
|
|
struct dma_fence *fence = NULL;
|
2017-12-05 00:41:58 +07:00
|
|
|
|
2017-12-06 16:53:27 +07: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-05 00:41:58 +07:00
|
|
|
|
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void etnaviv_sched_timedout_job(struct drm_sched_job *sched_job)
|
|
|
|
{
|
2017-12-06 16:53:27 +07:00
|
|
|
struct etnaviv_gem_submit *submit = to_etnaviv_submit(sched_job);
|
|
|
|
struct etnaviv_gpu *gpu = submit->gpu;
|
2018-06-27 20:58:13 +07:00
|
|
|
u32 dma_addr;
|
|
|
|
int change;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the GPU managed to complete this jobs fence, the timout is
|
|
|
|
* spurious. Bail out.
|
|
|
|
*/
|
2018-10-04 16:37:00 +07:00
|
|
|
if (dma_fence_is_signaled(submit->out_fence))
|
2018-06-27 20:58:13 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
if (change < 0 || change > 16) {
|
|
|
|
gpu->hangcheck_dma_addr = dma_addr;
|
|
|
|
return;
|
|
|
|
}
|
2017-12-06 16:53:27 +07:00
|
|
|
|
|
|
|
/* block scheduler */
|
2018-12-05 04:56:14 +07:00
|
|
|
drm_sched_stop(&gpu->sched);
|
|
|
|
|
|
|
|
if(sched_job)
|
|
|
|
drm_sched_increase_karma(sched_job);
|
2017-12-06 16:53:27 +07:00
|
|
|
|
|
|
|
/* get the GPU back into the init state */
|
|
|
|
etnaviv_core_dump(gpu);
|
|
|
|
etnaviv_gpu_recover_hang(gpu);
|
|
|
|
|
2018-12-05 04:56:14 +07:00
|
|
|
drm_sched_resubmit_jobs(&gpu->sched);
|
|
|
|
|
2017-12-06 16:53:27 +07:00
|
|
|
/* restart scheduler after GPU is usable again */
|
2018-12-05 04:56:14 +07:00
|
|
|
drm_sched_start(&gpu->sched, true);
|
2017-12-05 00:41:58 +07: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 16:32:28 +07:00
|
|
|
drm_sched_job_cleanup(sched_job);
|
|
|
|
|
2017-12-05 00:41:58 +07:00
|
|
|
etnaviv_submit_put(submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_sched_backend_ops etnaviv_sched_ops = {
|
|
|
|
.dependency = etnaviv_sched_dependency,
|
|
|
|
.run_job = etnaviv_sched_run_job,
|
|
|
|
.timedout_job = etnaviv_sched_timedout_job,
|
|
|
|
.free_job = etnaviv_sched_free_job,
|
|
|
|
};
|
|
|
|
|
|
|
|
int etnaviv_sched_push_job(struct drm_sched_entity *sched_entity,
|
|
|
|
struct etnaviv_gem_submit *submit)
|
|
|
|
{
|
2018-05-25 21:51:25 +07: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
|
|
|
|
* allocated in drm_sched_job_init.
|
|
|
|
*/
|
|
|
|
mutex_lock(&submit->gpu->fence_lock);
|
2017-12-05 00:41:58 +07:00
|
|
|
|
2018-07-20 19:21:05 +07:00
|
|
|
ret = drm_sched_job_init(&submit->sched_job, sched_entity,
|
2018-11-23 22:26:04 +07:00
|
|
|
submit->ctx);
|
2017-12-05 00:41:58 +07:00
|
|
|
if (ret)
|
2018-05-25 21:51:25 +07:00
|
|
|
goto out_unlock;
|
2017-12-05 00:41:58 +07: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 21:51:25 +07:00
|
|
|
if (submit->out_fence_id < 0) {
|
2018-10-29 16:32:28 +07:00
|
|
|
drm_sched_job_cleanup(&submit->sched_job);
|
2018-05-25 21:51:25 +07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2017-12-05 00:41:58 +07:00
|
|
|
|
|
|
|
/* the scheduler holds on to the job now */
|
|
|
|
kref_get(&submit->refcount);
|
|
|
|
|
|
|
|
drm_sched_entity_push_job(&submit->sched_job, sched_entity);
|
|
|
|
|
2018-05-25 21:51:25 +07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&submit->gpu->fence_lock);
|
|
|
|
|
|
|
|
return ret;
|
2017-12-05 00:41:58 +07: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,
|
|
|
|
msecs_to_jiffies(500), dev_name(gpu->dev));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void etnaviv_sched_fini(struct etnaviv_gpu *gpu)
|
|
|
|
{
|
|
|
|
drm_sched_fini(&gpu->sched);
|
|
|
|
}
|