diff options
author | Debarshi Dutta <ddutta@nvidia.com> | 2017-08-08 02:38:03 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-08-24 04:10:37 -0400 |
commit | 3fa47b877db1edc16018d662e7b9915d92354745 (patch) | |
tree | c1d9a8734e7d92b5ae647fbc3f582a01207a23f6 /drivers/gpu/nvgpu/common | |
parent | 8662fae334f2419da2e7fd220f7734217ec52433 (diff) |
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 <ddutta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1540899
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug_fifo.c | 23 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/driver_common.c | 2 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/ioctl_tsg.c | 2 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vm.c | 6 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/vm.c | 8 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/vm_area.c | 2 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/semaphore.c | 16 |
7 files changed, 30 insertions, 29 deletions
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 @@ | |||
20 | 20 | ||
21 | #include <nvgpu/sort.h> | 21 | #include <nvgpu/sort.h> |
22 | 22 | ||
23 | void __gk20a_fifo_profile_free(struct kref *ref); | 23 | void __gk20a_fifo_profile_free(struct nvgpu_ref *ref); |
24 | 24 | ||
25 | static void *gk20a_fifo_sched_debugfs_seq_start( | 25 | static void *gk20a_fifo_sched_debugfs_seq_start( |
26 | struct seq_file *s, loff_t *pos) | 26 | struct seq_file *s, loff_t *pos) |
@@ -145,14 +145,15 @@ static int gk20a_fifo_profile_enable(void *data, u64 val) | |||
145 | if (val == 0) { | 145 | if (val == 0) { |
146 | if (f->profile.enabled) { | 146 | if (f->profile.enabled) { |
147 | f->profile.enabled = false; | 147 | f->profile.enabled = false; |
148 | kref_put(&f->profile.ref, __gk20a_fifo_profile_free); | 148 | nvgpu_ref_put(&f->profile.ref, |
149 | __gk20a_fifo_profile_free); | ||
149 | } | 150 | } |
150 | } else { | 151 | } else { |
151 | if (!f->profile.enabled) { | 152 | if (!f->profile.enabled) { |
152 | /* not kref init as it can have a running condition if | 153 | /* not kref init as it can have a running condition if |
153 | * we enable/disable/enable while kickoff is happening | 154 | * we enable/disable/enable while kickoff is happening |
154 | */ | 155 | */ |
155 | if (!kref_get_unless_zero(&f->profile.ref)) { | 156 | if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) { |
156 | f->profile.data = vzalloc( | 157 | f->profile.data = vzalloc( |
157 | FIFO_PROFILING_ENTRIES * | 158 | FIFO_PROFILING_ENTRIES * |
158 | sizeof(struct fifo_profile_gk20a)); | 159 | sizeof(struct fifo_profile_gk20a)); |
@@ -165,7 +166,7 @@ static int gk20a_fifo_profile_enable(void *data, u64 val) | |||
165 | nvgpu_mutex_release(&f->profile.lock); | 166 | nvgpu_mutex_release(&f->profile.lock); |
166 | return -ENOMEM; | 167 | return -ENOMEM; |
167 | } | 168 | } |
168 | kref_init(&f->profile.ref); | 169 | nvgpu_ref_init(&f->profile.ref); |
169 | } | 170 | } |
170 | atomic_set(&f->profile.get.atomic_var, 0); | 171 | atomic_set(&f->profile.get.atomic_var, 0); |
171 | f->profile.enabled = true; | 172 | f->profile.enabled = true; |
@@ -241,7 +242,7 @@ static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) | |||
241 | u64 percentiles_append[PERCENTILE_RANGES]; | 242 | u64 percentiles_append[PERCENTILE_RANGES]; |
242 | u64 percentiles_userd[PERCENTILE_RANGES]; | 243 | u64 percentiles_userd[PERCENTILE_RANGES]; |
243 | 244 | ||
244 | if (!kref_get_unless_zero(&g->fifo.profile.ref)) { | 245 | if (!nvgpu_ref_get_unless_zero(&g->fifo.profile.ref)) { |
245 | seq_printf(s, "Profiling disabled\n"); | 246 | seq_printf(s, "Profiling disabled\n"); |
246 | return 0; | 247 | return 0; |
247 | } | 248 | } |
@@ -271,7 +272,7 @@ static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) | |||
271 | percentiles_jobtracking[index], | 272 | percentiles_jobtracking[index], |
272 | percentiles_userd[index]); | 273 | percentiles_userd[index]); |
273 | 274 | ||
274 | kref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); | 275 | nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); |
275 | 276 | ||
276 | return 0; | 277 | return 0; |
277 | } | 278 | } |
@@ -312,7 +313,7 @@ void gk20a_fifo_debugfs_init(struct gk20a *g) | |||
312 | nvgpu_mutex_init(&g->fifo.profile.lock); | 313 | nvgpu_mutex_init(&g->fifo.profile.lock); |
313 | g->fifo.profile.enabled = false; | 314 | g->fifo.profile.enabled = false; |
314 | atomic_set(&g->fifo.profile.get.atomic_var, 0); | 315 | atomic_set(&g->fifo.profile.get.atomic_var, 0); |
315 | atomic_set(&g->fifo.profile.ref.refcount, 0); | 316 | atomic_set(&g->fifo.profile.ref.refcount.atomic_var, 0); |
316 | 317 | ||
317 | debugfs_create_file("enable", 0600, profile_root, g, | 318 | debugfs_create_file("enable", 0600, profile_root, g, |
318 | &gk20a_fifo_profile_enable_debugfs_fops); | 319 | &gk20a_fifo_profile_enable_debugfs_fops); |
@@ -322,7 +323,7 @@ void gk20a_fifo_debugfs_init(struct gk20a *g) | |||
322 | 323 | ||
323 | } | 324 | } |
324 | 325 | ||
325 | void __gk20a_fifo_profile_free(struct kref *ref) | 326 | void __gk20a_fifo_profile_free(struct nvgpu_ref *ref) |
326 | { | 327 | { |
327 | struct fifo_gk20a *f = container_of(ref, struct fifo_gk20a, | 328 | struct fifo_gk20a *f = container_of(ref, struct fifo_gk20a, |
328 | profile.ref); | 329 | profile.ref); |
@@ -340,7 +341,7 @@ struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) | |||
340 | unsigned int index; | 341 | unsigned int index; |
341 | 342 | ||
342 | /* If kref is zero, profiling is not enabled */ | 343 | /* If kref is zero, profiling is not enabled */ |
343 | if (!kref_get_unless_zero(&f->profile.ref)) | 344 | if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) |
344 | return NULL; | 345 | return NULL; |
345 | index = atomic_inc_return(&f->profile.get.atomic_var); | 346 | index = atomic_inc_return(&f->profile.get.atomic_var); |
346 | profile = &f->profile.data[index % FIFO_PROFILING_ENTRIES]; | 347 | profile = &f->profile.data[index % FIFO_PROFILING_ENTRIES]; |
@@ -352,7 +353,7 @@ struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) | |||
352 | void gk20a_fifo_profile_release(struct gk20a *g, | 353 | void gk20a_fifo_profile_release(struct gk20a *g, |
353 | struct fifo_profile_gk20a *profile) | 354 | struct fifo_profile_gk20a *profile) |
354 | { | 355 | { |
355 | kref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); | 356 | nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); |
356 | } | 357 | } |
357 | 358 | ||
358 | void gk20a_fifo_debugfs_deinit(struct gk20a *g) | 359 | void gk20a_fifo_debugfs_deinit(struct gk20a *g) |
@@ -362,7 +363,7 @@ void gk20a_fifo_debugfs_deinit(struct gk20a *g) | |||
362 | nvgpu_mutex_acquire(&f->profile.lock); | 363 | nvgpu_mutex_acquire(&f->profile.lock); |
363 | if (f->profile.enabled) { | 364 | if (f->profile.enabled) { |
364 | f->profile.enabled = false; | 365 | f->profile.enabled = false; |
365 | kref_put(&f->profile.ref, __gk20a_fifo_profile_free); | 366 | nvgpu_ref_put(&f->profile.ref, __gk20a_fifo_profile_free); |
366 | } | 367 | } |
367 | nvgpu_mutex_release(&f->profile.lock); | 368 | nvgpu_mutex_release(&f->profile.lock); |
368 | } | 369 | } |
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, | |||
217 | 217 | ||
218 | g->remove_support = gk20a_remove_support; | 218 | g->remove_support = gk20a_remove_support; |
219 | 219 | ||
220 | kref_init(&g->refcount); | 220 | nvgpu_ref_init(&g->refcount); |
221 | 221 | ||
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
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) | |||
260 | struct tsg_private *priv = filp->private_data; | 260 | struct tsg_private *priv = filp->private_data; |
261 | struct tsg_gk20a *tsg = priv->tsg; | 261 | struct tsg_gk20a *tsg = priv->tsg; |
262 | 262 | ||
263 | kref_put(&tsg->refcount, gk20a_tsg_release); | 263 | nvgpu_ref_put(&tsg->refcount, gk20a_tsg_release); |
264 | nvgpu_kfree(tsg->g, priv); | 264 | nvgpu_kfree(tsg->g, priv); |
265 | return 0; | 265 | return 0; |
266 | } | 266 | } |
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, | |||
155 | else | 155 | else |
156 | mapped_buffer->own_mem_ref = true; | 156 | mapped_buffer->own_mem_ref = true; |
157 | } | 157 | } |
158 | kref_get(&mapped_buffer->ref); | 158 | nvgpu_ref_get(&mapped_buffer->ref); |
159 | 159 | ||
160 | nvgpu_log(g, gpu_dbg_map, | 160 | nvgpu_log(g, gpu_dbg_map, |
161 | "gv: 0x%04x_%08x + 0x%-7zu " | 161 | "gv: 0x%04x_%08x + 0x%-7zu " |
@@ -380,7 +380,7 @@ u64 nvgpu_vm_map(struct vm_gk20a *vm, | |||
380 | mapped_buffer->user_mapped = user_mapped ? 1 : 0; | 380 | mapped_buffer->user_mapped = user_mapped ? 1 : 0; |
381 | mapped_buffer->own_mem_ref = user_mapped; | 381 | mapped_buffer->own_mem_ref = user_mapped; |
382 | nvgpu_init_list_node(&mapped_buffer->buffer_list); | 382 | nvgpu_init_list_node(&mapped_buffer->buffer_list); |
383 | kref_init(&mapped_buffer->ref); | 383 | nvgpu_ref_init(&mapped_buffer->ref); |
384 | 384 | ||
385 | err = nvgpu_insert_mapped_buf(vm, mapped_buffer); | 385 | err = nvgpu_insert_mapped_buf(vm, mapped_buffer); |
386 | if (err) { | 386 | if (err) { |
@@ -425,6 +425,6 @@ void nvgpu_vm_unmap(struct vm_gk20a *vm, u64 offset) | |||
425 | return; | 425 | return; |
426 | } | 426 | } |
427 | 427 | ||
428 | kref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_kref); | 428 | nvgpu_ref_put(&mapped_buffer->ref, gk20a_vm_unmap_locked_ref); |
429 | nvgpu_mutex_release(&vm->update_gmmu_lock); | 429 | nvgpu_mutex_release(&vm->update_gmmu_lock); |
430 | } | 430 | } |
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, | |||
404 | vm->mapped_buffers = NULL; | 404 | vm->mapped_buffers = NULL; |
405 | 405 | ||
406 | nvgpu_mutex_init(&vm->update_gmmu_lock); | 406 | nvgpu_mutex_init(&vm->update_gmmu_lock); |
407 | kref_init(&vm->ref); | 407 | nvgpu_ref_init(&vm->ref); |
408 | nvgpu_init_list_node(&vm->vm_area_list); | 408 | nvgpu_init_list_node(&vm->vm_area_list); |
409 | 409 | ||
410 | /* | 410 | /* |
@@ -557,7 +557,7 @@ static void __nvgpu_vm_remove(struct vm_gk20a *vm) | |||
557 | nvgpu_kfree(g, vm); | 557 | nvgpu_kfree(g, vm); |
558 | } | 558 | } |
559 | 559 | ||
560 | static void __nvgpu_vm_remove_kref(struct kref *ref) | 560 | static void __nvgpu_vm_remove_ref(struct nvgpu_ref *ref) |
561 | { | 561 | { |
562 | struct vm_gk20a *vm = container_of(ref, struct vm_gk20a, ref); | 562 | struct vm_gk20a *vm = container_of(ref, struct vm_gk20a, ref); |
563 | 563 | ||
@@ -566,12 +566,12 @@ static void __nvgpu_vm_remove_kref(struct kref *ref) | |||
566 | 566 | ||
567 | void nvgpu_vm_get(struct vm_gk20a *vm) | 567 | void nvgpu_vm_get(struct vm_gk20a *vm) |
568 | { | 568 | { |
569 | kref_get(&vm->ref); | 569 | nvgpu_ref_get(&vm->ref); |
570 | } | 570 | } |
571 | 571 | ||
572 | void nvgpu_vm_put(struct vm_gk20a *vm) | 572 | void nvgpu_vm_put(struct vm_gk20a *vm) |
573 | { | 573 | { |
574 | kref_put(&vm->ref, __nvgpu_vm_remove_kref); | 574 | nvgpu_ref_put(&vm->ref, __nvgpu_vm_remove_ref); |
575 | } | 575 | } |
576 | 576 | ||
577 | int nvgpu_insert_mapped_buf(struct vm_gk20a *vm, | 577 | 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) | |||
202 | &vm_area->buffer_list_head, | 202 | &vm_area->buffer_list_head, |
203 | nvgpu_mapped_buf, buffer_list) { | 203 | nvgpu_mapped_buf, buffer_list) { |
204 | nvgpu_list_del(&buffer->buffer_list); | 204 | nvgpu_list_del(&buffer->buffer_list); |
205 | kref_put(&buffer->ref, gk20a_vm_unmap_locked_kref); | 205 | nvgpu_ref_put(&buffer->ref, gk20a_vm_unmap_locked_ref); |
206 | } | 206 | } |
207 | 207 | ||
208 | /* if this was a sparse mapping, free the va */ | 208 | /* 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( | |||
156 | p->sema_sea = sea; | 156 | p->sema_sea = sea; |
157 | nvgpu_init_list_node(&p->hw_semas); | 157 | nvgpu_init_list_node(&p->hw_semas); |
158 | nvgpu_init_list_node(&p->pool_list_entry); | 158 | nvgpu_init_list_node(&p->pool_list_entry); |
159 | kref_init(&p->ref); | 159 | nvgpu_ref_init(&p->ref); |
160 | 160 | ||
161 | sea->page_count++; | 161 | sea->page_count++; |
162 | nvgpu_list_add(&p->pool_list_entry, &sea->pool_list); | 162 | nvgpu_list_add(&p->pool_list_entry, &sea->pool_list); |
@@ -285,7 +285,7 @@ void nvgpu_semaphore_pool_unmap(struct nvgpu_semaphore_pool *p, | |||
285 | * Completely free a semaphore_pool. You should make sure this pool is not | 285 | * Completely free a semaphore_pool. You should make sure this pool is not |
286 | * mapped otherwise there's going to be a memory leak. | 286 | * mapped otherwise there's going to be a memory leak. |
287 | */ | 287 | */ |
288 | static void nvgpu_semaphore_pool_free(struct kref *ref) | 288 | static void nvgpu_semaphore_pool_free(struct nvgpu_ref *ref) |
289 | { | 289 | { |
290 | struct nvgpu_semaphore_pool *p = | 290 | struct nvgpu_semaphore_pool *p = |
291 | container_of(ref, struct nvgpu_semaphore_pool, ref); | 291 | container_of(ref, struct nvgpu_semaphore_pool, ref); |
@@ -314,12 +314,12 @@ static void nvgpu_semaphore_pool_free(struct kref *ref) | |||
314 | 314 | ||
315 | void nvgpu_semaphore_pool_get(struct nvgpu_semaphore_pool *p) | 315 | void nvgpu_semaphore_pool_get(struct nvgpu_semaphore_pool *p) |
316 | { | 316 | { |
317 | kref_get(&p->ref); | 317 | nvgpu_ref_get(&p->ref); |
318 | } | 318 | } |
319 | 319 | ||
320 | void nvgpu_semaphore_pool_put(struct nvgpu_semaphore_pool *p) | 320 | void nvgpu_semaphore_pool_put(struct nvgpu_semaphore_pool *p) |
321 | { | 321 | { |
322 | kref_put(&p->ref, nvgpu_semaphore_pool_free); | 322 | nvgpu_ref_put(&p->ref, nvgpu_semaphore_pool_free); |
323 | } | 323 | } |
324 | 324 | ||
325 | /* | 325 | /* |
@@ -423,7 +423,7 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch) | |||
423 | if (!s) | 423 | if (!s) |
424 | return NULL; | 424 | return NULL; |
425 | 425 | ||
426 | kref_init(&s->ref); | 426 | nvgpu_ref_init(&s->ref); |
427 | s->hw_sema = ch->hw_sema; | 427 | s->hw_sema = ch->hw_sema; |
428 | nvgpu_atomic_set(&s->value, 0); | 428 | nvgpu_atomic_set(&s->value, 0); |
429 | 429 | ||
@@ -438,7 +438,7 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch) | |||
438 | return s; | 438 | return s; |
439 | } | 439 | } |
440 | 440 | ||
441 | static void nvgpu_semaphore_free(struct kref *ref) | 441 | static void nvgpu_semaphore_free(struct nvgpu_ref *ref) |
442 | { | 442 | { |
443 | struct nvgpu_semaphore *s = | 443 | struct nvgpu_semaphore *s = |
444 | container_of(ref, struct nvgpu_semaphore, ref); | 444 | container_of(ref, struct nvgpu_semaphore, ref); |
@@ -450,10 +450,10 @@ static void nvgpu_semaphore_free(struct kref *ref) | |||
450 | 450 | ||
451 | void nvgpu_semaphore_put(struct nvgpu_semaphore *s) | 451 | void nvgpu_semaphore_put(struct nvgpu_semaphore *s) |
452 | { | 452 | { |
453 | kref_put(&s->ref, nvgpu_semaphore_free); | 453 | nvgpu_ref_put(&s->ref, nvgpu_semaphore_free); |
454 | } | 454 | } |
455 | 455 | ||
456 | void nvgpu_semaphore_get(struct nvgpu_semaphore *s) | 456 | void nvgpu_semaphore_get(struct nvgpu_semaphore *s) |
457 | { | 457 | { |
458 | kref_get(&s->ref); | 458 | nvgpu_ref_get(&s->ref); |
459 | } | 459 | } |