[igt-dev] [PATCH i-g-t v30 33/33] tests/api_intel_bb: verify cache realloc and fix memory leaks

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Wed Aug 19 12:33:06 UTC 2020


Introduce lot-of-objects test which checks does bb objects array
is properly reallocated and cache contains valid pointers.

Also fix some minor memory leaks pointed out by valgrind.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/i915/api_intel_bb.c | 64 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 57 insertions(+), 7 deletions(-)

diff --git a/tests/i915/api_intel_bb.c b/tests/i915/api_intel_bb.c
index 376021de..390f3a18 100644
--- a/tests/i915/api_intel_bb.c
+++ b/tests/i915/api_intel_bb.c
@@ -168,6 +168,39 @@ static void simple_bb(struct buf_ops *bops, bool use_context)
 		gem_context_destroy(i915, ctx);
 }
 
+/*
+ * Make sure we lead to realloc in the intel_bb.
+ */
+#define NUM_BUFS 4096
+static void lot_of_buffers(struct buf_ops *bops)
+{
+	int i915 = buf_ops_get_fd(bops);
+	struct intel_bb *ibb;
+	struct intel_buf *buf[NUM_BUFS];
+	int i;
+
+	ibb = intel_bb_create(i915, PAGE_SIZE);
+	if (debug_bb)
+		intel_bb_set_debug(ibb, true);
+
+	intel_bb_out(ibb, MI_BATCH_BUFFER_END);
+	intel_bb_ptr_align(ibb, 8);
+
+	for (i = 0; i < NUM_BUFS; i++) {
+		buf[i] = intel_buf_create(bops, 4096, 1, 8, 0, I915_TILING_NONE,
+					  I915_COMPRESSION_NONE);
+		intel_bb_add_intel_buf(ibb, buf[i], false);
+	}
+
+	intel_bb_exec(ibb, intel_bb_offset(ibb),
+		      I915_EXEC_DEFAULT | I915_EXEC_NO_RELOC, true);
+
+	intel_bb_destroy(ibb);
+
+	for (i = 0; i < NUM_BUFS; i++)
+		intel_buf_destroy(buf[i]);
+}
+
 /*
  * Make sure intel-bb space allocator currently doesn't enter 47-48 bit
  * gtt sizes.
@@ -298,6 +331,7 @@ static void __emit_blit(struct intel_bb *ibb,
 {
 	uint32_t mask;
 	bool has_64b_reloc;
+	uint64_t address;
 
 	has_64b_reloc = ibb->gen >= 8;
 
@@ -321,15 +355,19 @@ static void __emit_blit(struct intel_bb *ibb,
 	intel_bb_out(ibb, 3 << 24 | 0xcc << 16 | dst->surface[0].stride);
 	intel_bb_out(ibb, 0);
 	intel_bb_out(ibb, intel_buf_height(dst) << 16 | intel_buf_width(dst));
+
+	address = intel_bb_get_object_offset(ibb, dst->handle);
 	intel_bb_emit_reloc_fenced(ibb, dst->handle,
 				   I915_GEM_DOMAIN_RENDER,
 				   I915_GEM_DOMAIN_RENDER,
-				   0, dst->addr.offset);
+				   0, address);
 	intel_bb_out(ibb, 0);
 	intel_bb_out(ibb, src->surface[0].stride);
+
+	address = intel_bb_get_object_offset(ibb, src->handle);
 	intel_bb_emit_reloc_fenced(ibb, src->handle,
 				   I915_GEM_DOMAIN_RENDER, 0,
-				   0, src->addr.offset);
+				   0, address);
 
 	if ((src->tiling | dst->tiling) >= I915_TILING_Y) {
 		igt_assert(ibb->gen >= 6);
@@ -401,6 +439,7 @@ static void blit(struct buf_ops *bops,
 	poff_bb = intel_bb_get_object_offset(ibb, ibb->handle);
 	poff_src = intel_bb_get_object_offset(ibb, src->handle);
 	poff_dst = intel_bb_get_object_offset(ibb, dst->handle);
+
 	intel_bb_reset(ibb, purge_cache);
 
 	fill_buf(src, COLOR_77);
@@ -444,8 +483,8 @@ static void blit(struct buf_ops *bops,
 	igt_assert(poff_src == poff2_src);
 	igt_assert(poff_dst == poff2_dst);
 
-	intel_buf_close(bops, src);
-	intel_buf_close(bops, dst);
+	intel_buf_destroy(src);
+	intel_buf_destroy(dst);
 	intel_bb_destroy(ibb);
 }
 
@@ -780,6 +819,10 @@ static void offset_control(struct buf_ops *bops)
 		print_buf(dst2, "dst2");
 	}
 
+	intel_buf_destroy(src);
+	intel_buf_destroy(dst1);
+	intel_buf_destroy(dst2);
+	intel_buf_destroy(dst3);
 	intel_bb_destroy(ibb);
 }
 
@@ -898,8 +941,11 @@ static int render(struct buf_ops *bops, uint32_t tiling, bool do_reloc,
 
 static uint32_t count_compressed(int gen, struct intel_buf *buf)
 {
+	int i915 = buf_ops_get_fd(buf->bops);
 	int ccs_size = intel_buf_ccs_width(gen, buf) * intel_buf_ccs_height(gen, buf);
-	uint8_t *ptr = intel_buf_device_map(buf, false);
+	uint8_t *ptr = gem_mmap__device_coherent(i915, buf->handle, 0,
+						 intel_buf_bo_size(buf),
+						 PROT_READ);
 	uint32_t compressed = 0;
 	int i;
 
@@ -907,7 +953,7 @@ static uint32_t count_compressed(int gen, struct intel_buf *buf)
 		if (ptr[buf->ccs[0].offset + i])
 			compressed++;
 
-	intel_buf_unmap(buf);
+	munmap(buf, intel_buf_bo_size(buf));
 
 	return compressed;
 }
@@ -957,11 +1003,12 @@ static void render_ccs(struct buf_ops *bops)
 		    0, 0);
 
 	intel_bb_sync(ibb);
-	intel_bb_destroy(ibb);
 
 	fails = compare_bufs(&src, &final, true);
 	compressed = count_compressed(ibb->gen, &dst);
 
+	intel_bb_destroy(ibb);
+
 	igt_debug("fails: %u, compressed: %u\n", fails, compressed);
 
 	if (write_png) {
@@ -1034,6 +1081,9 @@ igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 	igt_subtest("simple-bb-ctx")
 		simple_bb(bops, true);
 
+	igt_subtest("lot-of-buffers")
+		lot_of_buffers(bops);
+
 	igt_subtest("check-canonical")
 		check_canonical(bops);
 
-- 
2.26.0



More information about the igt-dev mailing list