Revert "Do not use unnecessary `membarrier()` on x86."
This reverts commit c216744a805eed597dd490a26e53d15dd6e7af2a.
Reason for revert: b/265977812
Change-Id: I4277612c3e4b4b44e74bd7ba90e6aaea37cc9e76
diff --git a/libartbase/base/membarrier.cc b/libartbase/base/membarrier.cc
index 520bbbe..48f47df 100644
--- a/libartbase/base/membarrier.cc
+++ b/libartbase/base/membarrier.cc
@@ -24,7 +24,6 @@
#include <sys/utsname.h>
#include <unistd.h>
#endif
-#include "arch/instruction_set.h"
#include "macros.h"
#if defined(__BIONIC__)
@@ -46,21 +45,9 @@
namespace art {
-int membarrier(MembarrierCommand command) {
- if (kRuntimeISA == InstructionSet::kX86 || kRuntimeISA == InstructionSet::kX86_64) {
- // On x86, the `kPrivateExpedited` command is unnecessary thanks to the memory model.
- // The corresponding `kRegisterPrivateExpedited` command is also unnecessary.
- if (command == MembarrierCommand::kPrivateExpedited) {
- // We still want to prevent instruction reordering in case of whole program optimization.
- std::atomic_signal_fence(std::memory_order_seq_cst);
- return 0;
- }
- if (command == MembarrierCommand::kRegisterPrivateExpedited) {
- return 0;
- }
- }
-
#if defined(__NR_membarrier)
+
+int membarrier(MembarrierCommand command) {
// Check kernel version supports membarrier(2).
static constexpr int kRequiredMajor = 4;
static constexpr int kRequiredMinor = 16;
@@ -84,13 +71,17 @@
}
#endif // __BIONIC__
return syscall(__NR_membarrier, static_cast<int>(command), 0);
+}
+
#else // __NR_membarrier
+
+int membarrier(MembarrierCommand command ATTRIBUTE_UNUSED) {
// In principle this could be supported on linux, but Android's prebuilt glibc does not include
// the system call number defintions (b/111199492).
- UNUSED(command);
errno = ENOSYS;
return -1;
-#endif // __NR_membarrier
}
+#endif // __NR_membarrier
+
} // namespace art
diff --git a/libartbase/base/utils.cc b/libartbase/base/utils.cc
index 3ed0f16..bff9f45 100644
--- a/libartbase/base/utils.cc
+++ b/libartbase/base/utils.cc
@@ -42,6 +42,8 @@
#endif
#if defined(__BIONIC__)
+// membarrier(2) is only supported for target builds (b/111199492).
+#include <linux/membarrier.h>
#include <sys/syscall.h>
#endif