From c7bd7733e56510b72ab5f8235ca88aea52021cbb Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Thu, 29 Jun 2017 14:33:08 -0400 Subject: [PATCH] Align large buffers to BigK or huge-page boundary This should allow us to take advantage of BigK fragments and huge pages and improve TLB efficiency for VRAM allocations. Huge pages only work with 4-level page tables (gfx900 and up). BigK fragments work on older GPUs. Change-Id: I02e1fbf74de554e16fdaf44e44d03b47df45c3b0 Signed-off-by: Felix Kuehling --- src/fmm.c | 13 +++++++++++-- src/libhsakmt.h | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/fmm.c b/src/fmm.c index de46fe77c1..4ee9d71278 100644 --- a/src/fmm.c +++ b/src/fmm.c @@ -539,11 +539,20 @@ static void *aperture_allocate_area_aligned(manageable_aperture_t *app, vm_area_t *cur, *next; void *start; - MemorySizeInBytes = vm_align_area_size(app, MemorySizeInBytes); - if (align < app->align) align = app->align; + /* Huge-page and Big-K TLB optimizations require proper alignment */ + if (MemorySizeInBytes >= GPU_HUGE_PAGE_SIZE) { + if (align < GPU_HUGE_PAGE_SIZE) + align = GPU_HUGE_PAGE_SIZE; + } else if (MemorySizeInBytes >= GPU_BIGK_PAGE_SIZE) { + if (align < GPU_BIGK_PAGE_SIZE) + align = GPU_BIGK_PAGE_SIZE; + } + + MemorySizeInBytes = vm_align_area_size(app, MemorySizeInBytes); + /* Find a big enough "hole" in the address space */ cur = NULL; next = app->vm_ranges; diff --git a/src/libhsakmt.h b/src/libhsakmt.h index 7c4cc19f8c..8dd9d39ae2 100644 --- a/src/libhsakmt.h +++ b/src/libhsakmt.h @@ -55,6 +55,12 @@ extern int PAGE_SHIFT; /* VI HW bug requires this virtual address alignment */ #define TONGA_PAGE_SIZE 0x8000 +/* 64KB BigK fragment size for TLB efficiency */ +#define GPU_BIGK_PAGE_SIZE (1 << 16) + +/* 2MB huge page size for 4-level page tables on Vega10 and later GPUs */ +#define GPU_HUGE_PAGE_SIZE (2 << 20) + #define CHECK_PAGE_MULTIPLE(x) \ do { if ((uint64_t)PORT_VPTR_TO_UINT64(x) % PAGE_SIZE) return HSAKMT_STATUS_INVALID_PARAMETER; } while(0)