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/gk20a/fence_gk20a.c | 10 +++++----- drivers/gpu/nvgpu/gk20a/fence_gk20a.h | 2 +- drivers/gpu/nvgpu/gk20a/fifo_gk20a.h | 2 +- drivers/gpu/nvgpu/gk20a/gk20a.c | 11 ++++++----- drivers/gpu/nvgpu/gk20a/gk20a.h | 2 +- drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 15 ++++++++------- drivers/gpu/nvgpu/gk20a/mm_gk20a.h | 2 +- drivers/gpu/nvgpu/gk20a/sched_gk20a.c | 20 ++++++++++---------- drivers/gpu/nvgpu/gk20a/sync_gk20a.c | 10 +++++----- drivers/gpu/nvgpu/gk20a/tsg_gk20a.c | 10 +++++----- drivers/gpu/nvgpu/gk20a/tsg_gk20a.h | 4 ++-- 11 files changed, 45 insertions(+), 43 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a') diff --git a/drivers/gpu/nvgpu/gk20a/fence_gk20a.c b/drivers/gpu/nvgpu/gk20a/fence_gk20a.c index a7250b17..fdfef3da 100644 --- a/drivers/gpu/nvgpu/gk20a/fence_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/fence_gk20a.c @@ -33,10 +33,10 @@ struct gk20a_fence_ops { int (*wait)(struct gk20a_fence *, long timeout); bool (*is_expired)(struct gk20a_fence *); - void *(*free)(struct kref *); + void *(*free)(struct nvgpu_ref *); }; -static void gk20a_fence_free(struct kref *ref) +static void gk20a_fence_free(struct nvgpu_ref *ref) { struct gk20a_fence *f = container_of(ref, struct gk20a_fence, ref); @@ -59,13 +59,13 @@ static void gk20a_fence_free(struct kref *ref) void gk20a_fence_put(struct gk20a_fence *f) { if (f) - kref_put(&f->ref, gk20a_fence_free); + nvgpu_ref_put(&f->ref, gk20a_fence_free); } struct gk20a_fence *gk20a_fence_get(struct gk20a_fence *f) { if (f) - kref_get(&f->ref); + nvgpu_ref_get(&f->ref); return f; } @@ -175,7 +175,7 @@ struct gk20a_fence *gk20a_alloc_fence(struct channel_gk20a *c) fence = nvgpu_kzalloc(c->g, sizeof(struct gk20a_fence)); if (fence) { - kref_init(&fence->ref); + nvgpu_ref_init(&fence->ref); fence->g = c->g; } diff --git a/drivers/gpu/nvgpu/gk20a/fence_gk20a.h b/drivers/gpu/nvgpu/gk20a/fence_gk20a.h index 140f5488..e0eb09b6 100644 --- a/drivers/gpu/nvgpu/gk20a/fence_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/fence_gk20a.h @@ -33,7 +33,7 @@ struct gk20a_fence { /* Valid for all fence types: */ bool valid; - struct kref ref; + struct nvgpu_ref ref; bool wfi; struct sync_fence *sync_fence; const struct gk20a_fence_ops *ops; diff --git a/drivers/gpu/nvgpu/gk20a/fifo_gk20a.h b/drivers/gpu/nvgpu/gk20a/fifo_gk20a.h index a6eae8ca..fb4932c8 100644 --- a/drivers/gpu/nvgpu/gk20a/fifo_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/fifo_gk20a.h @@ -159,7 +159,7 @@ struct fifo_gk20a { nvgpu_atomic_t get; bool enabled; u64 *sorted; - struct kref ref; + struct nvgpu_ref ref; struct nvgpu_mutex lock; } profile; #endif diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 550b22c0..639ec4b5 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -511,7 +511,7 @@ int gk20a_init_gpu_characteristics(struct gk20a *g) /* * Free the gk20a struct. */ -static void gk20a_free_cb(struct kref *refcount) +static void gk20a_free_cb(struct nvgpu_ref *refcount) { struct gk20a *g = container_of(refcount, struct gk20a, refcount); @@ -544,10 +544,11 @@ struct gk20a * __must_check gk20a_get(struct gk20a *g) * the code will never be in such a situation that this race is * possible. */ - success = kref_get_unless_zero(&g->refcount); + success = nvgpu_ref_get_unless_zero(&g->refcount); gk20a_dbg(gpu_dbg_shutdown, "GET: refs currently %d %s", - atomic_read(&g->refcount.refcount), success ? "" : "(FAILED)"); + nvgpu_atomic_read(&g->refcount.refcount), + success ? "" : "(FAILED)"); return success ? g : NULL; } @@ -571,7 +572,7 @@ void gk20a_put(struct gk20a *g) * ... Freeing GK20A struct! */ gk20a_dbg(gpu_dbg_shutdown, "PUT: refs currently %d", - atomic_read(&g->refcount.refcount)); + nvgpu_atomic_read(&g->refcount.refcount)); - kref_put(&g->refcount, gk20a_free_cb); + nvgpu_ref_put(&g->refcount, gk20a_free_cb); } diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 5efa846d..15e81291 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -1036,7 +1036,7 @@ struct gk20a { nvgpu_atomic_t usage_count; - struct kref refcount; + struct nvgpu_ref refcount; struct resource *reg_mem; void __iomem *regs; diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index 2ce78cef..3030c170 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c @@ -811,7 +811,7 @@ int nvgpu_vm_get_buffers(struct vm_gk20a *vm, mapped_buffer = mapped_buffer_from_rbtree_node(node); if (mapped_buffer->user_mapped) { buffer_list[i] = mapped_buffer; - kref_get(&mapped_buffer->ref); + nvgpu_ref_get(&mapped_buffer->ref); i++; } nvgpu_rbtree_enum_next(&node, node); @@ -827,7 +827,7 @@ int nvgpu_vm_get_buffers(struct vm_gk20a *vm, return 0; } -void gk20a_vm_unmap_locked_kref(struct kref *ref) +void gk20a_vm_unmap_locked_ref(struct nvgpu_ref *ref) { struct nvgpu_mapped_buf *mapped_buffer = container_of(ref, struct nvgpu_mapped_buf, ref); @@ -849,8 +849,8 @@ void nvgpu_vm_put_buffers(struct vm_gk20a *vm, vm->kref_put_batch = &batch; for (i = 0; i < num_buffers; ++i) - kref_put(&mapped_buffers[i]->ref, - gk20a_vm_unmap_locked_kref); + nvgpu_ref_put(&mapped_buffers[i]->ref, + gk20a_vm_unmap_locked_ref); vm->kref_put_batch = NULL; nvgpu_vm_mapping_batch_finish_locked(vm, &batch); @@ -882,8 +882,9 @@ static void nvgpu_vm_unmap_user(struct vm_gk20a *vm, u64 offset, nvgpu_timeout_init(vm->mm->g, &timeout, 10000, NVGPU_TIMER_RETRY_TIMER); do { - if (atomic_read(&mapped_buffer->ref.refcount) == 1) - break; + if (nvgpu_atomic_read( + &mapped_buffer->ref.refcount) == 1) + break; nvgpu_udelay(5); } while (!nvgpu_timeout_expired_msg(&timeout, "sync-unmap failed on 0x%llx")); @@ -902,7 +903,7 @@ static void nvgpu_vm_unmap_user(struct vm_gk20a *vm, u64 offset, vm->num_user_mapped_buffers--; vm->kref_put_batch = batch; - kref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_kref); + nvgpu_ref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_ref); vm->kref_put_batch = NULL; nvgpu_mutex_release(&vm->update_gmmu_lock); diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h index e8b90c8f..82a4ee85 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h @@ -434,6 +434,6 @@ extern const struct gk20a_mmu_level gk20a_mm_levels_128k[]; int gk20a_mm_get_buffer_info(struct device *dev, int dmabuf_fd, u64 *buffer_id, u64 *buffer_len); -void gk20a_vm_unmap_locked_kref(struct kref *ref); +void gk20a_vm_unmap_locked_ref(struct nvgpu_ref *ref); #endif /* MM_GK20A_H */ diff --git a/drivers/gpu/nvgpu/gk20a/sched_gk20a.c b/drivers/gpu/nvgpu/gk20a/sched_gk20a.c index 014848ba..ac54addd 100644 --- a/drivers/gpu/nvgpu/gk20a/sched_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/sched_gk20a.c @@ -189,7 +189,7 @@ static int gk20a_sched_dev_ioctl_get_params(struct gk20a_sched_ctrl *sched, return -EINVAL; tsg = &f->tsg[tsgid]; - if (!kref_get_unless_zero(&tsg->refcount)) + if (!nvgpu_ref_get_unless_zero(&tsg->refcount)) return -ENXIO; arg->pid = tsg->tgid; /* kernel tgid corresponds to user pid */ @@ -206,7 +206,7 @@ static int gk20a_sched_dev_ioctl_get_params(struct gk20a_sched_ctrl *sched, arg->compute_preempt_mode = 0; } - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return 0; } @@ -227,7 +227,7 @@ static int gk20a_sched_dev_ioctl_tsg_set_timeslice( return -EINVAL; tsg = &f->tsg[tsgid]; - if (!kref_get_unless_zero(&tsg->refcount)) + if (!nvgpu_ref_get_unless_zero(&tsg->refcount)) return -ENXIO; err = gk20a_busy(g); @@ -239,7 +239,7 @@ static int gk20a_sched_dev_ioctl_tsg_set_timeslice( gk20a_idle(g); done: - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return err; } @@ -260,7 +260,7 @@ static int gk20a_sched_dev_ioctl_tsg_set_runlist_interleave( return -EINVAL; tsg = &f->tsg[tsgid]; - if (!kref_get_unless_zero(&tsg->refcount)) + if (!nvgpu_ref_get_unless_zero(&tsg->refcount)) return -ENXIO; err = gk20a_busy(g); @@ -272,7 +272,7 @@ static int gk20a_sched_dev_ioctl_tsg_set_runlist_interleave( gk20a_idle(g); done: - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return err; } @@ -320,7 +320,7 @@ static int gk20a_sched_dev_ioctl_get_tsg(struct gk20a_sched_ctrl *sched, return -EINVAL; tsg = &f->tsg[tsgid]; - if (!kref_get_unless_zero(&tsg->refcount)) + if (!nvgpu_ref_get_unless_zero(&tsg->refcount)) return -ENXIO; nvgpu_mutex_acquire(&sched->status_lock); @@ -328,7 +328,7 @@ static int gk20a_sched_dev_ioctl_get_tsg(struct gk20a_sched_ctrl *sched, nvgpu_warn(g, "tsgid=%d already referenced", tsgid); /* unlock status_lock as gk20a_tsg_release locks it */ nvgpu_mutex_release(&sched->status_lock); - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return -ENXIO; } @@ -364,7 +364,7 @@ static int gk20a_sched_dev_ioctl_put_tsg(struct gk20a_sched_ctrl *sched, nvgpu_mutex_release(&sched->status_lock); tsg = &f->tsg[tsgid]; - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return 0; } @@ -507,7 +507,7 @@ int gk20a_sched_dev_release(struct inode *inode, struct file *filp) for (tsgid = 0; tsgid < f->num_channels; tsgid++) { if (NVGPU_SCHED_ISSET(tsgid, sched->ref_tsg_bitmap)) { tsg = &f->tsg[tsgid]; - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); } } diff --git a/drivers/gpu/nvgpu/gk20a/sync_gk20a.c b/drivers/gpu/nvgpu/gk20a/sync_gk20a.c index deaf19a1..a8e824b6 100644 --- a/drivers/gpu/nvgpu/gk20a/sync_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/sync_gk20a.c @@ -43,7 +43,7 @@ struct gk20a_sync_timeline { */ struct gk20a_sync_pt { struct gk20a *g; - struct kref refcount; + struct nvgpu_ref refcount; u32 thresh; struct nvgpu_semaphore *sema; struct gk20a_sync_timeline *obj; @@ -170,7 +170,7 @@ static struct gk20a_sync_timeline *to_gk20a_timeline(struct sync_timeline *obj) return (struct gk20a_sync_timeline *)obj; } -static void gk20a_sync_pt_free_shared(struct kref *ref) +static void gk20a_sync_pt_free_shared(struct nvgpu_ref *ref) { struct gk20a_sync_pt *pt = container_of(ref, struct gk20a_sync_pt, refcount); @@ -192,7 +192,7 @@ static struct gk20a_sync_pt *gk20a_sync_pt_create_shared( if (!shared) return NULL; - kref_init(&shared->refcount); + nvgpu_ref_init(&shared->refcount); shared->g = g; shared->obj = obj; shared->sema = sema; @@ -229,7 +229,7 @@ static void gk20a_sync_pt_free_inst(struct sync_pt *sync_pt) { struct gk20a_sync_pt *pt = to_gk20a_sync_pt(sync_pt); if (pt) - kref_put(&pt->refcount, gk20a_sync_pt_free_shared); + nvgpu_ref_put(&pt->refcount, gk20a_sync_pt_free_shared); } static struct sync_pt *gk20a_sync_pt_dup_inst(struct sync_pt *sync_pt) @@ -242,7 +242,7 @@ static struct sync_pt *gk20a_sync_pt_dup_inst(struct sync_pt *sync_pt) if (!pti) return NULL; pti->shared = pt; - kref_get(&pt->refcount); + nvgpu_ref_get(&pt->refcount); return &pti->pt; } diff --git a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c index 99d72292..f3e87a13 100644 --- a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c @@ -104,7 +104,7 @@ int gk20a_tsg_bind_channel(struct tsg_gk20a *tsg, nvgpu_list_add_tail(&ch->ch_entry, &tsg->ch_list); up_write(&tsg->ch_list_lock); - kref_get(&tsg->refcount); + nvgpu_ref_get(&tsg->refcount); gk20a_dbg(gpu_dbg_fn, "BIND tsg:%d channel:%d\n", tsg->tsgid, ch->chid); @@ -122,7 +122,7 @@ int gk20a_tsg_unbind_channel(struct channel_gk20a *ch) nvgpu_list_del(&ch->ch_entry); up_write(&tsg->ch_list_lock); - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); ch->tsgid = NVGPU_INVALID_TSG_ID; @@ -257,7 +257,7 @@ struct tsg_gk20a *gk20a_tsg_open(struct gk20a *g) tsg->g = g; tsg->num_active_channels = 0; - kref_init(&tsg->refcount); + nvgpu_ref_init(&tsg->refcount); tsg->tsg_gr_ctx = NULL; tsg->vm = NULL; @@ -287,11 +287,11 @@ struct tsg_gk20a *gk20a_tsg_open(struct gk20a *g) return tsg; clean_up: - kref_put(&tsg->refcount, gk20a_tsg_release); + nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); return NULL; } -void gk20a_tsg_release(struct kref *ref) +void gk20a_tsg_release(struct nvgpu_ref *ref) { struct tsg_gk20a *tsg = container_of(ref, struct tsg_gk20a, refcount); struct gk20a *g = tsg->g; diff --git a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.h b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.h index 40e12105..9195d3d3 100644 --- a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.h @@ -25,7 +25,7 @@ struct channel_gk20a; bool gk20a_is_channel_marked_as_tsg(struct channel_gk20a *ch); struct tsg_gk20a *gk20a_tsg_open(struct gk20a *g); -void gk20a_tsg_release(struct kref *ref); +void gk20a_tsg_release(struct nvgpu_ref *ref); int gk20a_init_tsg_support(struct gk20a *g, u32 tsgid); struct tsg_gk20a *tsg_gk20a_from_ch(struct channel_gk20a *ch); @@ -36,7 +36,7 @@ struct tsg_gk20a { bool in_use; int tsgid; - struct kref refcount; + struct nvgpu_ref refcount; struct nvgpu_list_node ch_list; int num_active_channels; -- cgit v1.2.2