[Intel-gfx] [PATCH igt] igt/gem_shrink: Exercise allocations in the middle of execbuf under oom-pressure

Chris Wilson chris at chris-wilson.co.uk
Tue Dec 12 21:43:05 UTC 2017


Having discovered that we would encounter an indefinite wait in the
shrinker within execbuf/request construction, try to exercise that path
by emitting lots of execbuf with fences (which require allocation inside
request construction) whilst under severe mempressure.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
---
 tests/gem_shrink.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 06f7a3012..d39fe3cfe 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -36,6 +36,8 @@
 #define MADV_FREE 8
 #endif
 
+static unsigned int engines[16], nengine;
+
 static void get_pages(int fd, uint64_t alloc)
 {
 	uint32_t handle = gem_create(fd, alloc);
@@ -150,6 +152,37 @@ static void execbufN(int fd, uint64_t alloc)
 	munmap(obj, obj_size);
 }
 
+static void execbufX(int fd, uint64_t alloc)
+{
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	struct drm_i915_gem_exec_object2 *obj;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	int count = alloc >> 20;
+	uint64_t obj_size;
+
+	obj = __gem_calloc(fd, alloc + 1, sizeof(*obj), &obj_size);
+	memset(&execbuf, 0, sizeof(execbuf));
+
+	obj[count].handle = gem_create(fd, 4096);
+	gem_write(fd, obj[count].handle, 0, &bbe, sizeof(bbe));
+
+	for (int i = 1; i <= count; i++) {
+		int j = count - i;
+
+		obj[j].handle = gem_create(fd, 1 << 20);
+		obj[j].flags = EXEC_OBJECT_WRITE;
+
+		execbuf.buffers_ptr = to_user_pointer(&obj[j]);
+		execbuf.buffer_count = i + 1;
+		execbuf.flags = engines[j % nengine];
+		gem_execbuf(fd, &execbuf);
+	}
+
+	for (int i = 0; i <= count; i++)
+		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
+	munmap(obj, obj_size);
+}
+
 static void hang(int fd, uint64_t alloc)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -344,6 +377,7 @@ igt_main
 		{ "mmap-cpu", mmap_cpu },
 		{ "execbuf1", execbuf1 },
 		{ "execbufN", execbufN },
+		{ "execbufX", execbufX },
 		{ "hang", hang },
 		{ NULL },
 	};
@@ -364,6 +398,8 @@ igt_main
 
 	igt_fixture {
 		uint64_t mem_size = intel_get_total_ram_mb();
+		unsigned int engine;
+		int fd;
 
 		/* Spawn enough processes to use all memory, but each only
 		 * uses half the available mappable aperture ~128MiB.
@@ -379,6 +415,16 @@ igt_main
 
 		intel_require_memory(num_processes, alloc_size,
 				     CHECK_SWAP | CHECK_RAM);
+
+		fd = drm_open_driver(DRIVER_INTEL);
+		igt_require_gem(fd);
+
+		nengine = 0;
+		for_each_engine(fd, engine)
+			engines[nengine++] = engine;
+		igt_require(nengine);
+
+		close(fd);
 	}
 
 	igt_subtest("reclaim")
-- 
2.15.1



More information about the Intel-gfx mailing list