[Mesa-dev] [PATCH 2/2] anv: Advertise larger heap sizes

Gustaw Smolarczyk wielkiegie at gmail.com
Sat Mar 18 09:24:47 UTC 2017


18 mar 2017 05:24 "Jason Ekstrand" <jason at jlekstrand.net> napisaƂ(a):

Instead of just advertising the aperture size, we do something more
intelligent.  On systems with a full 48-bit PPGTT, we can address 100%
of the available system RAM from the GPU.  In order to keep clients from
burning 100% of your available RAM for graphics resources, we have a
nice little heuristic (which has received exactly zero tuning) to keep
things under a reasonable level of control.

Cc: Alex Smith <asmith at feralinteractive.com>
---
 src/intel/vulkan/anv_device.c  | 61 ++++++++++++++++++++++++++++++
+++---------
 src/intel/vulkan/anv_gem.c     | 16 +++++++++++
 src/intel/vulkan/anv_private.h | 13 ++++++++-
 3 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 8994e70..fd71a23 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -25,6 +25,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/sysinfo.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <xf86drm.h>
@@ -53,6 +54,48 @@ compiler_perf_log(void *data, const char *fmt, ...)
    va_end(args);
 }

+static VkResult
+anv_compute_heap_size(int fd, uint64_t *heap_size)
+{
+   uint64_t gtt_size;
+   if (anv_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE,
+                                 &gtt_size) == -1) {
+      /* If, for whatever reason, we can't actually get the GTT size from
the
+       * kernel (too old?) fall back to the aperture size.
+       */
+      anv_perf_warn("Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
+
+      if (anv_gem_get_aperture(fd, &gtt_size) == -1) {
+         return vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                          "failed to get aperture size: %m");
+      }
+   }
+
+   /* Query the total ram from the system */
+   struct sysinfo info;
+   sysinfo(&info);
+
+   uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
+
+   /* 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 * 1024ull * 1024ull * 1024ull)
+      available_ram = total_ram / 2;
+   else
+      available_ram = total_ram * 3 / 4;


This will result in 3/4 in case of exactly 4GB of RAM present. Did you mean
to use <= instead of <?

Regards,
Gustaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170318/40578ea8/attachment.html>


More information about the mesa-dev mailing list