freebsd/x86: Allow and override fence instructions to match kernel environment.

This is mostly based off of Olivier's (cognet@) work. I was considering
importing in __mbk but realistically, doesn't warrant the refactor.
cos
Samy Al Bahra 7 years ago
parent 064340dd62
commit 5517381929

@ -100,19 +100,12 @@
*/ */
#if defined(__i386__) && !defined(__x86__) #if defined(__i386__) && !defined(__x86__)
#define __x86__ #define __x86__
#define CK_MD_TSO
/* /*
* On i386, we resort to building the fence instructions on top of * If x86 becomes more relevant, we may want to consider importing in
* the kernel-provided facilities. * __mbk() to avoid potential issues around false sharing.
*/ */
#include <sys/cdefs.h> #define CK_MD_TSO
#include <sys/atomic.h> #define CK_MD_SSE_DISABLE 1
#define CK_MD_X86_MFENCE() mb()
#define CK_MD_X86_SFENCE() wmb()
#define CK_MD_X86_LFENCE() rmb()
#elif defined(__amd64__) #elif defined(__amd64__)
#define CK_MD_TSO #define CK_MD_TSO
#elif defined(__sparc64__) && !defined(__sparcv9__) #elif defined(__sparc64__) && !defined(__sparcv9__)

@ -45,15 +45,9 @@
/* Minimum requirements for the CK_PR interface are met. */ /* Minimum requirements for the CK_PR interface are met. */
#define CK_F_PR #define CK_F_PR
#ifdef CK_MD_UMP
#define CK_PR_LOCK_PREFIX
#else
#define CK_PR_LOCK_PREFIX "lock "
#endif /* CK_MD_UMP */
/* /*
* Prevent speculative execution in busy-wait loops (P4 <=) * Prevent speculative execution in busy-wait loops (P4 <=) or "predefined
* or "predefined delay". * delay".
*/ */
CK_CC_INLINE static void CK_CC_INLINE static void
ck_pr_stall(void) ck_pr_stall(void)
@ -62,28 +56,52 @@ ck_pr_stall(void)
return; return;
} }
#ifdef CK_MD_UMP
#define CK_PR_LOCK_PREFIX
#define CK_PR_FENCE(T, I) \
CK_CC_INLINE static void \
ck_pr_fence_strict_##T(void) \
{ \
__asm__ __volatile__("" ::: "memory"); \
return; \
}
#else
#define CK_PR_LOCK_PREFIX "lock "
#define CK_PR_FENCE(T, I) \ #define CK_PR_FENCE(T, I) \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_pr_fence_strict_##T(void) \ ck_pr_fence_strict_##T(void) \
{ \ { \
__asm__ __volatile__(I ::: "memory"); \ __asm__ __volatile__(I ::: "memory"); \
return; \
} }
#endif /* CK_MD_UMP */
CK_PR_FENCE(atomic, "sfence") #if defined(CK_MD_SSE_DISABLE)
CK_PR_FENCE(atomic_store, "sfence") /* If SSE is disabled, then use atomic operations for serialization. */
CK_PR_FENCE(atomic_load, "mfence") #define CK_MD_X86_MFENCE "lock addl $0, (%%esp)"
CK_PR_FENCE(store_atomic, "sfence") #define CK_MD_X86_SFENCE CK_MD_X86_MFENCE
CK_PR_FENCE(load_atomic, "mfence") #define CK_MD_X86_LFENCE CK_MD_X86_MFENCE
CK_PR_FENCE(load, "lfence") #else
CK_PR_FENCE(load_store, "mfence") #define CK_MD_X86_SFENCE "sfence"
CK_PR_FENCE(store, "sfence") #define CK_MD_X86_LFENCE "lfence"
CK_PR_FENCE(store_load, "mfence") #define CK_MD_X86_MFENCE "mfence"
CK_PR_FENCE(memory, "mfence") #endif /* !CK_MD_SSE_DISABLE */
CK_PR_FENCE(release, "mfence")
CK_PR_FENCE(acquire, "mfence") CK_PR_FENCE(atomic, "")
CK_PR_FENCE(acqrel, "mfence") CK_PR_FENCE(atomic_store, "")
CK_PR_FENCE(lock, "mfence") CK_PR_FENCE(atomic_load, "")
CK_PR_FENCE(unlock, "mfence") CK_PR_FENCE(store_atomic, "")
CK_PR_FENCE(load_atomic, "")
CK_PR_FENCE(load, CK_MD_X86_LFENCE)
CK_PR_FENCE(load_store, CK_MD_X86_MFENCE)
CK_PR_FENCE(store, CK_MD_X86_SFENCE)
CK_PR_FENCE(store_load, CK_MD_X86_MFENCE)
CK_PR_FENCE(memory, CK_MD_X86_MFENCE)
CK_PR_FENCE(release, CK_MD_X86_MFENCE)
CK_PR_FENCE(acquire, CK_MD_X86_MFENCE)
CK_PR_FENCE(acqrel, CK_MD_X86_MFENCE)
CK_PR_FENCE(lock, CK_MD_X86_MFENCE)
CK_PR_FENCE(unlock, CK_MD_X86_MFENCE)
#undef CK_PR_FENCE #undef CK_PR_FENCE

Loading…
Cancel
Save