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 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) (limited to 'drivers/gpu/nvgpu/common/linux') 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); } -- cgit v1.2.2