From 02e896bc49a2002f056bec9e14a274de53720c3b Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Tue, 25 Mar 2025 16:39:06 -0700 Subject: [PATCH] anv/xe: detect the newer xe.ko memory reporting model and act accordingly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kernel commit d2d5f6d57884 ("drm/xe: Increase the XE_PL_TT watermark") changed how xe.ko reportes memory: its ioctls now report 100% of the system RAM as available. Since our policy is to report 50% of the SRAM as available for the heaps, add some code to check the amount reported by xe.ko against the amount reported by the system, then act accordingly. Reviewed-by: José Roberto de Souza Signed-off-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_physical_device.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/intel/vulkan/anv_physical_device.c b/src/intel/vulkan/anv_physical_device.c index 9ef82c90be2..067de17b562 100644 --- a/src/intel/vulkan/anv_physical_device.c +++ b/src/intel/vulkan/anv_physical_device.c @@ -1971,8 +1971,27 @@ static uint64_t anv_restrict_sys_heap_size(struct anv_physical_device *device, uint64_t kmd_reported_sram) { - if (device->info.kmd_type == INTEL_KMD_TYPE_XE) - return kmd_reported_sram; + if (device->info.kmd_type == INTEL_KMD_TYPE_XE) { + uint64_t sys_reported_sram; + if (!os_get_total_physical_memory(&sys_reported_sram)) + return kmd_reported_sram; + + /* From what I could gather, kmd_reported_sram always seems to be + * exactly half of sys_reported_sram in older Kernels, but let's leave + * some room for imprecision here in case the interfaces chosen to + * report memory end up changing, accounting things differently somehow. + * + * If we detect an older Kernel (i.e., kmd_reported_sram == ~50% of + * sys_reported_sram) we just return the values reported by the KMD + * since they are already restricted. If we detect a newer Kernel, we + * deal with the value below, along with i915.ko (which is expected to + * always report 100% of SRAM). + */ + uint64_t ratio = kmd_reported_sram * 10 / sys_reported_sram; + assert(ratio <= 11); + if (ratio <= 6) + return kmd_reported_sram; + } return kmd_reported_sram / 2; }