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 <mary.guillemard@collabora.com>
Reviewed by: Eric R. Smith <eric.smith@collabora.com>

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30088>
This commit is contained in:
Mary Guillemard
2024-07-08 12:38:48 +02:00
committed by Marge Bot
parent 02e38664f3
commit 10d9bc3a2c
3 changed files with 35 additions and 10 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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 */});