[PATCH i-g-t 2/3] tests/gem_exec_kamil: Add simple igt tests

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri Oct 22 14:35:58 UTC 2021


Simple test for trybot.

Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 tests/i915/gem_exec_kamil.c | 231 +++++++++++++++---------------------
 1 file changed, 97 insertions(+), 134 deletions(-)

diff --git a/tests/i915/gem_exec_kamil.c b/tests/i915/gem_exec_kamil.c
index 94366b30..a95e23ae 100644
--- a/tests/i915/gem_exec_kamil.c
+++ b/tests/i915/gem_exec_kamil.c
@@ -21,83 +21,34 @@
  * IN THE SOFTWARE.
  */
 
+#include <sys/file.h>
+#include "ioctl_wrappers.h"
 #include "igt.h"
 #include "igt_collection.h"
 
 #include "i915/gem_create.h"
 
-IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");
+IGT_TEST_DESCRIPTION("Simple tests for experiment and learning.");
 
-static void gem(int fd)
+static inline uint64_t get_reloc_ahnd2(int fd, uint32_t ctx)
 {
-	uint32_t bb = gem_create(fd, 4096); // todo: why fd+1 works ???
+	bool do_relocs = !gem_uses_full_ppgtt(fd);
 
-	igt_info("bb handle: %x\n", bb);
-	gem_close(fd, bb);
-	igt_info("bb closed: %x\n", bb);
+	return do_relocs ? 0 : intel_allocator_open(fd, ctx, INTEL_ALLOCATOR_RELOC);
 }
 
-static void offsety(int i915)
+static void basic(int fd)
 {
-	uint32_t obiekt = gem_create(i915, 8192);
-	uint32_t bb = gem_create(i915, 4096);
-	uint32_t fake = gem_create(i915, 0x5000);
-	const uint32_t bbe = MI_BATCH_BUFFER_END;
-	int i;
-	uint32_t *ptr;
-
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 obj[3];
-	struct drm_i915_gem_relocation_entry reloc = {};
-
-	gem_write(i915, bb, 0, &bbe, sizeof(bbe));
-
-	ptr = gem_mmap__cpu_coherent(i915, bb, 0, 4096, PROT_READ);
-	for (i = 0; i < 8; i++)
-		igt_info("[%04x]: %08x\n", i, ptr[i]);
-	gem_munmap(ptr, 4096);
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(obj);
-	execbuf.buffer_count = 3;
-
-	memset(obj, 0, sizeof(obj));
-	obj[0].handle = fake;
-	obj[0].offset = 0;
-	obj[0].flags = EXEC_OBJECT_PINNED;
-	obj[1].handle = obiekt;
-	obj[1].alignment = 0x2000;
-	obj[2].handle = bb;
-	obj[2].relocation_count = 1;
-	obj[2].relocs_ptr = to_user_pointer(&reloc);
-	obj[2].offset = 0;
-	// offset = 0 with PINNED page will cause test fail, conflict with offset for fake
-	// obj[2].flags = EXEC_OBJECT_PINNED;
-
-	reloc.presumed_offset = -1;
-	reloc.offset = 16;
-	reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
-	reloc.write_domain = I915_GEM_DOMAIN_INSTRUCTION;
-	reloc.target_handle = obj[1].handle;
-
-	igt_info("A obj[0].offset: %llx, handle: %u\n", obj[0].offset, obj[0].handle);
-	igt_info("A obj[1].offset: %llx, handle: %u\n", obj[1].offset, obj[1].handle);
-	igt_info("A obj[2].offset: %llx, handle: %u\n", obj[2].offset, obj[2].handle);
-	gem_execbuf(i915, &execbuf);
-
-	igt_info("B obj[0].offset: %llx, handle: %u\n", obj[0].offset, obj[0].handle);
-	igt_info("B obj[1].offset: %llx, handle: %u\n", obj[1].offset, obj[1].handle);
-	igt_info("B obj[2].offset: %llx, handle: %u\n", obj[2].offset, obj[2].handle);
+	uint32_t bb = gem_create(fd, 4096); // todo: why fd+1 works ???
 
-	ptr = gem_mmap__cpu_coherent(i915, bb, 0, 4096, PROT_READ);
-	for (i = 0; i < 8; i++)
-		igt_info("[%04x]: %08x\n", i, ptr[i]);
-	gem_munmap(ptr, 4096);
+	igt_info("bb handle: %x\n", bb);
+	gem_close(fd, bb);
+	igt_info("bb closed: %x\n", bb);
 }
 
 #define MI_COPY ((2 << 29) | (0x53 << 22) | (3 << 20) | 8)
 
