From 2fece910f94695060ee84d0c7ffb7f54a694dfde Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Thu, 18 Apr 2019 10:42:31 +0200 Subject: [PATCH] Add system specific 'relax cpu' instruction. --- lib/pls/include/pls/internal/base/system_details.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/pls/include/pls/internal/base/system_details.h b/lib/pls/include/pls/internal/base/system_details.h index af2e71f..5d61b3f 100644 --- a/lib/pls/include/pls/internal/base/system_details.h +++ b/lib/pls/include/pls/internal/base/system_details.h @@ -24,9 +24,28 @@ constexpr std::uintptr_t CACHE_LINE_SIZE = 64; * Choose one of the following ways to store thread specific data. * Try to choose the fastest available on this processor/system. */ -// #define PLS_THREAD_SPECIFIC_PTHREAD +//#define PLS_THREAD_SPECIFIC_PTHREAD #define PLS_THREAD_SPECIFIC_COMPILER +/** + * When spinning one wants to 'relax' the CPU from some task, + * e.g. disabling speculative execution/branch prediction + * or reducing its clock speed. + * This is both good for power draw, as well as for hyperthreading. + * + * Choose the implementation appropriate for your compiler-cpu combination. + */ +#if (COMPILER == MVCC) +#include +inline void relax_cpu() { + _mm_pause(); +} +#elif (COMPILER == GCC || COMPILER == LLVM) +inline void relax_cpu() { + asm("pause"); +} +#endif + } } } -- libgit2 0.26.0