From 57838dd632b93aba733c15bd4a488b317f88e152 Mon Sep 17 00:00:00 2001 From: khizmax Date: Wed, 8 Mar 2017 12:53:00 +0300 Subject: [PATCH] Revised processor-specific hints for back-off --- cds/algo/backoff_strategy.h | 4 +- cds/compiler/backoff.h | 6 ++- cds/compiler/clang/defs.h | 10 +---- cds/compiler/gcc/amd64/backoff.h | 21 ++++------- cds/compiler/gcc/arm7/backoff.h | 52 ++++++++++++++++++++++++++ cds/compiler/gcc/arm8/backoff.h | 52 ++++++++++++++++++++++++++ cds/compiler/gcc/ia64/backoff.h | 6 --- cds/compiler/gcc/ppc64/backoff.h | 7 ++++ cds/compiler/gcc/sparc/backoff.h | 4 -- cds/compiler/gcc/x86/backoff.h | 21 ++++------- cds/compiler/vc/amd64/backoff.h | 8 ++-- cds/compiler/vc/x86/backoff.h | 11 ++---- projects/Win/vc14/cds.vcxproj | 2 + projects/Win/vc14/cds.vcxproj.filters | 12 ++++++ projects/Win/vc141/cds.vcxproj | 2 + projects/Win/vc141/cds.vcxproj.filters | 12 ++++++ 16 files changed, 169 insertions(+), 61 deletions(-) create mode 100644 cds/compiler/gcc/arm7/backoff.h create mode 100644 cds/compiler/gcc/arm8/backoff.h diff --git a/cds/algo/backoff_strategy.h b/cds/algo/backoff_strategy.h index 62cf5a5d..0e0711b3 100644 --- a/cds/algo/backoff_strategy.h +++ b/cds/algo/backoff_strategy.h @@ -129,8 +129,8 @@ namespace cds { //@cond void operator ()() const CDS_NOEXCEPT { -# ifdef CDS_backoff_pause_defined - platform::backoff_pause(); +# ifdef CDS_backoff_hint_defined + platform::backoff_hint(); # endif } diff --git a/cds/compiler/backoff.h b/cds/compiler/backoff.h index 9cfce783..cdb51fd7 100644 --- a/cds/compiler/backoff.h +++ b/cds/compiler/backoff.h @@ -52,8 +52,10 @@ # include # elif CDS_PROCESSOR_ARCH == CDS_PROCESSOR_PPC64 # include -//# elif CDS_PROCESSOR_ARCH == CDS_PROCESSOR_ARM7 -//# include +# elif CDS_PROCESSOR_ARCH == CDS_PROCESSOR_ARM7 +# include +# elif CDS_PROCESSOR_ARCH == CDS_PROCESSOR_ARM8 +# include # endif #else # error "Undefined compiler" diff --git a/cds/compiler/clang/defs.h b/cds/compiler/clang/defs.h index 49723b2b..01898169 100644 --- a/cds/compiler/clang/defs.h +++ b/cds/compiler/clang/defs.h @@ -31,12 +31,6 @@ #ifndef CDSLIB_COMPILER_CLANG_DEFS_H #define CDSLIB_COMPILER_CLANG_DEFS_H -/* - Known issues: - Error compiling 64bit boost.atomic on clang 3.4 - 3.5, see https://svn.boost.org/trac/boost/ticket/9610 - Solution: use boost 1.56 + -*/ - // Compiler version #define CDS_COMPILER_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) @@ -44,8 +38,8 @@ #define CDS_COMPILER__NAME ("clang " __clang_version__) #define CDS_COMPILER__NICK "clang" -#if CDS_COMPILER_VERSION < 30300 -# error "Compiler version error. Clang version 3.3.0 and above is supported" +#if CDS_COMPILER_VERSION < 30600 +# error "Compiler version error. Clang version 3.6.0 and above is supported" #endif #if defined(_LIBCPP_VERSION) && !defined(CDS_USE_BOOST_ATOMIC) && CDS_COMPILER_VERSION < 30700 diff --git a/cds/compiler/gcc/amd64/backoff.h b/cds/compiler/gcc/amd64/backoff.h index 6ee6bc4f..9896260c 100644 --- a/cds/compiler/gcc/amd64/backoff.h +++ b/cds/compiler/gcc/amd64/backoff.h @@ -36,26 +36,19 @@ namespace cds { namespace backoff { namespace gcc { namespace amd64 { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) - { - asm volatile ( - "andl %[nLoop], %%ecx; \n\t" - "cmovzl %[nLoop], %%ecx; \n\t" - "rep; " - "nop; \n\t" - : /*no output*/ - : [nLoop] "r" (nLoop) - : "ecx", "cc" - ); - } - # define CDS_backoff_nop_defined static inline void backoff_nop() { asm volatile ( "nop;" ); } +# define CDS_backoff_hint_defined + static inline void backoff_hint() + { + asm volatile ( "pause;" ); + } + + }} // namespace gcc::amd64 namespace platform { diff --git a/cds/compiler/gcc/arm7/backoff.h b/cds/compiler/gcc/arm7/backoff.h new file mode 100644 index 00000000..c5e3a579 --- /dev/null +++ b/cds/compiler/gcc/arm7/backoff.h @@ -0,0 +1,52 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSLIB_COMPILER_GCC_ARM7_BACKOFF_H +#define CDSLIB_COMPILER_GCC_ARM7_BACKOFF_H + +//@cond none + +namespace cds { namespace backoff { + namespace gcc { namespace arm7 { + +# define CDS_backoff_hint_defined + static inline void backoff_hint() + { + asm volatile( "yield" ::: "memory" ); + } + }} // namespace gcc::arm7 + + namespace platform { + using namespace gcc::arm7; + } +}} // namespace cds::backoff + +//@endcond +#endif // #ifndef CDSLIB_COMPILER_GCC_ARM7_BACKOFF_H diff --git a/cds/compiler/gcc/arm8/backoff.h b/cds/compiler/gcc/arm8/backoff.h new file mode 100644 index 00000000..72a6083a --- /dev/null +++ b/cds/compiler/gcc/arm8/backoff.h @@ -0,0 +1,52 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSLIB_COMPILER_GCC_ARM8_BACKOFF_H +#define CDSLIB_COMPILER_GCC_ARM8_BACKOFF_H + +//@cond none + +namespace cds { namespace backoff { + namespace gcc { namespace arm8 { + +# define CDS_backoff_hint_defined + static inline void backoff_hint() + { + asm volatile( "yield" ::: "memory" ); + } + }} // namespace gcc::arm8 + + namespace platform { + using namespace gcc::arm8; + } +}} // namespace cds::backoff + +//@endcond +#endif // #ifndef CDSLIB_COMPILER_GCC_ARM8_BACKOFF_H diff --git a/cds/compiler/gcc/ia64/backoff.h b/cds/compiler/gcc/ia64/backoff.h index ecc6eb16..5a0304ed 100644 --- a/cds/compiler/gcc/ia64/backoff.h +++ b/cds/compiler/gcc/ia64/backoff.h @@ -36,12 +36,6 @@ namespace cds { namespace backoff { namespace gcc { namespace ia64 { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) - { - asm volatile ( "hint @pause" ); - } - # define CDS_backoff_hint_defined static inline void backoff_hint() { diff --git a/cds/compiler/gcc/ppc64/backoff.h b/cds/compiler/gcc/ppc64/backoff.h index f1bf7fd2..75e45741 100644 --- a/cds/compiler/gcc/ppc64/backoff.h +++ b/cds/compiler/gcc/ppc64/backoff.h @@ -36,6 +36,13 @@ namespace cds { namespace backoff { namespace gcc { namespace ppc64 { +# define CDS_backoff_hint_defined + static inline void backoff_hint() + { + // Provide a hint that performance will probably be improved + // if shared resources dedicated to the executing processor are released for use by other processors + asm volatile( "or 27,27,27 # yield" ); + } }} // namespace gcc::ppc64 namespace platform { diff --git a/cds/compiler/gcc/sparc/backoff.h b/cds/compiler/gcc/sparc/backoff.h index 76fb9c45..41f7ac97 100644 --- a/cds/compiler/gcc/sparc/backoff.h +++ b/cds/compiler/gcc/sparc/backoff.h @@ -36,10 +36,6 @@ namespace cds { namespace backoff { namespace gcc { namespace Sparc { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) - {} - # define CDS_backoff_nop_defined static inline void backoff_nop() { diff --git a/cds/compiler/gcc/x86/backoff.h b/cds/compiler/gcc/x86/backoff.h index 777bac04..30324066 100644 --- a/cds/compiler/gcc/x86/backoff.h +++ b/cds/compiler/gcc/x86/backoff.h @@ -36,26 +36,19 @@ namespace cds { namespace backoff { namespace gcc { namespace x86 { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) - { - asm volatile ( - "andl %[nLoop], %%ecx; \n\t" - "cmovzl %[nLoop], %%ecx; \n\t" - "rep; " - "nop; \n\t" - : /*no output*/ - : [nLoop] "r" (nLoop) - : "ecx", "cc" - ); - } - # define CDS_backoff_nop_defined static inline void backoff_nop() { asm volatile ( "nop;" ); } +# define CDS_backoff_hint_defined + static inline void backoff_hint() + { + asm volatile ( "pause;" ); + } + + }} // namespace gcc::x86 namespace platform { diff --git a/cds/compiler/vc/amd64/backoff.h b/cds/compiler/vc/amd64/backoff.h index a26b0a05..87eec6a5 100644 --- a/cds/compiler/vc/amd64/backoff.h +++ b/cds/compiler/vc/amd64/backoff.h @@ -32,15 +32,15 @@ #define CDSLIB_COMPILER_VC_AMD64_BACKOFF_H //@cond none +#include namespace cds { namespace backoff { namespace vc { namespace amd64 { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) +# define CDS_backoff_hint_defined + static inline void backoff_hint() { - for ( unsigned int i = 0; i < nLoop; i++ ) - __nop(); + _mm_pause(); } # define CDS_backoff_nop_defined diff --git a/cds/compiler/vc/x86/backoff.h b/cds/compiler/vc/x86/backoff.h index 8545104d..e2113e95 100644 --- a/cds/compiler/vc/x86/backoff.h +++ b/cds/compiler/vc/x86/backoff.h @@ -32,18 +32,15 @@ #define CDSLIB_COMPILER_VC_X86_BACKOFF_H //@cond none +#include namespace cds { namespace backoff { namespace vc { namespace x86 { -# define CDS_backoff_pause_defined - static inline void backoff_pause( unsigned int nLoop = 0x000003FF ) +# define CDS_backoff_hint_defined + static inline void backoff_hint() { - __asm { - and ecx, nLoop; - cmovz ecx, nLoop; - rep nop; - } + _mm_pause(); } # define CDS_backoff_nop_defined diff --git a/projects/Win/vc14/cds.vcxproj b/projects/Win/vc14/cds.vcxproj index a0d0f66a..ada6ba79 100644 --- a/projects/Win/vc14/cds.vcxproj +++ b/projects/Win/vc14/cds.vcxproj @@ -396,6 +396,8 @@ + + diff --git a/projects/Win/vc14/cds.vcxproj.filters b/projects/Win/vc14/cds.vcxproj.filters index c5448492..82017a5f 100644 --- a/projects/Win/vc14/cds.vcxproj.filters +++ b/projects/Win/vc14/cds.vcxproj.filters @@ -147,6 +147,12 @@ {0a2328b4-ff6f-4afb-8de0-9884ae172fa9} + + {8f1fe8df-3837-42fd-a2f7-581aaf653c53} + + + {fb32845c-1b47-49d0-8065-4a0aa4b55d6d} + @@ -1246,5 +1252,11 @@ Header Files\cds\details + + Header Files\cds\compiler\gcc\arm7 + + + Header Files\cds\compiler\gcc\arm8 + \ No newline at end of file diff --git a/projects/Win/vc141/cds.vcxproj b/projects/Win/vc141/cds.vcxproj index 02cdd5db..2079d4cf 100644 --- a/projects/Win/vc141/cds.vcxproj +++ b/projects/Win/vc141/cds.vcxproj @@ -396,6 +396,8 @@ + + diff --git a/projects/Win/vc141/cds.vcxproj.filters b/projects/Win/vc141/cds.vcxproj.filters index 2b0de7cb..3b28674f 100644 --- a/projects/Win/vc141/cds.vcxproj.filters +++ b/projects/Win/vc141/cds.vcxproj.filters @@ -147,6 +147,12 @@ {0a2328b4-ff6f-4afb-8de0-9884ae172fa9} + + {151e21e7-1535-430a-a7d1-676b93d8162c} + + + {754f330c-8443-4012-b05b-41b3eba647f9} + @@ -1246,5 +1252,11 @@ Header Files\cds\details + + Header Files\cds\compiler\gcc\arm8 + + + Header Files\cds\compiler\gcc\arm7 + \ No newline at end of file -- 2.34.1