[1/1] tests/gem_exec_reloc: basic-range: Use actual GEM chunk size

Submitted by Janusz Krzysztofik on May 17, 2019, 11:17 a.m.

Details

Message ID 20190517111723.28396-2-janusz.krzysztofik@linux.intel.com
State New
Headers show
Series "tests/gem_exec_reloc: basic-range: Use actual GEM chunk size" ( rev: 2 1 ) in IGT - Trybot

Not browsing as part of any series.

Commit Message

Janusz Krzysztofik May 17, 2019, 11:17 a.m.
From: Janusz Krzysztofik <janusz.krzysztofik@intel.com>

The basic-range subtest assumes 4kB chunk size for GEM buffer object
allocation.  On hardware with a bigger chunk size this test may fail as
buffer objects may overlap.

Obtain actual GEM chunk size and use it for safe offset calculation.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@intel.com>
---
 tests/gem_exec_reloc.c | 47 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/gem_exec_reloc.c b/tests/gem_exec_reloc.c
index 837f60a6..718c8d05 100644
--- a/tests/gem_exec_reloc.c
+++ b/tests/gem_exec_reloc.c
@@ -511,6 +511,33 @@  static uint64_t gen8_canonical_address(uint64_t address)
 	return sign_extend(address, 47);
 }
 
+static int create_ioctl(int fd, struct drm_i915_gem_create *create)
+{
+        int err = 0;
+
+        if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, create)) {
+                err = -errno;
+                igt_assume(err != 0);
+        }
+
+        errno = 0;
+        return err;
+}
+
+static uint64_t get_chunk_size(int fd)
+{
+	int size_initial_nonaligned = 15;
+	struct drm_i915_gem_create create = {
+		.size = size_initial_nonaligned,
+	};
+
+	igt_assert_eq(create_ioctl(fd, &create), 0);
+	gem_close(fd, create.handle);
+
+	igt_assert_neq(create.size, size_initial_nonaligned);
+	return create.size;
+}
+
 static void basic_range(int fd, unsigned flags)
 {
 	struct drm_i915_gem_relocation_entry reloc[128];
@@ -518,16 +545,20 @@  static void basic_range(int fd, unsigned flags)
 	struct drm_i915_gem_execbuffer2 execbuf;
 	uint64_t address_mask = has_64b_reloc(fd) ? ~(uint64_t)0 : ~(uint32_t)0;
 	uint64_t gtt_size = gem_aperture_size(fd);
+	uint64_t chunk_size = get_chunk_size(fd);
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
 	igt_spin_t *spin = NULL;
-	int count, n;
+	int chunk_order, count, n;
 
 	igt_require(gem_has_softpin(fd));
 
-	for (count = 12; gtt_size >> (count + 1); count++)
+	for (chunk_order = 0; chunk_size >> (chunk_order + 1); chunk_order++)
+		;
+
+	for (count = chunk_order; gtt_size >> (count + 1); count++)
 		;
 
-	count -= 12;
+	count -= chunk_order;
 
 	memset(obj, 0, sizeof(obj));
 	memset(reloc, 0, sizeof(reloc));
@@ -535,8 +566,8 @@  static void basic_range(int fd, unsigned flags)
 
 	n = 0;
 	for (int i = 0; i <= count; i++) {
-		obj[n].handle = gem_create(fd, 4096);
-		obj[n].offset = (1ull << (i + 12)) - 4096;
+		obj[n].handle = gem_create(fd, chunk_size);
+		obj[n].offset = (1ull << (i + chunk_order)) - chunk_size;
 		obj[n].offset = gen8_canonical_address(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
@@ -555,8 +586,8 @@  static void basic_range(int fd, unsigned flags)
 		n++;
 	}
 	for (int i = 1; i < count; i++) {
-		obj[n].handle = gem_create(fd, 4096);
-		obj[n].offset = 1ull << (i + 12);
+		obj[n].handle = gem_create(fd, chunk_size);
+		obj[n].offset = 1ull << (i + chunk_order);
 		obj[n].offset = gen8_canonical_address(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
@@ -576,7 +607,7 @@  static void basic_range(int fd, unsigned flags)
 	}
 	igt_require(n);
 
-	obj[n].handle = gem_create(fd, 4096);
+	obj[n].handle = gem_create(fd, chunk_size);
 	obj[n].relocs_ptr = to_user_pointer(reloc);
 	obj[n].relocation_count = n;
 	gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));