[Mesa-dev] [PATCH] radeon-llvm: Start multithreaded before using llvm.

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


Pushed.

Thanks for investigating this and coming up with a clean solution.

-Tom

On Sat, Aug 18, 2012 at 11:43:51AM +0200, Mathias Fröhlich wrote:
> This is required to make some of llvm's api calls
> thread save. In particular the PassRegistry, which is
> implicitly accessed while compiling shader programs.
> The PassRegistry uses a mutex that is only active if
> the llvm_is_multithreaded() returns true.
> Calling llvm_start_multithreading() makes this happen
> and by calling this function we try to make sure that
> we can savely compile shaders in paralell.
> Since there is also a call llvm_stop_multithreading()
> in the llvm api, we cannot guarantee that this does
> not get switched off while we are relying on this being
> set, but for the easier use cases this fixes a race with
> the radeon llvm compiler we have as of today.
> 
> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>
> ---
>  src/gallium/drivers/radeon/radeon_llvm_emit.cpp | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.cpp 
> b/src/gallium/drivers/radeon/radeon_llvm_emit.cpp
> index 89130b3..eef55a8 100644
> --- a/src/gallium/drivers/radeon/radeon_llvm_emit.cpp
> +++ b/src/gallium/drivers/radeon/radeon_llvm_emit.cpp
> @@ -35,6 +35,7 @@
>  #include <llvm/Support/SourceMgr.h>
>  #include <llvm/Support/TargetRegistry.h>
>  #include <llvm/Support/TargetSelect.h>
> +#include <llvm/Support/Threading.h>
>  #include <llvm/Target/TargetData.h>
>  #include <llvm/Target/TargetMachine.h>
>  
> @@ -57,6 +58,20 @@ void LLVMInitializeAMDGPUTargetInfo(void);
>  }
>  #endif
>  
> +namespace {
> +
> +class LLVMEnsureMultithreaded {
> +public:
> +   LLVMEnsureMultithreaded()
> +   {
> +      llvm_start_multithreaded();
> +   }
> +};
> +
> +static LLVMEnsureMultithreaded lLVMEnsureMultithreaded;
> +
> +}
> +
>  /**
>   * Compile an LLVM module to machine code.
>   *
> -- 
> 1.7.11.4
> 
> 



More information about the mesa-dev mailing list