summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-08-15 14:16:07 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-08-16 14:04:20 -0400
commit61ef5a58744d22e65d3ad7c3a04a2521d0ccb6af (patch)
tree5b8836864d06495101e15d381f8fdcb8f19f6a6a /drivers/gpu/nvgpu/common/mm/lockless_allocator.c
parentff38ab4dcd87088dc60c870aaf910fcdc4af5918 (diff)
gpu: nvgpu: Deterministic submit fix
Fix some simple pointer arithmetic errors in the deterministic submit path. The lockless allocator was doing a subtraction to determine the correct offset of the element to free. However, this subtraction was using the base address and a numeric offset - not a pointer offset. Thus the difference computed was in bytes not in elements of the block size. The fix is simple: just divide by the block size. Also this modifies the debugging statement a bit so that a bit more information is printed at more useful times. Lastly, a pointer to numeric cast was fixed in the fence code. Change-Id: I514724205f1b73805b21e979481a13ac689f3482 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1538905 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> Reviewed-by: Aingara Paramakuru <aparamakuru@nvidia.com> Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: Konsta Holtta <kholtta@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/lockless_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/lockless_allocator.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
index 944b4b0f..2a569efd 100644
--- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
@@ -66,12 +66,16 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len)
66 if (ret == head) { 66 if (ret == head) {
67 addr = pa->base + head * pa->blk_size; 67 addr = pa->base + head * pa->blk_size;
68 atomic_inc(&pa->nr_allocs); 68 atomic_inc(&pa->nr_allocs);
69 alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head,
70 addr);
71 break; 69 break;
72 } 70 }
73 head = ACCESS_ONCE(pa->head); 71 head = ACCESS_ONCE(pa->head);
74 } 72 }
73
74 if (addr)
75 alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head, addr);
76 else
77 alloc_dbg(a, "Alloc failed!\n");
78
75 return addr; 79 return addr;
76} 80}
77 81
@@ -81,7 +85,9 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr)
81 int head, ret; 85 int head, ret;
82 u64 cur_idx; 86 u64 cur_idx;
83 87
84 cur_idx = addr - pa->base; 88 cur_idx = (addr - pa->base) / pa->blk_size;
89
90 alloc_dbg(a, "Free node # %llu @ addr 0x%llx\n", cur_idx, addr);
85 91
86 while (1) { 92 while (1) {
87 head = ACCESS_ONCE(pa->head); 93 head = ACCESS_ONCE(pa->head);
@@ -89,7 +95,6 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr)
89 ret = cmpxchg(&pa->head, head, cur_idx); 95 ret = cmpxchg(&pa->head, head, cur_idx);
90 if (ret == head) { 96 if (ret == head) {
91 atomic_dec(&pa->nr_allocs); 97 atomic_dec(&pa->nr_allocs);
92 alloc_dbg(a, "Free node # %llu\n", cur_idx);
93 break; 98 break;
94 } 99 }
95 } 100 }