Commit 614cc8c3 authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Add flags to asymmetric mem barrier

Summary:
Original sys_membarrier call supported an EXPEDITED flag, that was much faster than the current version, at some extra CPU cost.

The basic idea was a normal one would be used in a background thread, while EXPEDITED would be useful inline in foreground threads.

Add the flag here, and use the mprotect hack until sys_membarrier supports both.

Reviewed By: magedm

Differential Revision: D5292680

fbshipit-source-id: 30edf27514976991bbaa8e776a7138eb815ade36
parent 08f64cbb
......@@ -32,8 +32,7 @@ struct DummyPageCreator {
}
static void* get() {
static auto ptr =
kIsLinux && !detail::sysMembarrierAvailable() ? create() : nullptr;
static auto ptr = kIsLinux ? create() : nullptr;
return ptr;
}
......@@ -81,10 +80,11 @@ void mprotectMembarrier() {
}
}
void asymmetricHeavyBarrier() {
void asymmetricHeavyBarrier(AMBFlags flags) {
if (kIsLinux) {
static const bool useSysMembarrier = detail::sysMembarrierAvailable();
if (useSysMembarrier) {
// sys_membarrier currently does not support EXPEDITED
if (useSysMembarrier && flags != AMBFlags::EXPEDITED) {
auto r = detail::sysMembarrier();
checkUnixError(r, "membarrier");
} else {
......
......@@ -22,6 +22,11 @@
namespace folly {
enum class AMBFlags {
NORMAL,
EXPEDITED,
};
FOLLY_ALWAYS_INLINE void asymmetricLightBarrier() {
if (kIsLinux) {
asm_volatile_memory();
......@@ -30,5 +35,5 @@ FOLLY_ALWAYS_INLINE void asymmetricLightBarrier() {
}
}
void asymmetricHeavyBarrier();
void asymmetricHeavyBarrier(AMBFlags flags = AMBFlags::NORMAL);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment