Re: [Mesa-dev] [PATCH v2] disk cache: Link with -latomic if necessary

2018-03-02 Thread Thierry Reding
On Thu, Mar 01, 2018 at 08:53:59AM -0800, Dylan Baker wrote:
> Quoting Thierry Reding (2018-03-01 05:28:07)
> > From: Thierry Reding 
> > 
> > The disk cache implementation uses 64-bit atomic operations. For some
> > architectures, such as 32-bit ARM, GCC will not be able to translate
> > these operations into atomic, lock-free instructions and will instead
> > rely on the external atomics library to provide these operations.
> > 
> > Check at configuration time whether or not linking against libatomic
> > is necessary and if so, create a dependency that can be used while
> > linking the mesautil library.
> > 
> > This is the meson equivalent of 2ef7f23820a6 ("configure: check if
> > -latomic is needed for __atomic_*").
> > 
> > For some background information on this, see:
> > 
> > https://gcc.gnu.org/wiki/Atomic/GCCMM
> > 
> > Changes in v2:
> > - clarify meaning of lock-free in commit message
> > - fix build if -latomic is not necessary
> > 
> > Acked-by: Matt Turner 
> > Signed-off-by: Thierry Reding 
> > ---
> >  meson.build  | 17 +
> >  src/util/meson.build |  2 +-
> >  2 files changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/meson.build b/meson.build
> > index e9928a379313..bb6a835084fe 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -790,9 +790,26 @@ else
> >  endif
> >  
> >  # Check for GCC style atomics
> > +dep_atomic = declare_dependency()
> > +
> >  if cc.compiles('int main() { int n; return __atomic_load_n(, 
> > __ATOMIC_ACQUIRE); }',
> > name : 'GCC atomic builtins')
> >pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
> > +
> > +  # Not all atomic calls can be turned into lock-free instructions, in 
> > which
> > +  # GCC will make calls into the libatomic library. Check whether we need 
> > to
> > +  # link with -latomic.
> > +  #
> > +  # This can happen for 64-bit atomic operations on 32-bit architectures 
> > such
> > +  # as ARM.
> > +  if not cc.links('''#include 
> > + int main() {
> > +   uint64_t n;
> > +   return (int)__atomic_load_n(, __ATOMIC_ACQUIRE);
> > + }''',
> > +  name : 'GCC atomic builtins required -latomic')
> > +dep_atomic = cc.find_library('atomic')
> > +  endif
> >  endif
> >  if not cc.links('''#include 
> > uint64_t v;
> > diff --git a/src/util/meson.build b/src/util/meson.build
> > index b23dba3a9851..eece1cefef6a 100644
> > --- a/src/util/meson.build
> > +++ b/src/util/meson.build
> > @@ -102,7 +102,7 @@ libmesa_util = static_library(
> >'mesa_util',
> >[files_mesa_util, format_srgb],
> >include_directories : inc_common,
> > -  dependencies : [dep_zlib, dep_clock, dep_thread],
> > +  dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic],
> >c_args : [c_msvc_compat_args, c_vis_args],
> >build_by_default : false
> >  )
> > -- 
> > 2.16.2
> > 
> 
> Reviewed-by: Dylan Baker 

Thanks. Pushed to master.

Thierry


signature.asc
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2] disk cache: Link with -latomic if necessary

2018-03-01 Thread Dylan Baker
Quoting Thierry Reding (2018-03-01 05:28:07)
> From: Thierry Reding 
> 
> The disk cache implementation uses 64-bit atomic operations. For some
> architectures, such as 32-bit ARM, GCC will not be able to translate
> these operations into atomic, lock-free instructions and will instead
> rely on the external atomics library to provide these operations.
> 
> Check at configuration time whether or not linking against libatomic
> is necessary and if so, create a dependency that can be used while
> linking the mesautil library.
> 
> This is the meson equivalent of 2ef7f23820a6 ("configure: check if
> -latomic is needed for __atomic_*").
> 
> For some background information on this, see:
> 
> https://gcc.gnu.org/wiki/Atomic/GCCMM
> 
> Changes in v2:
> - clarify meaning of lock-free in commit message
> - fix build if -latomic is not necessary
> 
> Acked-by: Matt Turner 
> Signed-off-by: Thierry Reding 
> ---
>  meson.build  | 17 +
>  src/util/meson.build |  2 +-
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index e9928a379313..bb6a835084fe 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -790,9 +790,26 @@ else
>  endif
>  
>  # Check for GCC style atomics
> +dep_atomic = declare_dependency()
> +
>  if cc.compiles('int main() { int n; return __atomic_load_n(, 
> __ATOMIC_ACQUIRE); }',
> name : 'GCC atomic builtins')
>pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
> +
> +  # Not all atomic calls can be turned into lock-free instructions, in which
> +  # GCC will make calls into the libatomic library. Check whether we need to
> +  # link with -latomic.
> +  #
> +  # This can happen for 64-bit atomic operations on 32-bit architectures such
> +  # as ARM.
> +  if not cc.links('''#include 
> + int main() {
> +   uint64_t n;
> +   return (int)__atomic_load_n(, __ATOMIC_ACQUIRE);
> + }''',
> +  name : 'GCC atomic builtins required -latomic')
> +dep_atomic = cc.find_library('atomic')
> +  endif
>  endif
>  if not cc.links('''#include 
> uint64_t v;
> diff --git a/src/util/meson.build b/src/util/meson.build
> index b23dba3a9851..eece1cefef6a 100644
> --- a/src/util/meson.build
> +++ b/src/util/meson.build
> @@ -102,7 +102,7 @@ libmesa_util = static_library(
>'mesa_util',
>[files_mesa_util, format_srgb],
>include_directories : inc_common,
> -  dependencies : [dep_zlib, dep_clock, dep_thread],
> +  dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic],
>c_args : [c_msvc_compat_args, c_vis_args],
>build_by_default : false
>  )
> -- 
> 2.16.2
> 

