From 5ce4438380eeb7cf4cb5f53e80b2b28dd3ee0fe2 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Tue, 30 Sep 2014 13:30:13 +0300 Subject: gpu: nvgpu: find unused cde context instead of lru When preparing a new job, loop initially through the small number of preallocated contexts and try to find one that is already finished, instead of blindly getting the next slot in lru order. If all have work to do, select next in lru order. This reduces the possibility of a deadlock between cde tasks. Bug 200040211 Change-Id: Ib695c0a8e1bcec095d50ec4f2522f3aad39ce97b Signed-off-by: Konsta Holtta Reviewed-on: http://git-master/r/552035 GVS: Gerrit_Virtual_Submit Reviewed-by: Arto Merilainen --- drivers/gpu/nvgpu/gk20a/cde_gk20a.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/gk20a/cde_gk20a.c b/drivers/gpu/nvgpu/gk20a/cde_gk20a.c index e6dbaea8..1c230be6 100644 --- a/drivers/gpu/nvgpu/gk20a/cde_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/cde_gk20a.c @@ -589,6 +589,33 @@ static int gk20a_cde_execute_buffer(struct gk20a_cde_ctx *cde_ctx, num_entries, flags, fence, fence_out); } +static struct gk20a_cde_ctx *gk20a_cde_get_context(struct gk20a_cde_app *cde_app) +{ + struct gk20a_cde_ctx *cde_ctx = cde_app->cde_ctx; + int i; + + /* try to find a jobless context */ + + for (i = 0; i < ARRAY_SIZE(cde_app->cde_ctx); i++, cde_ctx++) { + struct channel_gk20a *ch = cde_ctx->ch; + bool empty; + + mutex_lock(&ch->jobs_lock); + empty = list_empty(&ch->jobs); + mutex_unlock(&ch->jobs_lock); + + if (empty) + return cde_ctx; + } + + /* pick just the next cde context, hopefully somewhat in order */ + cde_ctx = cde_app->cde_ctx + cde_app->cde_ctx_ptr; + cde_app->cde_ctx_ptr = (cde_app->cde_ctx_ptr + 1) % + ARRAY_SIZE(cde_app->cde_ctx); + + return cde_ctx; +} + int gk20a_cde_convert(struct gk20a *g, struct dma_buf *dst, s32 dst_kind, u64 dst_byte_offset, @@ -610,10 +637,7 @@ int gk20a_cde_convert(struct gk20a *g, mutex_lock(&cde_app->mutex); - /* pick next free cde context */ - cde_ctx = cde_app->cde_ctx + cde_app->cde_ctx_ptr; - cde_app->cde_ctx_ptr = (cde_app->cde_ctx_ptr + 1) % - ARRAY_SIZE(cde_app->cde_ctx); + cde_ctx = gk20a_cde_get_context(cde_app); /* First, map the buffers to local va */ -- cgit v1.2.2