[PATCH i-g-t 14/15] i915/gem_create: Measure object creation latency for different memory regions

Matthew Auld matthew.auld at intel.com
Tue May 11 12:33:17 UTC 2021


From: Chris Wilson <chris.p.wilson at intel.com>

Ideally all objects are equally fast.

Signed-off-by: Chris Wilson <chris.p.wilson at intel.com>
Reviewed-by: Matthew Auld <matthew.auld at intel.com>
---
 tests/i915/gem_create.c | 86 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
index 4ee13e64..8e34cd05 100644
--- a/tests/i915/gem_create.c
+++ b/tests/i915/gem_create.c
@@ -346,6 +346,74 @@ static void busy_create(int i915, const struct memory_region *r, int timeout)
 	igt_stop_hang_detector();
 }
 
+static const char *size_repr(uint64_t sz, char *buf, size_t len)
+{
+	const char *unit;
+
+	if (sz < 1ull << 20) {
+		unit = "KiB";
+		sz >>= 10;
+	} else if (sz < 1ull << 30) {
+		unit = "MiB";
+		sz >>= 20;
+	} else {
+		unit = "GiB";
+		sz >>= 30;
+	}
+
+	snprintf(buf, len, "%"PRIu64"%s", sz, unit);
+	return buf;
+}
+
+static void
+max_create(int i915, const struct memory_region *r, unsigned int flags)
+#define MAX_POPULATE 0x1
+{
+	struct drm_i915_gem_create_ext_memory_regions p_region = {
+		.base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS },
+		.regions = to_user_pointer(&r->ci),
+		.num_regions = 1,
+	};
+	uint64_t size, total;
+	uint32_t handle;
+
+	size = 4096;
+	igt_assert_eq(__gem_create_ext(i915, &size, &handle, &p_region.base), 0);
+	igt_info("%s min object size is %"PRIu64"\n", r->name, size);
+	gem_close(i915, handle);
+
+	for (; size <= r->size / 2; size *= 2) {
+		for (total = size; total <= r->size / 2; total *= 2) {
+			unsigned long count = total / size;
+			int fd = gem_reopen_driver(i915);
+			struct timespec tv;
+			uint64_t elapsed;
+			char str[80];
+
+			igt_nsec_elapsed(memset(&tv, 0, sizeof(tv)));
+			while (count--) {
+				handle = gem_create_ext(fd, size, &p_region.base);
+				if (flags & MAX_POPULATE) {
+					char *ptr = gem_mmap__device_coherent(fd, handle, 0, size, PROT_READ);
+					gem_set_domain(fd, handle, I915_GEM_DOMAIN_WC, 0);
+					for (int p = 0; p < size; p += 4096)
+						igt_assert_eq(ptr[p], 0);
+					munmap(ptr, size);
+				}
+			}
+			elapsed = igt_nsec_elapsed(&tv);
+			close(fd); /* discard all the objects at once */
+
+			igt_info("%s: %s %9lu %s objects took %.1fms\n",
+				 r->name,
+				 flags & MAX_POPULATE ? "Populating" : "Creating",
+				 total / size,
+				 size_repr(size, str, sizeof(str)),
+				 elapsed * 1e-6);
+		}
+	}
+}
+
 static void size_update(int fd)
 {
 	int size_initial_nonaligned = 15;
@@ -583,6 +651,24 @@ igt_main
 		}
 	}
 
+	igt_subtest_with_dynamic("max-create") {
+		struct memory_region *r;
+
+		for_each_memory_region(r, fd) {
+			igt_dynamic_f("%s", r->name)
+				max_create(fd, r, 0);
+		}
+	}
+
+	igt_subtest_with_dynamic("max-populate") {
+		struct memory_region *r;
+
+		for_each_memory_region(r, fd) {
+			igt_dynamic_f("%s", r->name)
+				max_create(fd, r, MAX_POPULATE);
+		}
+	}
+
 	igt_fixture
 		close(fd);
 }
-- 
2.26.3



More information about the Intel-gfx-trybot mailing list