Mesa (main): anv: Use intel_i915_query_alloc for memory regions
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jul 16 14:29:49 UTC 2021
Module: Mesa
Branch: main
Commit: 35ec1d9730cd1d0e3d8f212d5edcea53fe7cc518
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=35ec1d9730cd1d0e3d8f212d5edcea53fe7cc518
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Wed Jul 7 14:32:23 2021 -0500
anv: Use intel_i915_query_alloc for memory regions
Error handling with DRM_IOCTL_I915_QUERY is tricky and we got it wrong
in one of the two calls here. Use the common helper instead. This also
fixes a theoretical bug where calloc() fails. While we're here, inline
anv_track_meminfo because we're not really benefiting from having it
separate anymore.
Fixes: 65e8d72bc106 "anv: Query memory region info"
Reviewed-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11770>
---
src/intel/vulkan/anv_device.c | 38 ++++++++------------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 158d6734d35..9aeabc9b381 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -328,13 +328,17 @@ get_device_extensions(const struct anv_physical_device *device,
};
}
-static void
-anv_track_meminfo(struct anv_physical_device *device,
- const struct drm_i915_query_memory_regions *mem_regions)
+static bool
+anv_get_query_meminfo(struct anv_physical_device *device, int fd)
{
+ struct drm_i915_query_memory_regions *mem_regions =
+ intel_i915_query_alloc(fd, DRM_I915_QUERY_MEMORY_REGIONS);
+ if (mem_regions == NULL)
+ return false;
+
for(int i = 0; i < mem_regions->num_regions; i++) {
switch(mem_regions->regions[i].region.memory_class) {
- case I915_MEMORY_CLASS_SYSTEM:
+ case I915_MEMORY_CLASS_SYSTEM:
device->sys.region = mem_regions->regions[i].region;
device->sys.size = mem_regions->regions[i].probed_size;
break;
@@ -346,32 +350,6 @@ anv_track_meminfo(struct anv_physical_device *device,
break;
}
}
-}
-
-static bool
-anv_get_query_meminfo(struct anv_physical_device *device, int fd)
-{
- struct drm_i915_query_item item = {
- .query_id = DRM_I915_QUERY_MEMORY_REGIONS
- };
-
- struct drm_i915_query query = {
- .num_items = 1,
- .items_ptr = (uintptr_t) &item,
- };
-
- if (drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query))
- return false;
-
- struct drm_i915_query_memory_regions *mem_regions = calloc(1, item.length);
- item.data_ptr = (uintptr_t) mem_regions;
-
- if (drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query) || item.length <= 0) {
- free(mem_regions);
- return false;
- }
-
- anv_track_meminfo(device, mem_regions);
free(mem_regions);
return true;
More information about the mesa-commit
mailing list