-static void copyrnd(int i915, bool use_reloc)
+static void copyrnd(int i915, uint64_t ahnd, int child)
 {
 	uint32_t src = gem_create(i915, 4096);
 	uint32_t dst = gem_create(i915, 4096);
@@ -106,11 +57,23 @@ static void copyrnd(int i915, bool use_reloc)
 	int i;
 	uint32_t *ptr;
 	char myaddr[128], mybuff[1024], mybatch[1024];
+	uint64_t offbb, offsrc, offdst;
 
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 obj[3];
 	struct drm_i915_gem_relocation_entry reloc[2];
 
+	flock(i915, LOCK_EX);
+	igt_info("child: %u, gem: %u %u %u\n", child, src, dst, bb);
+	fflush(stdout);
+	flock(i915, LOCK_UN);
+
+	/* offbb = intel_allocator_alloc_with_strategy(ahnd, bb, 0x1000, 0,
+						    ALLOC_STRATEGY_LOW_TO_HIGH); */
+	offbb = get_offset(ahnd, bb, 0x1000, 0);
+	offsrc = get_offset(ahnd, src, 0x1000, 0);
+	offdst = get_offset(ahnd, dst, 0x1000, 0);
+
 	ptr = gem_mmap__cpu_coherent(i915, src, 0, 4096, PROT_READ|PROT_WRITE);
 	for (i = 0; i < 4096/4; i++)
 		ptr[i] = i; //rnd();
@@ -123,14 +86,14 @@ static void copyrnd(int i915, bool use_reloc)
 	// dst
 	batch[i++] = 0; // Y1, X1 top, left
 	batch[i++] = (1 << 16) | 0x400; // Y2, X2 bottom, right 0,1024 ??? 1 or 0 ???
-	batch[i++] = 0x1000; // dst addr low-endian
-	batch[i++] = 0; // dst addr high bits
+	batch[i++] = offdst; // dst addr low-endian
+	batch[i++] = offdst >> 32; // dst addr high bits
 	// src
 	batch[i++] = 0; // Y1, X1 top, left
 	batch[i++] = 1024; // src pitch
 	//
-	batch[i++] = 0x2000; // src addr low-endian
-	batch[i++] = 0; // src addr
+	batch[i++] = offsrc; // src addr low-endian
+	batch[i++] = offsrc >> 32; // src addr
 	igt_assert((i % 2) == 0);
 	batch[i++] = MI_BATCH_BUFFER_END;
 	batch[i++] = 0; // MI_NOP
@@ -148,8 +111,8 @@ static void copyrnd(int i915, bool use_reloc)
 	obj[1].flags = EXEC_OBJECT_WRITE;
 	obj[1].handle = dst;
 	obj[2].handle = bb;
-	obj[2].offset = 0;
-	if (use_reloc) {
+	obj[2].offset = offbb;
+	if (!ahnd) {
 		memset(reloc, 0, sizeof(reloc));
 		reloc[0].offset = 4*sizeof(uint32_t);
 		reloc[0].presumed_offset = -1;
@@ -164,15 +127,15 @@ static void copyrnd(int i915, bool use_reloc)
 		obj[2].relocation_count = 2;
 		obj[2].relocs_ptr = to_user_pointer(reloc);
 	} else {
-		obj[0].offset = 0x2000;
+		obj[0].offset = offsrc;
 		obj[0].flags = EXEC_OBJECT_PINNED;
-		obj[1].offset = 0x1000;
+		obj[1].offset = offdst;
 		obj[1].flags |= EXEC_OBJECT_PINNED;
 	}
 
 	gem_execbuf(i915, &execbuf);
 	i = getpid();
-	sprintf(myaddr, "%04x s/d %06" PRIx64 "/%06" PRIx64, i,
+	sprintf(myaddr, "%02d %04x s/d %06" PRIx64 "/%06" PRIx64, child, i,
 		 (uint64_t)obj[0].offset, (uint64_t)obj[1].offset);
 	//igt_info("%s\n", myaddr);
 	//
@@ -195,35 +158,69 @@ static void copyrnd(int i915, bool use_reloc)
 	sprintf(mybatch, "%x %x %x %x %06x %x %x %x %x", ptr[0], ptr[1], ptr[2], ptr[3],
 			ptr[4], ptr[5], ptr[6], ptr[7], ptr[8]);
 	gem_munmap(ptr, 4096);
+	flock(i915, LOCK_EX);
 	igt_info("%s %s %s\n", myaddr, mybuff, mybatch);
+	fflush(stdout);
+	flock(i915, LOCK_UN);
+	gem_close(i915, bb);
+	gem_close(i915, src);
+	gem_close(i915, dst);
+	put_offset(ahnd, bb);
+	put_offset(ahnd, src);
+	put_offset(ahnd, dst);
 }
-
-static void fork_ten(int i915)
+/*
+static void create(int i915)
 {
-	int child;
-	time_t t;
-	const int n = 10;
-
-	/* Intializes random number generator */
-	//srand((unsigned) time(&t));
-	srand(42); //3137417);
+	uint32_t h = gem_create(i915, 4096);
+	int fdh = prime_handle_to_fd(i915, h);
+	igt_spin_t *spin = igt_spin_new(i915, .fence = fdh, .flags = IGT_SPIN_FENCE_IN);
 
-	// igt_fork() - re-worked macro
-	for (child = 0; child < n; ++child) {
-		if(__igt_fork())
-			break;
-	}
+	igt_info("fdh=%d\n", fdh);
+	sleep(1);
+	igt_spin_free(i915, spin);
 
-	if (child == n) { // parent
-		igt_waitchildren_timeout(3, "fork_ten wait timeout"); //int seconds, const char *reason
-	} else { // children
-		//srand((unsigned) time(&t));
-		for (int i=0; i < 2*child; ++i) rand();
+}
+*/
 
-		usleep(1000 + (rand() % 8000));
-		copyrnd(i915, true);
-		exit(0);
+static void forkten(int i915, int N)
+{
+	//time_t t;
+	uint64_t ahnd;
+
+	igt_info("parent: %d\n", getpid());
+	intel_allocator_multiprocess_start();
+	//ahnd = intel_allocator_open(i915, 0, INTEL_ALLOCATOR_SIMPLE);
+	ahnd = get_reloc_ahnd2(i915, 0);
+	igt_info("parent ahnd: %lld\n", (long long)ahnd);
+	fflush(stdout);
+	//srand((unsigned) time(&t));
+	srand(42); // or other magic, like 3137
+
+	igt_fork(child, N) {
+		/*
+		 * children
+		 * srand((unsigned) time(&t));
+		 */
+		for (int i = 0; i <= child; ++i)
+			rand();
+
+		usleep(1000 + (rand() % 20000));
+		ahnd = get_reloc_ahnd2(i915, 0);
+
+		copyrnd(i915, ahnd, child);
+
+		put_ahnd(ahnd);
+		flock(i915, LOCK_EX);
+		igt_info("child: %02d exit\n", child);
+		fflush(stdout);
+		flock(i915, LOCK_UN);
 	}
+
+	igt_waitchildren_timeout(3, "forkten wait timeout"); //seconds, reason
+	//put_ahnd(ahnd);
+	igt_assert_eq(put_ahnd(ahnd), true);
+	intel_allocator_multiprocess_stop();
 }
 
 igt_main
@@ -234,52 +231,18 @@ igt_main
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	igt_subtest("gem") {
-		gem(fd);
-	}
-	igt_subtest("offsety") {
-		offsety(fd);
-	}
-	igt_subtest("copyrnd-noreloc") {
-		copyrnd(fd, false);
+	igt_subtest("basic") {
+		basic(fd);
 	}
-	igt_subtest("copyrnd-reloc") {
-		copyrnd(fd, true);
+/*
+	igt_subtest("create") {
+		create(fd);
 	}
-	igt_subtest("fork-ten") {
-		fork_ten(fd);
+*/
+	igt_subtest("forkten") {
+		forkten(fd, 10);
 	}
-	igt_subtest("exec") {
 
-	}
-/*	igt_subtest_with_dynamic("basic") {
-		for_each_combination(regions, 1, set) {
-			char *sub_name = memregion_dynamic_subtest_name(regions);
-			struct drm_i915_gem_exec_object2 exec;
-			uint32_t region = igt_collection_get_value(regions, 0);
-
-			batch_size = gem_get_batch_size(fd, MEMORY_TYPE_FROM_REGION(region));
-			memset(&exec, 0, sizeof(exec));
-			exec.handle = batch_create(fd, batch_size, region);
-
-			for_each_ctx_engine(fd, ctx, e) {
-				igt_dynamic_f("%s-%s", e->name, sub_name) {
-					struct drm_i915_gem_execbuffer2 execbuf = {
-						.buffers_ptr = to_user_pointer(&exec),
-						.buffer_count = 1,
-						.flags = e->flags,
-						.rsvd1 = ctx->id,
-					};
-
-					gem_execbuf(fd, &execbuf);
-				}
-			}
-			gem_sync(fd, exec.handle);
-			gem_close(fd, exec.handle);
-			free(sub_name);
-		}
-	}
-*/
 	igt_fixture {
 		close(fd);
 	}
-- 
2.30.2



More information about the Intel-gfx-trybot mailing list