Reviewed-by: Dylan Baker 


signature.asc
Description: signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2] disk cache: Link with -latomic if necessary

2018-03-01 Thread Thierry Reding
From: Thierry Reding 

The disk cache implementation uses 64-bit atomic operations. For some
architectures, such as 32-bit ARM, GCC will not be able to translate
these operations into atomic, lock-free instructions and will instead
rely on the external atomics library to provide these operations.

Check at configuration time whether or not linking against libatomic
is necessary and if so, create a dependency that can be used while
linking the mesautil library.

This is the meson equivalent of 2ef7f23820a6 ("configure: check if
-latomic is needed for __atomic_*").

For some background information on this, see:

https://gcc.gnu.org/wiki/Atomic/GCCMM

Changes in v2:
- clarify meaning of lock-free in commit message
- fix build if -latomic is not necessary

Acked-by: Matt Turner 
Signed-off-by: Thierry Reding 
---
 meson.build  | 17 +
 src/util/meson.build |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index e9928a379313..bb6a835084fe 100644
--- a/meson.build
+++ b/meson.build
@@ -790,9 +790,26 @@ else
 endif
 
 # Check for GCC style atomics
+dep_atomic = declare_dependency()
+
 if cc.compiles('int main() { int n; return __atomic_load_n(, 
__ATOMIC_ACQUIRE); }',
name : 'GCC atomic builtins')
   pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
+
+  # Not all atomic calls can be turned into lock-free instructions, in which
+  # GCC will make calls into the libatomic library. Check whether we need to
+  # link with -latomic.
+  #
+  # This can happen for 64-bit atomic operations on 32-bit architectures such
+  # as ARM.
+  if not cc.links('''#include 
+ int main() {
+   uint64_t n;
+   return (int)__atomic_load_n(, __ATOMIC_ACQUIRE);
+ }''',
+  name : 'GCC atomic builtins required -latomic')
+dep_atomic = cc.find_library('atomic')
+  endif
 endif
 if not cc.links('''#include 
uint64_t v;
diff --git a/src/util/meson.build b/src/util/meson.build
index b23dba3a9851..eece1cefef6a 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -102,7 +102,7 @@ libmesa_util = static_library(
   'mesa_util',
   [files_mesa_util, format_srgb],
   include_directories : inc_common,
-  dependencies : [dep_zlib, dep_clock, dep_thread],
+  dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic],
   c_args : [c_msvc_compat_args, c_vis_args],
   build_by_default : false
 )
-- 
2.16.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev