[PATCH 07/11] tests/i915/gem_gpu_meminfo: Check available memory reporting
Matthew Auld
matthew.auld at intel.com
Fri Apr 23 11:38:21 UTC 2021
From: Andrzej Turko <andrzej.turko at linux.intel.com>
Introduce a test which checks memory region reporting
by the gem_get_query_memory_regions procedure (including
available memory size reporting).
Signed-off-by: Andrzej Turko <andrzej.turko at linux.intel.com>
Cc: Zbigniew Kempczynski <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
---
tests/i915/gem_gpu_meminfo.c | 134 +++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 135 insertions(+)
create mode 100644 tests/i915/gem_gpu_meminfo.c
diff --git a/tests/i915/gem_gpu_meminfo.c b/tests/i915/gem_gpu_meminfo.c
new file mode 100644
index 00000000..64f232e7
--- /dev/null
+++ b/tests/i915/gem_gpu_meminfo.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2008 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Eric Anholt <eric at anholt.net>
+ *
+ */
+
+#include "igt.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "drm.h"
+
+IGT_TEST_DESCRIPTION("Verify region reporting query correctness.");
+
+static void test_get_gpu_meminfo(int i915,
+ struct local_drm_i915_query_memory_regions *info)
+{
+ intel_dump_gpu_meminfo(info);
+ igt_info("num regions <smem: %d>\n",
+ gpu_meminfo_region_count(info, LOCAL_I915_MEMORY_CLASS_SYSTEM));
+
+}
+
+#define OBJSIZE (1024 * 1024 * 16)
+
+static void test_get_gpu_memsize(int i915, uint32_t region)
+{
+ uint32_t handle;
+ uint64_t avail, prev_avail;
+ void *ptr;
+
+ struct local_drm_i915_query_memory_regions *info;
+
+ info = gem_get_query_memory_regions(i915);
+
+ igt_debug("system total_size: 0x%lx\n",
+ gpu_meminfo_region_total_size(info, LOCAL_I915_MEMORY_CLASS_SYSTEM));
+ igt_debug("system total_available: 0x%lx\n",
+ gpu_meminfo_region_total_available(info, LOCAL_I915_MEMORY_CLASS_SYSTEM));
+
+
+ switch (MEMORY_TYPE_FROM_REGION(region)) {
+ case LOCAL_I915_MEMORY_CLASS_SYSTEM:
+ prev_avail = gpu_meminfo_region_total_available(info, LOCAL_I915_MEMORY_CLASS_SYSTEM);
+ if (prev_avail == -1)
+ break;
+
+ free(info);
+ handle = gem_create_in_memory_regions(i915, OBJSIZE, region);
+ ptr = gem_mmap__cpu(i915, handle, 0, OBJSIZE, PROT_WRITE);
+ memset(ptr, 0, OBJSIZE);
+
+ info = gem_get_query_memory_regions(i915);
+ avail = gpu_meminfo_region_total_available(info, LOCAL_I915_MEMORY_CLASS_SYSTEM);
+ igt_debug("system avail: 0x%lx, prev avail: 0x%0lx\n",
+ prev_avail, avail);
+ igt_assert(prev_avail > avail);
+
+ gem_close(i915, handle);
+ munmap(ptr, OBJSIZE);
+ break;
+ }
+
+ free(info);
+}
+
+igt_main
+{
+ struct local_drm_i915_query_memory_regions *regions;
+ struct igt_collection *set, *region_set;
+ int i915;
+
+ igt_fixture {
+ i915 = drm_open_driver(DRIVER_INTEL);
+
+ regions = gem_get_query_memory_regions(i915);
+ igt_assert(regions);
+
+ set = get_memory_region_set(regions,
+ I915_SYSTEM_MEMORY);
+ }
+
+ igt_describe("Get meminfo from region query");
+ igt_subtest("meminfo") {
+ igt_debug("fd: %d\n", i915);
+ test_get_gpu_meminfo(i915, regions);
+ }
+
+ igt_describe("Verify region meminfo update correctness on alloc");
+ igt_subtest_with_dynamic("memsize")
+ for_each_combination(region_set, 1, set) {
+ uint32_t region = igt_collection_get_value(region_set, 0);
+ char *sub_name = memregion_dynamic_subtest_name(region_set);
+
+ igt_dynamic_f("%s", sub_name)
+ test_get_gpu_memsize(i915, region);
+
+ free(sub_name);
+ }
+
+ igt_fixture {
+ free(regions);
+ close(i915);
+ igt_collection_destroy(set);
+ }
+
+}
diff --git a/tests/meson.build b/tests/meson.build
index 19cc4ebe..594834ef 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -168,6 +168,7 @@ i915_progs = [
'gem_flink_basic',
'gem_flink_race',
'gem_gpgpu_fill',
+ 'gem_gpu_meminfo',
'gem_gtt_cpu_tlb',
'gem_gtt_hog',
'gem_gtt_speed',
--
2.26.3
More information about the Intel-gfx-trybot
mailing list