From dedaae98309f8412f4fe33d624ce38c344117c73 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Sun, 2 Jul 2017 21:20:10 -0700 Subject: [PATCH] Replace folly::asm_pause with folly::asm_volatile_pause Summary: There is no difference, as the statements are already implicitly volatile. Reviewed By: yfeldblum Differential Revision: D5363491 fbshipit-source-id: ab5bb878f5ca72aa0de96f82e345213729c071e2 --- folly/MicroLock.cpp | 2 +- folly/SharedMutex.h | 2 +- folly/detail/AtomicHashUtils.h | 2 +- folly/portability/Asm.h | 12 ------------ folly/test/SmallLocksTest.cpp | 2 +- folly/test/SpinLockTest.cpp | 6 +++--- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/folly/MicroLock.cpp b/folly/MicroLock.cpp index 06e8de08..ac587ca0 100644 --- a/folly/MicroLock.cpp +++ b/folly/MicroLock.cpp @@ -51,7 +51,7 @@ retry: // sched_yield(), but more portable std::this_thread::yield(); } else { - folly::asm_pause(); + folly::asm_volatile_pause(); } oldWord = wordPtr->load(std::memory_order_relaxed); goto retry; diff --git a/folly/SharedMutex.h b/folly/SharedMutex.h index 24d8051c..163382ab 100644 --- a/folly/SharedMutex.h +++ b/folly/SharedMutex.h @@ -991,7 +991,7 @@ class SharedMutexImpl { return; } } - asm_pause(); + asm_volatile_pause(); if (UNLIKELY(++spinCount >= kMaxSpinCount)) { applyDeferredReaders(state, ctx, slot); return; diff --git a/folly/detail/AtomicHashUtils.h b/folly/detail/AtomicHashUtils.h index 70d30ac2..e9ca9d0b 100644 --- a/folly/detail/AtomicHashUtils.h +++ b/folly/detail/AtomicHashUtils.h @@ -29,7 +29,7 @@ void atomic_hash_spin_wait(Cond condition) { constexpr size_t kPauseLimit = 10000; for (size_t i = 0; condition(); ++i) { if (i < kPauseLimit) { - folly::asm_pause(); + folly::asm_volatile_pause(); } else { std::this_thread::yield(); } diff --git a/folly/portability/Asm.h b/folly/portability/Asm.h index f3343649..f7b7ebba 100644 --- a/folly/portability/Asm.h +++ b/folly/portability/Asm.h @@ -42,16 +42,4 @@ inline void asm_volatile_pause() { asm volatile("or 27,27,27"); #endif } - -inline void asm_pause() { -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) - ::_mm_pause(); -#elif defined(__i386__) || FOLLY_X64 - asm("pause"); -#elif FOLLY_A64 || defined(__arm__) - asm("yield"); -#elif FOLLY_PPC64 - asm("or 31,31,31"); -#endif -} } diff --git a/folly/test/SmallLocksTest.cpp b/folly/test/SmallLocksTest.cpp index 9da8b2bd..77f42db7 100644 --- a/folly/test/SmallLocksTest.cpp +++ b/folly/test/SmallLocksTest.cpp @@ -71,7 +71,7 @@ void splock_test() { const int max = 1000; auto rng = folly::ThreadLocalPRNG(); for (int i = 0; i < max; i++) { - folly::asm_pause(); + folly::asm_volatile_pause(); MSLGuard g(v.lock); int first = v.ar[0]; diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 67279a70..1f53d76f 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -42,7 +42,7 @@ void spinlockTestThread(LockedVal* v) { const int max = 1000; auto rng = folly::ThreadLocalPRNG(); for (int i = 0; i < max; i++) { - folly::asm_pause(); + folly::asm_volatile_pause(); SpinLockGuardImpl g(v->lock); int first = v->ar[0]; @@ -67,7 +67,7 @@ struct TryLockState { template void trylockTestThread(TryLockState* state, size_t count) { while (true) { - folly::asm_pause(); + folly::asm_volatile_pause(); bool ret = state->lock2.try_lock(); SpinLockGuardImpl g(state->lock1); if (state->obtained >= count) { @@ -89,7 +89,7 @@ void trylockTestThread(TryLockState* state, size_t count) { auto oldFailed = state->failed; while (state->failed == oldFailed && state->obtained < count) { state->lock1.unlock(); - folly::asm_pause(); + folly::asm_volatile_pause(); state->lock1.lock(); } -- 2.34.1