diff mbox

igt/gem_userptr_blits: Fix multi-threaded mm stress tester

Message ID 1406024091-30396-1-git-send-email-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tvrtko Ursulin July 22, 2014, 10:14 a.m. UTC
Two parts to the fix:
  1. Do not use pthread_cancel since not available on Android.
  2. Do not assert in the thread since that does not get propagated
     to the process. Rather pass out any failures so we know test
     did not work as expected.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Tim Gore <tim.gore@intel.com>
---
 tests/gem_userptr_blits.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

Comments

tim.gore@intel.com July 22, 2014, 11:23 a.m. UTC | #1
Builds ok for Android now. I get an assert when I run it on MRD7/Gmin but
This may be expected. I'll put it on my list of tests to look into.

   Tim

> -----Original Message-----
> From: Tvrtko Ursulin [mailto:tvrtko.ursulin@linux.intel.com]
> Sent: Tuesday, July 22, 2014 11:15 AM
> To: Intel-gfx@lists.freedesktop.org
> Cc: Tvrtko Ursulin; Ursulin, Tvrtko; Gore, Tim
> Subject: [PATCH] igt/gem_userptr_blits: Fix multi-threaded mm stress tester
> 
> Two parts to the fix:
>   1. Do not use pthread_cancel since not available on Android.
>   2. Do not assert in the thread since that does not get propagated
>      to the process. Rather pass out any failures so we know test
>      did not work as expected.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Tim Gore <tim.gore@intel.com>
> ---
>  tests/gem_userptr_blits.c | 37 ++++++++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index
> 2a52856..3277096 100644
> --- a/tests/gem_userptr_blits.c
> +++ b/tests/gem_userptr_blits.c
> @@ -1137,21 +1137,32 @@ static void test_unmap_cycles(int fd, int
> expected)
>  		test_unmap(fd, expected);
>  }
> 
> +struct stress_thread_data {
> +	unsigned int stop;
> +	int exit_code;
> +};
> +
>  static void *mm_stress_thread(void *data)  {
> -        void *ptr;
> -        int ret;
> +	struct stress_thread_data *stdata = (struct stress_thread_data
> *)data;
> +	void *ptr;
> +	int ret;
> 
> -	for (;;) {
> +	while (!stdata->stop) {
>  		ptr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
>  				MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> -		igt_assert(ptr != MAP_FAILED);
> +		if (ptr == MAP_FAILED) {
> +			stdata->exit_code = -EFAULT;
> +			break;
> +		}
>  		ret = munmap(ptr, PAGE_SIZE);
> -		igt_assert(ret == 0);
> -		pthread_testcancel();
> -        }
> +		if (ret) {
> +		        stdata->exit_code = errno;
> +		        break;
> +		}
> +	}
> 
> -        return NULL;
> +	return NULL;
>  }
> 
>  static void test_stress_mm(int fd)
> @@ -1161,10 +1172,13 @@ static void test_stress_mm(int fd)
>  	unsigned int loops = 100000;
>  	uint32_t handle;
>  	void *ptr;
> +	struct stress_thread_data stdata;
> +
> +	memset(&stdata, 0, sizeof(stdata));
> 
>  	igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
> 
> -	ret = pthread_create(&t, NULL, mm_stress_thread, NULL);
> +	ret = pthread_create(&t, NULL, mm_stress_thread, &stdata);
>  	igt_assert(ret == 0);
> 
>  	while (loops--) {
> @@ -1176,10 +1190,11 @@ static void test_stress_mm(int fd)
> 
>  	free(ptr);
> 
> -	ret = pthread_cancel(t);
> -	igt_assert(ret == 0);
> +	stdata.stop = 1;
>  	ret = pthread_join(t, NULL);
>  	igt_assert(ret == 0);
> +
> +	igt_assert(stdata.exit_code == 0);
>  }
> 
>  unsigned int total_ram;
> --
> 1.9.3
tim.gore@intel.com July 24, 2014, 8:19 a.m. UTC | #2
> -----Original Message-----
> From: Tvrtko Ursulin [mailto:tvrtko.ursulin@linux.intel.com]
> Sent: Tuesday, July 22, 2014 11:15 AM
> To: Intel-gfx@lists.freedesktop.org
> Cc: Tvrtko Ursulin; Ursulin, Tvrtko; Gore, Tim
> Subject: [PATCH] igt/gem_userptr_blits: Fix multi-threaded mm stress tester
> 
> Two parts to the fix:
>   1. Do not use pthread_cancel since not available on Android.
>   2. Do not assert in the thread since that does not get propagated
>      to the process. Rather pass out any failures so we know test
>      did not work as expected.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Tim Gore <tim.gore@intel.com>
Reviewed-by: Tim Gore <tim.gore@intel.com>

Builds for Android now, and stress-mm test passes on linux. Fails for Android but this is a different issue.

