[Piglit] Test to exercise a race with r600-llvm

Tom Stellard thomas.stellard at amd.com
Mon Aug 20 09:26:19 PDT 2012


On Wed, Aug 15, 2012 at 07:51:56AM +0200, Mathias Fröhlich wrote:
> 
> Hi,
> 
> This new attached test points to a problem that I observe with initializatiion 
> of the llvm backend in todays r600 driver.
> The new test concurrently, in two threads, creates a new context compiles a 
> simple shader and destroys the context again.
> The problem it points out is a race condition we have somewhere in 
> initialization of the llvm backend.
> But since this is a race condition I see the test only with some probability 
> failing, even if the probability is for my test machine > 90%.
> 
> please review.
> 
> Thanks
> Mathias

> From a3e67f2b7822225da87d97434110fdff2a012c7c Mon Sep 17 00:00:00 2001
> Message-Id: <a3e67f2b7822225da87d97434110fdff2a012c7c.1345009097.git.Mathias.Froehlich at gmx.net>
> From: Mathias Froehlich <Mathias.Froehlich at web.de>
> Date: Tue, 14 Aug 2012 07:38:57 +0200
> Subject: [PATCH] Add test for concurrent shader compiler use.
> 
> Add a test that creates two contexts and concurrently
> compiles shader programs to test race conditions of
> the shader compiler.
> 
> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>

One minor thing, I think you should add the new test to the all.tests
file.

Otherwise:

Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

> ---
>  tests/glx/CMakeLists.gl.txt                |   2 +
>  tests/glx/glx-multithread-shader-compile.c | 117 +++++++++++++++++++++++++++++
>  2 files changed, 119 insertions(+)
>  create mode 100644 tests/glx/glx-multithread-shader-compile.c
> 
> diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
> index 874991b..7bd62e3 100644
> --- a/tests/glx/CMakeLists.gl.txt
> +++ b/tests/glx/CMakeLists.gl.txt
> @@ -41,6 +41,8 @@ IF(BUILD_GLX_TESTS)
>  	target_link_libraries(glx-multithread-makecurrent-3 pthread)
>  	piglit_add_executable (glx-multithread-makecurrent-4 glx-multithread-makecurrent-4.c)
>  	target_link_libraries(glx-multithread-makecurrent-4 pthread)
> +	piglit_add_executable (glx-multithread-shader-compile glx-multithread-shader-compile.c)
> +	target_link_libraries(glx-multithread-shader-compile pthread)
>  	piglit_add_executable (glx-make-current glx-make-current.c)
>  	piglit_add_executable (glx-swap-event glx-swap-event.c)
>  	piglit_add_executable (glx-make-glxdrawable-current glx-make-glxdrawable-current.c)
> diff --git a/tests/glx/glx-multithread-shader-compile.c b/tests/glx/glx-multithread-shader-compile.c
> new file mode 100644
> index 0000000..46e7808
> --- /dev/null
> +++ b/tests/glx/glx-multithread-shader-compile.c
> @@ -0,0 +1,117 @@
> +/*
> + * Copyright (c) 2012 Mathias Fröhlich
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +/**
> + * @file glx-multithread-shader-compile.c
> + * @author Mathias Fröhlich
> + *
> + * Create two GLX contexts and concurrently compile shaders.
> + * Exercises a race conditon with the r600 llvm compiler.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +#include "piglit-glx-util.h"
> +#include "pthread.h"
> +
> +static const char *vert_shader_text =
> +   "void main() \n"
> +   "{ \n"
> +   "   gl_Position = ftransform(); \n"
> +   "   gl_FrontColor = gl_Color; \n"
> +   "} \n";
> +
> +static const char *frag_shader_text =
> +   "void main() \n"
> +   "{ \n"
> +   "   gl_FragColor = vec4(1.0) - gl_Color; \n"
> +   "} \n";
> +
> +static pthread_mutex_t mutex;
> +
> +static void *
> +thread_func(void *arg)
> +{
> +	Display *dpy;
> +	XVisualInfo *visinfo;
> +	Window win;
> +	unsigned i;
> +
> +	dpy = piglit_get_glx_display();
> +	visinfo = piglit_get_glx_visual(dpy);
> +	win = piglit_get_glx_window(dpy, visinfo);
> +
> +	for (i = 0; i < 100; ++i) {
> +		GLXContext ctx;
> +		GLuint vert_shader, frag_shader;
> +		GLuint program;
> +
> +		ctx = piglit_get_glx_context(dpy, visinfo);
> +		glXMakeCurrent(dpy, win, ctx);
> +
> +		/* Ok, not nice but should be safe due to all threads working
> +		   on the same type of context. */
> +		pthread_mutex_lock(&mutex);
> +		piglit_dispatch_default_init();
> +		pthread_mutex_unlock(&mutex);
> +
> +		vert_shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vert_shader_text);
> +		piglit_check_gl_error(GL_NO_ERROR);
> +
> +		frag_shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag_shader_text);
> +		piglit_check_gl_error(GL_NO_ERROR);
> +
> +		program = piglit_link_simple_program(vert_shader, frag_shader);
> +		piglit_check_gl_error(GL_NO_ERROR);
> +
> +		glUseProgram(program);
> +		piglit_check_gl_error(GL_NO_ERROR);
> +
> +		glXDestroyContext(dpy, ctx);
> +	}
> +
> +	return NULL;
> +}
> +
> +int
> +main(int argc, char **argv)
> +{
> +	int ret;
> +	pthread_t thread1, thread2;
> +
> +	pthread_mutex_init(&mutex, NULL);
> +
> +	/* Now, spawn some threads that compile simple shaders.
> +	 */
> +	pthread_create(&thread1, NULL, thread_func, NULL);
> +	pthread_create(&thread2, NULL, thread_func, NULL);
> +
> +	ret = pthread_join(thread1, NULL);
> +	assert(ret == 0);
> +	ret = pthread_join(thread2, NULL);
> +	assert(ret == 0);
> +
> +	pthread_mutex_destroy(&mutex);
> +
> +	return 0;
> +}
> +
> -- 
> 1.7.11.2
> 

> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit




More information about the Piglit mailing list