[Mesa-dev] threading analysis tools (was: [PATCH] os: add pipe_mutex_assert_locked())

Eero Tamminen eero.t.tamminen at intel.com
Fri Jul 22 08:30:10 UTC 2016


Hi,

On 21.07.2016 20:53, Rob Clark wrote:
> Would be nice if we could also have lockdep, like in the linux kernel.
> But this is better than nothing.

I haven't tried it, but there is a user-space lockdep:
	http://lwn.net/Articles/536363/

Clang has some support for static lock analysis:
http://clang.llvm.org/docs/ThreadSafetyAnalysis.html

And Valgrind has couple of tools for run-time analysis of threading 
issues (which differ in how much false positives they can give & 
potentially miss real issues):
http://valgrind.org/docs/manual/hg-manual.html
http://valgrind.org/docs/manual/drd-manual.html

Some notes about threading behavior under Valgrind:
http://valgrind.org/docs/manual/manual-core.html#manual-core.pthreads

For faster lock contention checking than Valgrind, you could try this (I 
haven't used it in recent years so I don't know how well it nowadays works):
	http://0pointer.de/blog/projects/mutrace.html


	- Eero

> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
>  src/gallium/auxiliary/os/os_thread.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
> index be8adcc..ec8adbc 100644
> --- a/src/gallium/auxiliary/os/os_thread.h
> +++ b/src/gallium/auxiliary/os/os_thread.h
> @@ -116,6 +116,22 @@ typedef mtx_t pipe_mutex;
>  #define pipe_mutex_unlock(mutex) \
>     (void) mtx_unlock(&(mutex))
>
> +#define pipe_mutex_assert_locked(mutex) \
> +   __pipe_mutex_assert_locked(&(mutex))
> +
> +static inline void
> +__pipe_mutex_assert_locked(pipe_mutex *mutex)
> +{
> +#ifdef DEBUG
> +   /* NOTE: this would not work for recursive mutexes, but
> +    * pipe_mutex doesn't support those
> +    */
> +   int ret = mtx_trylock(mutex);
> +   assert(ret == thrd_busy);
> +   if (ret == thrd_success)
> +      mtx_unlock(mutex);
> +#endif
> +}
>
>  /* pipe_condvar
>   */
>



More information about the mesa-dev mailing list