> ---
>  tests/gem_userptr_blits.c | 37 ++++++++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index
> 2a52856..3277096 100644
> --- a/tests/gem_userptr_blits.c
> +++ b/tests/gem_userptr_blits.c
> @@ -1137,21 +1137,32 @@ static void test_unmap_cycles(int fd, int
> expected)
>  		test_unmap(fd, expected);
>  }
> 
> +struct stress_thread_data {
> +	unsigned int stop;
> +	int exit_code;
> +};
> +
>  static void *mm_stress_thread(void *data)  {
> -        void *ptr;
> -        int ret;
> +	struct stress_thread_data *stdata = (struct stress_thread_data
> *)data;
> +	void *ptr;
> +	int ret;
> 
> -	for (;;) {
> +	while (!stdata->stop) {
>  		ptr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
>  				MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> -		igt_assert(ptr != MAP_FAILED);
> +		if (ptr == MAP_FAILED) {
> +			stdata->exit_code = -EFAULT;
> +			break;
> +		}
>  		ret = munmap(ptr, PAGE_SIZE);
> -		igt_assert(ret == 0);
> -		pthread_testcancel();
> -        }
> +		if (ret) {
> +		        stdata->exit_code = errno;
> +		        break;
> +		}
> +	}
> 
> -        return NULL;
> +	return NULL;
>  }
> 
>  static void test_stress_mm(int fd)
> @@ -1161,10 +1172,13 @@ static void test_stress_mm(int fd)
>  	unsigned int loops = 100000;
>  	uint32_t handle;
>  	void *ptr;
> +	struct stress_thread_data stdata;
> +
> +	memset(&stdata, 0, sizeof(stdata));
> 
>  	igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
> 
> -	ret = pthread_create(&t, NULL, mm_stress_thread, NULL);
> +	ret = pthread_create(&t, NULL, mm_stress_thread, &stdata);
>  	igt_assert(ret == 0);
> 
>  	while (loops--) {
> @@ -1176,10 +1190,11 @@ static void test_stress_mm(int fd)
> 
>  	free(ptr);
> 
> -	ret = pthread_cancel(t);
> -	igt_assert(ret == 0);
> +	stdata.stop = 1;
>  	ret = pthread_join(t, NULL);
>  	igt_assert(ret == 0);
> +
> +	igt_assert(stdata.exit_code == 0);
>  }
> 
>  unsigned int total_ram;
> --
> 1.9.3
Chris Wilson July 24, 2014, 8:32 a.m. UTC | #3
On Thu, Jul 24, 2014 at 08:19:19AM +0000, Gore, Tim wrote:
> 
> > -----Original Message-----
> > From: Tvrtko Ursulin [mailto:tvrtko.ursulin@linux.intel.com]
> > Sent: Tuesday, July 22, 2014 11:15 AM
> > To: Intel-gfx@lists.freedesktop.org
> > Cc: Tvrtko Ursulin; Ursulin, Tvrtko; Gore, Tim
> > Subject: [PATCH] igt/gem_userptr_blits: Fix multi-threaded mm stress tester
> > 
> > Two parts to the fix:
> >   1. Do not use pthread_cancel since not available on Android.
> >   2. Do not assert in the thread since that does not get propagated
> >      to the process. Rather pass out any failures so we know test
> >      did not work as expected.
> > 
> > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > Cc: Tim Gore <tim.gore@intel.com>
> Reviewed-by: Tim Gore <tim.gore@intel.com>
Pushed.
-Chris
diff mbox

Patch

diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
index 2a52856..3277096 100644
--- a/tests/gem_userptr_blits.c
+++ b/tests/gem_userptr_blits.c
@@ -1137,21 +1137,32 @@  static void test_unmap_cycles(int fd, int expected)
 		test_unmap(fd, expected);
 }
 
+struct stress_thread_data {
+	unsigned int stop;
+	int exit_code;
+};
+
 static void *mm_stress_thread(void *data)
 {
-        void *ptr;
-        int ret;
+	struct stress_thread_data *stdata = (struct stress_thread_data *)data;
+	void *ptr;
+	int ret;
 
-	for (;;) {
+	while (!stdata->stop) {
 		ptr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
 				MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-		igt_assert(ptr != MAP_FAILED);
+		if (ptr == MAP_FAILED) {
+			stdata->exit_code = -EFAULT;
+			break;
+		}
 		ret = munmap(ptr, PAGE_SIZE);
-		igt_assert(ret == 0);
-		pthread_testcancel();
-        }
+		if (ret) {
+		        stdata->exit_code = errno;
+		        break;
+		}
+	}
 
-        return NULL;
+	return NULL;
 }
 
 static void test_stress_mm(int fd)
@@ -1161,10 +1172,13 @@  static void test_stress_mm(int fd)
 	unsigned int loops = 100000;
 	uint32_t handle;
 	void *ptr;
+	struct stress_thread_data stdata;
+
+	memset(&stdata, 0, sizeof(stdata));
 
 	igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
 
-	ret = pthread_create(&t, NULL, mm_stress_thread, NULL);
+	ret = pthread_create(&t, NULL, mm_stress_thread, &stdata);
 	igt_assert(ret == 0);
 
 	while (loops--) {
@@ -1176,10 +1190,11 @@  static void test_stress_mm(int fd)
 
 	free(ptr);
 
-	ret = pthread_cancel(t);
-	igt_assert(ret == 0);
+	stdata.stop = 1;
 	ret = pthread_join(t, NULL);
 	igt_assert(ret == 0);
+
+	igt_assert(stdata.exit_code == 0);
 }
 
 unsigned int total_ram;