From 4d07572c8279f199c220e7c606cc9ffb73216d83 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Tue, 20 Sep 2016 13:32:45 +0300 Subject: gpu: nvgpu: add space query in page and buddy allocs Amount of free space in the buddy allocator is computed from the complete capacity minus currently used bytes. The page allocator just queries its underlying allocator. Bug 1787771 Bug 200233138 Change-Id: I9b6f5ef90119236a13de14e14cd0a3ee72144a11 Signed-off-by: Konsta Holtta Reviewed-on: http://git-master/r/1223761 (cherry picked from commit 0b324a60ebdf67e793ade869c252a8ddd56c04f8) Reviewed-on: http://git-master/r/1235979 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/gk20a_allocator_buddy.c | 14 ++++++++++++++ drivers/gpu/nvgpu/gk20a/gk20a_allocator_page.c | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator_buddy.c b/drivers/gpu/nvgpu/gk20a/gk20a_allocator_buddy.c index f9fb48b5..a8a031be 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator_buddy.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a_allocator_buddy.c @@ -1090,6 +1090,19 @@ static u64 gk20a_buddy_alloc_end(struct gk20a_allocator *a) return ba->end; } +static u64 gk20a_buddy_alloc_space(struct gk20a_allocator *a) +{ + struct gk20a_buddy_allocator *ba = a->priv; + u64 space; + + alloc_lock(a); + space = ba->end - ba->start - + (ba->bytes_alloced_real - ba->bytes_freed); + alloc_unlock(a); + + return space; +} + /* * Print the buddy allocator top level stats. If you pass @s as NULL then the * stats are printed to the kernel log. This lets this code be used for @@ -1180,6 +1193,7 @@ static const struct gk20a_allocator_ops buddy_ops = { .length = gk20a_buddy_alloc_length, .end = gk20a_buddy_alloc_end, .inited = gk20a_buddy_alloc_inited, + .space = gk20a_buddy_alloc_space, .fini = gk20a_buddy_allocator_destroy, diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator_page.c b/drivers/gpu/nvgpu/gk20a/gk20a_allocator_page.c index 42eb9a14..2e5d46b9 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator_page.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a_allocator_page.c @@ -57,6 +57,13 @@ static u64 gk20a_page_alloc_end(struct gk20a_allocator *a) return gk20a_alloc_end(&va->source_allocator); } +static u64 gk20a_page_alloc_space(struct gk20a_allocator *a) +{ + struct gk20a_page_allocator *va = a->priv; + + return gk20a_alloc_space(&va->source_allocator); +} + static int gk20a_page_reserve_co(struct gk20a_allocator *a, struct gk20a_alloc_carveout *co) { @@ -492,6 +499,7 @@ static const struct gk20a_allocator_ops page_ops = { .length = gk20a_page_alloc_length, .end = gk20a_page_alloc_end, .inited = gk20a_page_alloc_inited, + .space = gk20a_page_alloc_space, .fini = gk20a_page_allocator_destroy, -- cgit v1.2.2