From 3fa47b877db1edc16018d662e7b9915d92354745 Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Tue, 8 Aug 2017 12:08:03 +0530 Subject: gpu: nvgpu: Replace kref for refcounting in nvgpu - added wrapper struct nvgpu_ref over nvgpu_atomic_t - added nvgpu_ref_* APIs to access the above struct JIRA NVGPU-140 Change-Id: Id47f897995dd4721751f7610b6d4d4fbfe4d6b9a Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/1540899 Reviewed-by: svc-mobile-coverity Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Konsta Holtta Reviewed-by: Vijayakumar Subbu --- drivers/gpu/nvgpu/common/linux/debug_fifo.c | 23 ++++++++++++----------- drivers/gpu/nvgpu/common/linux/driver_common.c | 2 +- drivers/gpu/nvgpu/common/linux/ioctl_tsg.c | 2 +- drivers/gpu/nvgpu/common/linux/vm.c | 6 +++--- drivers/gpu/nvgpu/common/mm/vm.c | 8 ++++---- drivers/gpu/nvgpu/common/mm/vm_area.c | 2 +- drivers/gpu/nvgpu/common/semaphore.c | 16 ++++++++-------- 7 files changed, 30 insertions(+), 29 deletions(-) (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/linux/debug_fifo.c b/drivers/gpu/nvgpu/common/linux/debug_fifo.c index 1763eb7e..59198718 100644 --- a/drivers/gpu/nvgpu/common/linux/debug_fifo.c +++ b/drivers/gpu/nvgpu/common/linux/debug_fifo.c @@ -20,7 +20,7 @@ #include -void __gk20a_fifo_profile_free(struct kref *ref); +void __gk20a_fifo_profile_free(struct nvgpu_ref *ref); static void *gk20a_fifo_sched_debugfs_seq_start( struct seq_file *s, loff_t *pos) @@ -145,14 +145,15 @@ static int gk20a_fifo_profile_enable(void *data, u64 val) if (val == 0) { if (f->profile.enabled) { f->profile.enabled = false; - kref_put(&f->profile.ref, __gk20a_fifo_profile_free); + nvgpu_ref_put(&f->profile.ref, + __gk20a_fifo_profile_free); } } else { if (!f->profile.enabled) { /* not kref init as it can have a running condition if * we enable/disable/enable while kickoff is happening */ - if (!kref_get_unless_zero(&f->profile.ref)) { + if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) { f->profile.data = vzalloc( FIFO_PROFILING_ENTRIES * sizeof(struct fifo_profile_gk20a)); @@ -165,7 +166,7 @@ static int gk20a_fifo_profile_enable(void *data, u64 val) nvgpu_mutex_release(&f->profile.lock); return -ENOMEM; } - kref_init(&f->profile.ref); + nvgpu_ref_init(&f->profile.ref); } atomic_set(&f->profile.get.atomic_var, 0); f->profile.enabled = true; @@ -241,7 +242,7 @@ static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) u64 percentiles_append[PERCENTILE_RANGES]; u64 percentiles_userd[PERCENTILE_RANGES]; - if (!kref_get_unless_zero(&g->fifo.profile.ref)) { + if (!nvgpu_ref_get_unless_zero(&g->fifo.profile.ref)) { seq_printf(s, "Profiling disabled\n"); return 0; } @@ -271,7 +272,7 @@ static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) percentiles_jobtracking[index], percentiles_userd[index]); - kref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); + nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); return 0; } @@ -312,7 +313,7 @@ void gk20a_fifo_debugfs_init(struct gk20a *g) nvgpu_mutex_init(&g->fifo.profile.lock); g->fifo.profile.enabled = false; atomic_set(&g->fifo.profile.get.atomic_var, 0); - atomic_set(&g->fifo.profile.ref.refcount, 0); + atomic_set(&g->fifo.profile.ref.refcount.atomic_var, 0); debugfs_create_file("enable", 0600, profile_root, g, &gk20a_fifo_profile_enable_debugfs_fops); @@ -322,7 +323,7 @@ void gk20a_fifo_debugfs_init(struct gk20a *g) } -void __gk20a_fifo_profile_free(struct kref *ref) +void __gk20a_fifo_profile_free(struct nvgpu_ref *ref) { struct fifo_gk20a *f = container_of(ref, struct fifo_gk20a, profile.ref); @@ -340,7 +341,7 @@ struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) unsigned int index; /* If kref is zero, profiling is not enabled */ - if (!kref_get_unless_zero(&f->profile.ref)) + if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) return NULL; index = atomic_inc_return(&f->profile.get.atomic_var); profile = &f->profile.data[index % FIFO_PROFILING_ENTRIES]; @@ -352,7 +353,7 @@ struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) void gk20a_fifo_profile_release(struct gk20a *g, struct fifo_profile_gk20a *profile) { - kref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); + nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); } void gk20a_fifo_debugfs_deinit(struct gk20a *g) @@ -362,7 +363,7 @@ void gk20a_fifo_debugfs_deinit(struct gk20a *g) nvgpu_mutex_acquire(&f->profile.lock); if (f->profile.enabled) { f->profile.enabled = false; - kref_put(&f->profile.ref, __gk20a_fifo_profile_free); + nvgpu_ref_put(&f->profile.ref, __gk20a_fifo_profile_free); } nvgpu_mutex_release(&f->profile.lock); } diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index d1905c86..e8530c05 100644 --- a/drivers/gpu/nvgpu/common/linux/driver_common.c +++ b/drivers/gpu/nvgpu/common/linux/driver_common.c @@ -217,7 +217,7 @@ int nvgpu_probe(struct gk20a *g, g->remove_support = gk20a_remove_support; - kref_init(&g->refcount); + nvgpu_ref_init(&g->refcount); return 0; } diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c index cb876e23..c68c907e 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c @@ -260,7 +260,7 @@ int nvgpu_ioctl_tsg_dev_release(struct inode *inode, struct file *filp) struct tsg_private *priv = filp->private_data; struct tsg_gk20a *tsg = priv->tsg; - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); nvgpu_kfree(tsg->g, priv); return 0; } diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c index 3d1219b6..c84f531d 100644 --- a/drivers/gpu/nvgpu/common/linux/vm.c +++ b/drivers/gpu/nvgpu/common/linux/vm.c @@ -155,7 +155,7 @@ static u64 __nvgpu_vm_find_mapping(struct vm_gk20a *vm, else mapped_buffer->own_mem_ref = true; } - kref_get(&mapped_buffer->ref); + nvgpu_ref_get(&mapped_buffer->ref); nvgpu_log(g, gpu_dbg_map, "gv: 0x%04x_%08x + 0x%-7zu " @@ -380,7 +380,7 @@ u64 nvgpu_vm_map(struct vm_gk20a *vm, mapped_buffer->user_mapped = user_mapped ? 1 : 0; mapped_buffer->own_mem_ref = user_mapped; nvgpu_init_list_node(&mapped_buffer->buffer_list); - kref_init(&mapped_buffer->ref); + nvgpu_ref_init(&mapped_buffer->ref); err = nvgpu_insert_mapped_buf(vm, mapped_buffer); if (err) { @@ -425,6 +425,6 @@ void nvgpu_vm_unmap(struct vm_gk20a *vm, u64 offset) return; } - kref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_kref); + nvgpu_ref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_ref); nvgpu_mutex_release(&vm->update_gmmu_lock); } diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 3ed3c7fe..2e2f52df 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -404,7 +404,7 @@ static int __nvgpu_vm_init(struct mm_gk20a *mm, vm->mapped_buffers = NULL; nvgpu_mutex_init(&vm->update_gmmu_lock); - kref_init(&vm->ref); + nvgpu_ref_init(&vm->ref); nvgpu_init_list_node(&vm->vm_area_list); /* @@ -557,7 +557,7 @@ static void __nvgpu_vm_remove(struct vm_gk20a *vm) nvgpu_kfree(g, vm); } -static void __nvgpu_vm_remove_kref(struct kref *ref) +static void __nvgpu_vm_remove_ref(struct nvgpu_ref *ref) { struct vm_gk20a *vm = container_of(ref, struct vm_gk20a, ref); @@ -566,12 +566,12 @@ static void __nvgpu_vm_remove_kref(struct kref *ref) void nvgpu_vm_get(struct vm_gk20a *vm) { - kref_get(&vm->ref); + nvgpu_ref_get(&vm->ref); } void nvgpu_vm_put(struct vm_gk20a *vm) { - kref_put(&vm->ref, __nvgpu_vm_remove_kref); + nvgpu_ref_put(&vm->ref, __nvgpu_vm_remove_ref); } int nvgpu_insert_mapped_buf(struct vm_gk20a *vm, diff --git a/drivers/gpu/nvgpu/common/mm/vm_area.c b/drivers/gpu/nvgpu/common/mm/vm_area.c index 7b831947..19864439 100644 --- a/drivers/gpu/nvgpu/common/mm/vm_area.c +++ b/drivers/gpu/nvgpu/common/mm/vm_area.c @@ -202,7 +202,7 @@ int nvgpu_vm_area_free(struct vm_gk20a *vm, u64 addr) &vm_area->buffer_list_head, nvgpu_mapped_buf, buffer_list) { nvgpu_list_del(&buffer->buffer_list); - kref_put(&buffer->ref, gk20a_vm_unmap_locked_kref); + nvgpu_ref_put(&buffer->ref, gk20a_vm_unmap_locked_ref); } /* if this was a sparse mapping, free the va */ diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c index ac45aaaa..5496f5ec 100644 --- a/drivers/gpu/nvgpu/common/semaphore.c +++ b/drivers/gpu/nvgpu/common/semaphore.c @@ -156,7 +156,7 @@ struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc( p->sema_sea = sea; nvgpu_init_list_node(&p->hw_semas); nvgpu_init_list_node(&p->pool_list_entry); - kref_init(&p->ref); + nvgpu_ref_init(&p->ref); sea->page_count++; nvgpu_list_add(&p->pool_list_entry, &sea->pool_list); @@ -285,7 +285,7 @@ void nvgpu_semaphore_pool_unmap(struct nvgpu_semaphore_pool *p, * Completely free a semaphore_pool. You should make sure this pool is not * mapped otherwise there's going to be a memory leak. */ -static void nvgpu_semaphore_pool_free(struct kref *ref) +static void nvgpu_semaphore_pool_free(struct nvgpu_ref *ref) { struct nvgpu_semaphore_pool *p = container_of(ref, struct nvgpu_semaphore_pool, ref); @@ -314,12 +314,12 @@ static void nvgpu_semaphore_pool_free(struct kref *ref) void nvgpu_semaphore_pool_get(struct nvgpu_semaphore_pool *p) { - kref_get(&p->ref); + nvgpu_ref_get(&p->ref); } void nvgpu_semaphore_pool_put(struct nvgpu_semaphore_pool *p) { - kref_put(&p->ref, nvgpu_semaphore_pool_free); + nvgpu_ref_put(&p->ref, nvgpu_semaphore_pool_free); } /* @@ -423,7 +423,7 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch) if (!s) return NULL; - kref_init(&s->ref); + nvgpu_ref_init(&s->ref); s->hw_sema = ch->hw_sema; nvgpu_atomic_set(&s->value, 0); @@ -438,7 +438,7 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch) return s; } -static void nvgpu_semaphore_free(struct kref *ref) +static void nvgpu_semaphore_free(struct nvgpu_ref *ref) { struct nvgpu_semaphore *s = container_of(ref, struct nvgpu_semaphore, ref); @@ -450,10 +450,10 @@ static void nvgpu_semaphore_free(struct kref *ref) void nvgpu_semaphore_put(struct nvgpu_semaphore *s) { - kref_put(&s->ref, nvgpu_semaphore_free); + nvgpu_ref_put(&s->ref, nvgpu_semaphore_free); } void nvgpu_semaphore_get(struct nvgpu_semaphore *s) { - kref_get(&s->ref); + nvgpu_ref_get(&s->ref); } -- cgit v1.2.2