[Intel-gfx] [PATCH i-g-t] tests/gem_fence_thrash.c: Reduce memory usage

Derek Morton derek.j.morton at intel.com
Tue Jun 23 08:01:53 PDT 2015


On android platforms with 1Gb RAM gem_fence_thrash was failing
with an out of memory error.
This patch causes gem_close() to be called when a thread is
finished with its handles rather than relying on the cleanup
when the fd is closed. This greatly improves the memory footprint
of the test allowing it to run on 1Mb systems.

Also fixed a leak of the 'threads' variable.

Signed-off-by: Derek Morton <derek.j.morton at intel.com>
---
 tests/gem_fence_thrash.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/tests/gem_fence_thrash.c b/tests/gem_fence_thrash.c
index 6447e13..bfb2e6d 100644
--- a/tests/gem_fence_thrash.c
+++ b/tests/gem_fence_thrash.c
@@ -60,26 +60,25 @@ struct test {
 };
 
 static void *
-bo_create (int fd, int tiling)
+bo_create (int fd, int tiling, uint32_t *handle)
 {
 	void *ptr;
-	int handle;
 
-	handle = gem_create(fd, OBJECT_SIZE);
+	*handle = gem_create(fd, OBJECT_SIZE);
 
 	/* dirty cpu caches a bit ... */
-	ptr = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
+	ptr = gem_mmap__cpu(fd, *handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
 	igt_assert(ptr);
 	memset(ptr, 0, OBJECT_SIZE);
 	munmap(ptr, OBJECT_SIZE);
 
-	gem_set_tiling(fd, handle, tiling, 1024);
+	gem_set_tiling(fd, *handle, tiling, 1024);
 
-	ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
+	ptr = gem_mmap(fd, *handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
 	igt_assert(ptr);
 
 	/* XXX: mmap_gtt pulls the bo into the GTT read domain. */
-	gem_sync(fd, handle);
+	gem_sync(fd, *handle);
 
 	return ptr;
 }
@@ -91,15 +90,19 @@ bo_copy (void *_arg)
 	int fd = t->fd;
 	int n;
 	char *a, *b;
+	uint32_t ha, hb;
 
-	a = bo_create (fd, t->tiling);
-	b = bo_create (fd, t->tiling);
+	a = bo_create (fd, t->tiling, &ha);
+	b = bo_create (fd, t->tiling, &hb);
 
 	for (n = 0; n < 1000; n++) {
 		memcpy (a, b, OBJECT_SIZE);
 		sched_yield ();
 	}
 
+	gem_close(fd, ha);
+	gem_close(fd, hb);
+
 	return NULL;
 }
 
@@ -112,15 +115,18 @@ _bo_write_verify(struct test *t)
 	uint32_t v;
 	unsigned int dwords = OBJECT_SIZE >> 2;
 	const char *tile_str[] = { "none", "x", "y" };
+	uint32_t *h;
 
 	igt_assert(t->tiling >= 0 && t->tiling <= I915_TILING_Y);
 	igt_assert_lt(0, t->num_surfaces);
 
 	s = calloc(sizeof(*s), t->num_surfaces);
 	igt_assert(s);
+	h = calloc(sizeof(*h), t->num_surfaces);
+	igt_assert(h);
 
 	for (k = 0; k < t->num_surfaces; k++)
-		s[k] = bo_create(fd, t->tiling);
+		s[k] = bo_create(fd, t->tiling, &(h[k]));
 
 	for (k = 0; k < t->num_surfaces; k++) {
 		volatile uint32_t *a = s[k];
@@ -141,10 +147,13 @@ _bo_write_verify(struct test *t)
 		}
 	}
 
-	for (k = 0; k < t->num_surfaces; k++)
+	for (k = 0; k < t->num_surfaces; k++) {
 		munmap(s[k], OBJECT_SIZE);
+		gem_close(fd, h[k]);
+	}
 
 	free(s);
+	free(h);
 }
 
 static void *
@@ -188,6 +197,8 @@ static int run_test(int threads_per_fence, void *f, int tiling,
 
 		for (n = 0; n < num_threads; n++)
 			pthread_join (threads[n], NULL);
+
+		free(threads);
 	} else {
 		void *(*func)(void *) = f;
 		igt_assert(func(&t) == (void *)0);
-- 
1.9.1



More information about the Intel-gfx mailing list