tests/gem_fence_thrash.c: Reduce memory usage
PATCH 1/1 tests/gem_fence_thrash.c: Reduce memory usage
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.
--- tests/gem_fence_thrash.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
tests/gem_fence_thrash.c +22 -11
@@ -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 );
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 38 lines · Derek Morton
On android platforms with 1Gb RAM
gem_fence_thrashwas failing with an out of memory error.
This patch causesgem_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 <[email protected]>--- tests/gem_fence_thrash.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)tests/gem_fence_thrash.c +3
-4@@ -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 );
tests/gem_fence_thrash.c struct test { · line 81
Quoted 10 lines
tests/gem_fence_thrash.c +3
-3-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);
Just call gem_close(fd, handle); the mmap will hold the reference for the test.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 56 lines
-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Tuesday, June 23, 2015 4:08 PM
To: Morton, Derek J
Cc: [email protected]; Wood, Thomas
Subject: Re: [Intel-gfx] [PATCH i-g-t]tests/gem_fence_thrash.c: Reduce memory usageQuoted 46 lines · Derek Morton
On android platforms with 1Gb RAM
gem_fence_thrashwas failing with an out of memory error.
This patch causesgem_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 <[email protected]>--- tests/gem_fence_thrash.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)tests/gem_fence_thrash.c index renamed from tests/gem_fence_thrash.c +0
-06447e13..bfb2e6d 100644
tests/gem_fence_thrash.c +6
-6@@ -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);
Quoted 5 lines
tests/gem_fence_thrash.c struct test { · line 81
Quoted 3 lines
tests/gem_fence_thrash.c +1
-1/* XXX: mmap_gtt pulls the bo into the GTT read domain. */ -gem_sync (fd, handle); +gem_sync (fd, *handle);Just call
gem_close(fd, handle); the mmap will hold the reference for the test.
Thanks for the suggestion. I did not realise that was the case. It simplifies the patch a lot. Will submit a new version.
//Derek
Quoted 5 lines
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx