From 7e403974d3584ab8880e42d422ee3afb7f49d6f3 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 29 Nov 2016 16:01:41 -0800 Subject: gpu: nvgpu: Simplify ref-counting on VMs Simplify ref-counting on VMs: take a ref when a VM is bound to a channel and drop a ref when a channel is freed. Previously ref-counts were scattered over the driver. Also the CE and CDE code would bind channels with custom rolled code. This was because the gk20a_vm_bind_channel() function took an as_share as the VM argument (the VM was then inferred from that as_share). However, it is trivial to abtract that bit out and allow a central bind channel function that just takes a VM and a channel. Bug 1846718 Change-Id: I156aab259f6c7a2fa338408c6c4a3a464cd44a0c Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1261886 Reviewed-by: Richard Zhao Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/channel_gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index e272b130..c8b1c105 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -1008,11 +1008,10 @@ static void gk20a_free_channel(struct channel_gk20a *ch, bool force) if (ch->hw_sema) gk20a_semaphore_free_hw_sema(ch); - /* release channel binding to the as_share */ - if (ch_vm->as_share) - gk20a_as_release_share(ch_vm->as_share); - else - gk20a_vm_put(ch_vm); + /* + * When releasing the channel we unbind the VM - so release the ref. + */ + gk20a_vm_put(ch_vm); spin_lock(&ch->update_fn_lock); ch->update_fn = NULL; @@ -2252,14 +2251,11 @@ static int gk20a_channel_add_job(struct channel_gk20a *c, int err = 0, num_mapped_buffers = 0; bool pre_alloc_enabled = channel_gk20a_is_prealloc_enabled(c); - /* job needs reference to this vm (released in channel_update) */ - gk20a_vm_get(vm); - if (!skip_buffer_refcounting) { err = gk20a_vm_get_buffers(vm, &mapped_buffers, &num_mapped_buffers); if (err) - goto err_put_vm; + return err; } /* put() is done in gk20a_channel_update() when the job is done */ @@ -2293,8 +2289,6 @@ static int gk20a_channel_add_job(struct channel_gk20a *c, err_put_buffers: gk20a_vm_put_buffers(vm, mapped_buffers, num_mapped_buffers); -err_put_vm: - gk20a_vm_put(vm); return err; } @@ -2385,8 +2379,6 @@ static void gk20a_channel_clean_up_jobs(struct channel_gk20a *c, gk20a_free_priv_cmdbuf(c, job->wait_cmd); gk20a_free_priv_cmdbuf(c, job->incr_cmd); - /* job is done. release its vm reference (taken in add_job) */ - gk20a_vm_put(vm); /* another bookkeeping taken in add_job. caller must hold a ref * so this wouldn't get freed here. */ gk20a_channel_put(c); -- cgit v1.2.2