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>
This commit is contained in:
Alex Waterman
2017-08-15 11:16:07 -07:00
committed by mobile promotions
parent ff38ab4dcd
commit 61ef5a5874
2 changed files with 10 additions and 5 deletions

View File

@@ -66,12 +66,16 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len)
if (ret == head) { if (ret == head) {
addr = pa->base + head * pa->blk_size; addr = pa->base + head * pa->blk_size;
atomic_inc(&pa->nr_allocs); atomic_inc(&pa->nr_allocs);
alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head,
addr);
break; break;
} }
head = ACCESS_ONCE(pa->head); head = ACCESS_ONCE(pa->head);
} }
if (addr)
alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head, addr);
else
alloc_dbg(a, "Alloc failed!\n");
return addr; return addr;
} }
@@ -81,7 +85,9 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr)
int head, ret; int head, ret;
u64 cur_idx; u64 cur_idx;
cur_idx = addr - pa->base; cur_idx = (addr - pa->base) / pa->blk_size;
alloc_dbg(a, "Free node # %llu @ addr 0x%llx\n", cur_idx, addr);
while (1) { while (1) {
head = ACCESS_ONCE(pa->head); head = ACCESS_ONCE(pa->head);
@@ -89,7 +95,6 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr)
ret = cmpxchg(&pa->head, head, cur_idx); ret = cmpxchg(&pa->head, head, cur_idx);
if (ret == head) { if (ret == head) {
atomic_dec(&pa->nr_allocs); atomic_dec(&pa->nr_allocs);
alloc_dbg(a, "Free node # %llu\n", cur_idx);
break; break;
} }
} }

View File

@@ -51,7 +51,7 @@ static void gk20a_fence_free(struct kref *ref)
if (f->allocator) { if (f->allocator) {
if (nvgpu_alloc_initialized(f->allocator)) if (nvgpu_alloc_initialized(f->allocator))
nvgpu_free(f->allocator, (size_t)f); nvgpu_free(f->allocator, (u64)(uintptr_t)f);
} else } else
nvgpu_kfree(g, f); nvgpu_kfree(g, f);
} }