From 1537c8091da102c649b7335d0de7d4005c510ac4 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sun, 28 Jun 2015 15:06:08 -0400 Subject: [PATCH] ck_pr: Introduce ck_pr_fence_lock and fence_unlock. These primitives are meant to be used in lock implementations where control dependency ordering is sufficient to enforce ordering of critical section. At the moment, this only affects PPC. Currently, we rely on lwsync for entry into critical sections which is insufficient. sync is rather heavy-weight, and assuming we aren't falling victim into compiler re-ordering, isync should be sufficient. There is follow-up work to be done in ARM, as we may have cheaper (but target-specialized) ISB-tricks for load-load ordering. --- include/ck_pr.h | 6 ++++++ include/gcc/arm/ck_pr.h | 2 ++ include/gcc/ck_pr.h | 2 ++ include/gcc/ppc/ck_pr.h | 2 ++ include/gcc/ppc64/ck_pr.h | 2 ++ include/gcc/sparcv9/ck_pr.h | 2 ++ include/gcc/x86/ck_pr.h | 2 ++ include/gcc/x86_64/ck_pr.h | 2 ++ 8 files changed, 20 insertions(+) diff --git a/include/ck_pr.h b/include/ck_pr.h index 3632f7b..00d95a0 100644 --- a/include/ck_pr.h +++ b/include/ck_pr.h @@ -97,6 +97,8 @@ CK_PR_FENCE_EMIT(store) CK_PR_FENCE_EMIT(memory) CK_PR_FENCE_EMIT(acquire) CK_PR_FENCE_EMIT(release) +CK_PR_FENCE_EMIT(lock) +CK_PR_FENCE_EMIT(unlock) #elif defined(CK_MD_PSO) /* * Anything can be re-ordered with respect to stores. @@ -114,6 +116,8 @@ CK_PR_FENCE_EMIT(store) CK_PR_FENCE_EMIT(memory) CK_PR_FENCE_EMIT(acquire) CK_PR_FENCE_EMIT(release) +CK_PR_FENCE_EMIT(lock) +CK_PR_FENCE_EMIT(unlock) #elif defined(CK_MD_TSO) /* * Only loads are re-ordered and only with respect to @@ -131,6 +135,8 @@ CK_PR_FENCE_NOOP(store) CK_PR_FENCE_NOOP(memory) CK_PR_FENCE_NOOP(acquire) CK_PR_FENCE_NOOP(release) +CK_PR_FENCE_NOOP(lock) +CK_PR_FENCE_NOOP(unlock) #else #error "No memory model has been defined." #endif /* CK_MD_TSO */ diff --git a/include/gcc/arm/ck_pr.h b/include/gcc/arm/ck_pr.h index 35be59a..98cdb8d 100644 --- a/include/gcc/arm/ck_pr.h +++ b/include/gcc/arm/ck_pr.h @@ -94,6 +94,8 @@ CK_PR_FENCE(load_store, CK_DMB) CK_PR_FENCE(memory, CK_DMB) CK_PR_FENCE(acquire, CK_DMB) CK_PR_FENCE(release, CK_DMB) +CK_PR_FENCE(lock, CK_DMB) +CK_PR_FENCE(unlock, CK_DMB) #undef CK_PR_FENCE diff --git a/include/gcc/ck_pr.h b/include/gcc/ck_pr.h index 53e75e1..cf6e699 100644 --- a/include/gcc/ck_pr.h +++ b/include/gcc/ck_pr.h @@ -142,6 +142,8 @@ CK_PR_FENCE(store_load) CK_PR_FENCE(memory) CK_PR_FENCE(acquire) CK_PR_FENCE(release) +CK_PR_FENCE(lock) +CK_PR_FENCE(unlock) #undef CK_PR_FENCE diff --git a/include/gcc/ppc/ck_pr.h b/include/gcc/ppc/ck_pr.h index 305039a..ef9105c 100644 --- a/include/gcc/ppc/ck_pr.h +++ b/include/gcc/ppc/ck_pr.h @@ -79,6 +79,8 @@ CK_PR_FENCE(load_store, "lwsync") CK_PR_FENCE(memory, "sync") CK_PR_FENCE(acquire, "lwsync") CK_PR_FENCE(release, "lwsync") +CK_PR_FENCE(lock, "isync") +CK_PR_FENCE(unlock, "lwsync") #undef CK_PR_FENCE diff --git a/include/gcc/ppc64/ck_pr.h b/include/gcc/ppc64/ck_pr.h index 734f954..03a9cf1 100644 --- a/include/gcc/ppc64/ck_pr.h +++ b/include/gcc/ppc64/ck_pr.h @@ -82,6 +82,8 @@ CK_PR_FENCE(load_store, "lwsync") CK_PR_FENCE(memory, "sync") CK_PR_FENCE(acquire, "lwsync") CK_PR_FENCE(release, "lwsync") +CK_PR_FENCE(lock, "isync") +CK_PR_FENCE(unlock, "lwsync") #undef CK_PR_FENCE diff --git a/include/gcc/sparcv9/ck_pr.h b/include/gcc/sparcv9/ck_pr.h index 154d148..9e21748 100644 --- a/include/gcc/sparcv9/ck_pr.h +++ b/include/gcc/sparcv9/ck_pr.h @@ -79,6 +79,8 @@ CK_PR_FENCE(load_store, "membar #LoadStore") CK_PR_FENCE(memory, "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad") CK_PR_FENCE(acquire, "membar #LoadLoad | #LoadStore") CK_PR_FENCE(release, "membar #LoadStore | #StoreStore") +CK_PR_FENCE(lock, "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad") +CK_PR_FENCE(unlock, "membar #LoadStore | #StoreStore") #undef CK_PR_FENCE diff --git a/include/gcc/x86/ck_pr.h b/include/gcc/x86/ck_pr.h index 5eb9e89..c28381d 100644 --- a/include/gcc/x86/ck_pr.h +++ b/include/gcc/x86/ck_pr.h @@ -82,6 +82,8 @@ CK_PR_FENCE(store_load, "mfence") CK_PR_FENCE(memory, "mfence") CK_PR_FENCE(release, "mfence") CK_PR_FENCE(acquire, "mfence") +CK_PR_FENCE(lock, "mfence") +CK_PR_FENCE(unlock, "mfence") #undef CK_PR_FENCE diff --git a/include/gcc/x86_64/ck_pr.h b/include/gcc/x86_64/ck_pr.h index b56776f..9c8dd6d 100644 --- a/include/gcc/x86_64/ck_pr.h +++ b/include/gcc/x86_64/ck_pr.h @@ -88,6 +88,8 @@ CK_PR_FENCE(store_load, "mfence") CK_PR_FENCE(memory, "mfence") CK_PR_FENCE(release, "mfence") CK_PR_FENCE(acquire, "mfence") +CK_PR_FENCE(lock, "mfence") +CK_PR_FENCE(unlock, "mfence") #undef CK_PR_FENCE