From 98186ec2c2127c2af65a34f9e697e04f518a79ab Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Thu, 3 Aug 2017 15:34:44 +0530 Subject: gpu: nvgpu: Add wrapper over atomic_t and atomic64_t - added wrapper structs nvgpu_atomic_t and nvgpu_atomic64_t over atomic_t and atomic64_t - added nvgpu_atomic_* and nvgpu_atomic64_* APIs to access the above wrappers. JIRA NVGPU-121 Change-Id: I61667bb0a84c2fc475365abb79bffb42b8b4786a Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/1533044 Reviewed-by: svccoveritychecker Reviewed-by: svc-mobile-coverity Reviewed-by: Terje Bergstrom GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/linux/debug_fifo.c | 8 ++++---- drivers/gpu/nvgpu/common/linux/dma.c | 4 ++-- drivers/gpu/nvgpu/common/linux/module.c | 10 +++++----- drivers/gpu/nvgpu/common/mm/lockless_allocator.c | 13 ++++++++----- drivers/gpu/nvgpu/common/mm/lockless_allocator_priv.h | 4 ++-- drivers/gpu/nvgpu/common/semaphore.c | 4 ++-- 6 files changed, 23 insertions(+), 20 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 a240a138..1763eb7e 100644 --- a/drivers/gpu/nvgpu/common/linux/debug_fifo.c +++ b/drivers/gpu/nvgpu/common/linux/debug_fifo.c @@ -167,7 +167,7 @@ static int gk20a_fifo_profile_enable(void *data, u64 val) } kref_init(&f->profile.ref); } - atomic_set(&f->profile.get, 0); + atomic_set(&f->profile.get.atomic_var, 0); f->profile.enabled = true; } } @@ -246,7 +246,7 @@ static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) return 0; } - get = atomic_read(&g->fifo.profile.get); + get = atomic_read(&g->fifo.profile.get.atomic_var); __gk20a_fifo_create_stats(g, percentiles_ioctl, PROFILE_IOCTL_EXIT, PROFILE_IOCTL_ENTRY); @@ -311,7 +311,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, 0); + atomic_set(&g->fifo.profile.get.atomic_var, 0); atomic_set(&g->fifo.profile.ref.refcount, 0); debugfs_create_file("enable", 0600, profile_root, g, @@ -342,7 +342,7 @@ struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) /* If kref is zero, profiling is not enabled */ if (!kref_get_unless_zero(&f->profile.ref)) return NULL; - index = atomic_inc_return(&f->profile.get); + index = atomic_inc_return(&f->profile.get.atomic_var); profile = &f->profile.data[index % FIFO_PROFILING_ENTRIES]; return profile; diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c index ea5b2837..2116053d 100644 --- a/drivers/gpu/nvgpu/common/linux/dma.c +++ b/drivers/gpu/nvgpu/common/linux/dma.c @@ -197,7 +197,7 @@ int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags, WARN_ON(flags != NVGPU_DMA_NO_KERNEL_MAPPING); nvgpu_mutex_acquire(&g->mm.vidmem.clear_list_mutex); - before_pending = atomic64_read(&g->mm.vidmem.bytes_pending); + before_pending = atomic64_read(&g->mm.vidmem.bytes_pending.atomic_var); addr = __nvgpu_dma_alloc(vidmem_alloc, at, size); nvgpu_mutex_release(&g->mm.vidmem.clear_list_mutex); if (!addr) { @@ -394,7 +394,7 @@ static void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem) was_empty = nvgpu_list_empty(&g->mm.vidmem.clear_list_head); nvgpu_list_add_tail(&mem->clear_list_entry, &g->mm.vidmem.clear_list_head); - atomic64_add(mem->size, &g->mm.vidmem.bytes_pending); + atomic64_add(mem->size, &g->mm.vidmem.bytes_pending.atomic_var); nvgpu_mutex_release(&g->mm.vidmem.clear_list_mutex); if (was_empty) { diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index bfbe7a58..f5c6ca1f 100644 --- a/drivers/gpu/nvgpu/common/linux/module.c +++ b/drivers/gpu/nvgpu/common/linux/module.c @@ -68,13 +68,13 @@ int gk20a_busy(struct gk20a *g) if (!g) return -ENODEV; - atomic_inc(&g->usage_count); + atomic_inc(&g->usage_count.atomic_var); down_read(&g->busy_lock); if (!gk20a_can_busy(g)) { ret = -ENODEV; - atomic_dec(&g->usage_count); + atomic_dec(&g->usage_count.atomic_var); goto fail; } @@ -87,7 +87,7 @@ int gk20a_busy(struct gk20a *g) /* Mark suspended so runtime pm will retry later */ pm_runtime_set_suspended(dev); pm_runtime_put_noidle(dev); - atomic_dec(&g->usage_count); + atomic_dec(&g->usage_count.atomic_var); goto fail; } } else { @@ -97,7 +97,7 @@ int gk20a_busy(struct gk20a *g) vgpu_pm_finalize_poweron(dev) : gk20a_pm_finalize_poweron(dev); if (ret) { - atomic_dec(&g->usage_count); + atomic_dec(&g->usage_count.atomic_var); nvgpu_mutex_release(&g->poweron_lock); goto fail; } @@ -120,7 +120,7 @@ void gk20a_idle(struct gk20a *g) { struct device *dev; - atomic_dec(&g->usage_count); + atomic_dec(&g->usage_count.atomic_var); dev = dev_from_gk20a(g); diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c index 2a569efd..eeb86095 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c @@ -65,7 +65,9 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len) ret = cmpxchg(&pa->head, head, new_head); if (ret == head) { addr = pa->base + head * pa->blk_size; - atomic_inc(&pa->nr_allocs); + nvgpu_atomic_inc(&pa->nr_allocs); + alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head, + addr); break; } head = ACCESS_ONCE(pa->head); @@ -94,7 +96,8 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr) ACCESS_ONCE(pa->next[cur_idx]) = head; ret = cmpxchg(&pa->head, head, cur_idx); if (ret == head) { - atomic_dec(&pa->nr_allocs); + nvgpu_atomic_dec(&pa->nr_allocs); + alloc_dbg(a, "Free node # %llu\n", cur_idx); break; } } @@ -125,9 +128,9 @@ static void nvgpu_lockless_print_stats(struct nvgpu_allocator *a, /* Actual stats. */ __alloc_pstat(s, a, "Stats:\n"); __alloc_pstat(s, a, " Number allocs = %d\n", - atomic_read(&pa->nr_allocs)); + nvgpu_atomic_read(&pa->nr_allocs)); __alloc_pstat(s, a, " Number free = %d\n", - pa->nr_nodes - atomic_read(&pa->nr_allocs)); + pa->nr_nodes - nvgpu_atomic_read(&pa->nr_allocs)); } #endif @@ -193,7 +196,7 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a, a->blk_size = blk_size; a->nr_nodes = nr_nodes; a->flags = flags; - atomic_set(&a->nr_allocs, 0); + nvgpu_atomic_set(&a->nr_allocs, 0); wmb(); a->inited = true; diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator_priv.h b/drivers/gpu/nvgpu/common/mm/lockless_allocator_priv.h index 32421ac1..c527bff9 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator_priv.h +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator_priv.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016 - 2017, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -109,7 +109,7 @@ struct nvgpu_lockless_allocator { bool inited; /* Statistics */ - atomic_t nr_allocs; + nvgpu_atomic_t nr_allocs; }; static inline struct nvgpu_lockless_allocator *lockless_allocator( diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c index 3e916b9d..ac45aaaa 100644 --- a/drivers/gpu/nvgpu/common/semaphore.c +++ b/drivers/gpu/nvgpu/common/semaphore.c @@ -364,7 +364,7 @@ static int __nvgpu_init_hw_sema(struct channel_gk20a *ch) hw_sema->p = p; hw_sema->idx = hw_sema_idx; hw_sema->offset = SEMAPHORE_SIZE * hw_sema_idx; - atomic_set(&hw_sema->next_value, 0); + nvgpu_atomic_set(&hw_sema->next_value, 0); nvgpu_init_list_node(&hw_sema->hw_sema_list); nvgpu_mem_wr(ch->g, &p->rw_mem, hw_sema->offset, 0); @@ -425,7 +425,7 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch) kref_init(&s->ref); s->hw_sema = ch->hw_sema; - atomic_set(&s->value, 0); + nvgpu_atomic_set(&s->value, 0); /* * Take a ref on the pool so that we can keep this pool alive for -- cgit v1.2.2