From 646df4f34e5da0004661f569800505d887c52006 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 10 Feb 2018 08:20:37 +0100 Subject: [PATCH] Move aligned cache line constant to commun header. --- m-buffer.h | 15 +++------------ m-core.h | 8 ++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/m-buffer.h b/m-buffer.h index 52b087f3..a77da753 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -70,15 +70,6 @@ typedef enum { /********************************** INTERNAL ************************************/ -/* Define the exclusion size so that 2 atomic variables can be in - separate cache line. This prevents false sharing to occur within the - CPU cache. */ -#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) -# define BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION 128 -#else -# define BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION 64 -#endif - #define BUFFERI_IF_CTE_SIZE(m_size) M_IF(M_BOOL(m_size)) #define BUFFERI_SIZE(m_size) BUFFERI_IF_CTE_SIZE(m_size) (m_size, v->size) @@ -425,14 +416,14 @@ M_C(name, _init)(buffer_t v, size_t size) \ typedef struct M_C(name, _el_s) { \ atomic_ullong seq; /* Can only increase. */ \ type x; \ - char align[BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION > sizeof(atomic_ullong)+sizeof(type) ? BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION - sizeof(atomic_ullong)-sizeof(type) : 1]; \ + char align[M_ALIGN_FOR_CACHELINE_EXCLUSION > sizeof(atomic_ullong)+sizeof(type) ? M_ALIGN_FOR_CACHELINE_EXCLUSION - sizeof(atomic_ullong)-sizeof(type) : 1]; \ } M_C(name, _el_t); \ \ typedef struct M_C(name, _s) { \ atomic_ullong ProdIdx; /* Can only increase */ \ - char align1[BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION]; \ + char align1[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ atomic_ullong ConsoIdx; /* can only increase */ \ - char align2[BUFFERI_ALIGN_FOR_CACHELINE_EXCLUSION]; \ + char align2[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ M_C(name, _el_t) *Tab; \ unsigned int size; \ } buffer_t[1]; \ diff --git a/m-core.h b/m-core.h index 29bf93f8..0f96bcdf 100644 --- a/m-core.h +++ b/m-core.h @@ -62,6 +62,14 @@ # define M_UNLIKELY(cond) (cond) #endif +/* Define the exclusion size so that 2 atomic variables can be in + separate cache line. This prevents false sharing to occur within the + CPU cache. */ +#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) +# define M_ALIGN_FOR_CACHELINE_EXCLUSION 128 +#else +# define M_ALIGN_FOR_CACHELINE_EXCLUSION 64 +#endif /***************************************************************/ /****************** Preprocessing Times Macro ******************/