From 10d9bc3a2ce4878b50926b0578ab33c37c7561bc Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Mon, 8 Jul 2024 12:38:48 +0200 Subject: [PATCH] panfrost: Fetch available system memory This reproduces panvk logic of showing how much memory is available while taking into account the address space limits we have. Signed-off-by: Mary Guillemard Reviewed by: Eric R. Smith Part-of: --- src/gallium/drivers/panfrost/pan_device.c | 9 +++---- src/gallium/drivers/panfrost/pan_device.h | 6 +++++ src/gallium/drivers/panfrost/pan_screen.c | 30 ++++++++++++++++++++--- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_device.c b/src/gallium/drivers/panfrost/pan_device.c index 267868e0bee..afd2cec7716 100644 --- a/src/gallium/drivers/panfrost/pan_device.c +++ b/src/gallium/drivers/panfrost/pan_device.c @@ -54,9 +54,6 @@ panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt) return panfrost_query_compressed_formats(&dev->kmod.props) & (1 << idx); } -/* Always reserve the lower 32MB. */ -#define PANFROST_VA_RESERVE_BOTTOM 0x2000000ull - void panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) { @@ -81,10 +78,10 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) /* 48bit address space max, with the lower 32MB reserved. We clamp * things so it matches kmod VA range limitations. */ - uint64_t user_va_start = panfrost_clamp_to_usable_va_range( - dev->kmod.dev, PANFROST_VA_RESERVE_BOTTOM); + uint64_t user_va_start = + panfrost_clamp_to_usable_va_range(dev->kmod.dev, PAN_VA_USER_START); uint64_t user_va_end = - panfrost_clamp_to_usable_va_range(dev->kmod.dev, 1ull << 48ull); + panfrost_clamp_to_usable_va_range(dev->kmod.dev, PAN_VA_USER_END); dev->kmod.vm = pan_kmod_vm_create( dev->kmod.dev, PAN_KMOD_VM_FLAG_AUTO_VA | PAN_KMOD_VM_FLAG_TRACK_ACTIVITY, diff --git a/src/gallium/drivers/panfrost/pan_device.h b/src/gallium/drivers/panfrost/pan_device.h index 4eb7b4b0dd6..ed8f03a8d47 100644 --- a/src/gallium/drivers/panfrost/pan_device.h +++ b/src/gallium/drivers/panfrost/pan_device.h @@ -53,6 +53,12 @@ extern "C" { #endif +/* Always reserve the lower 32MB */ +#define PAN_VA_USER_START 0x2000000ull + +/* Max address space size allowed */ +#define PAN_VA_USER_END (1ull << 48ull) + /* Driver limits */ #define PAN_MAX_CONST_BUFFERS 16 diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index 36be6e6a9e7..5cca2d69713 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -787,7 +787,32 @@ panfrost_get_compute_param(struct pipe_screen *pscreen, RET((uint64_t[]){dev->arch >= 6 ? 256 : 128}); case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: - RET((uint64_t[]){1024 * 1024 * 512 /* Maybe get memory */}); + case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE: { + uint64_t total_ram; + + if (!os_get_total_physical_memory(&total_ram)) + return 0; + + /* We don't want to burn too much ram with the GPU. If the user has 4GiB + * or less, we use at most half. If they have more than 4GiB, we use 3/4. + */ + uint64_t available_ram; + if (total_ram <= 4ull * 1024 * 1024 * 1024) + available_ram = total_ram / 2; + else + available_ram = total_ram * 3 / 4; + + /* 48bit address space max, with the lower 32MB reserved. We clamp + * things so it matches kmod VA range limitations. + */ + uint64_t user_va_start = + panfrost_clamp_to_usable_va_range(dev->kmod.dev, PAN_VA_USER_START); + uint64_t user_va_end = + panfrost_clamp_to_usable_va_range(dev->kmod.dev, PAN_VA_USER_END); + + /* We cannot support more than the VA limit */ + RET((uint64_t[]){MIN2(available_ram, user_va_end - user_va_start)}); + } case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: RET((uint64_t[]){32768}); @@ -796,9 +821,6 @@ panfrost_get_compute_param(struct pipe_screen *pscreen, case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: RET((uint64_t[]){4096}); - case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE: - RET((uint64_t[]){1024 * 1024 * 512 /* Maybe get memory */}); - case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY: RET((uint32_t[]){800 /* MHz -- TODO */});