From 7515e75bc294e01665fcd8502b51533e9dea86c4 Mon Sep 17 00:00:00 2001 From: Kostya Kortchinsky Date: Mon, 20 Aug 2018 14:57:58 +0000 Subject: [PATCH] [sanitizer] Use private futex operations for BlockingMutex Summary: Use `FUTEX_PRIVATE_FLAG` in conjunction with the wait & wake operations employed by `BlockingMutex`. As far as I can tell, the mutexes are process-private, and there is an actual performance benefit at employing the private operations. There should be no downside to switching to it. Reviewers: eugenis, alekseyshl, dvyukov Reviewed By: dvyukov Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D50910 llvm-svn: 340178 --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 204b0d18ac24..9dbdd21ac656 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -117,6 +117,9 @@ struct kernel_timeval { // is broken on some linux distributions. const int FUTEX_WAIT = 0; const int FUTEX_WAKE = 1; +const int FUTEX_PRIVATE_FLAG = 128; +const int FUTEX_WAIT_PRIVATE = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; +const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; #endif // SANITIZER_LINUX // Are we using 32-bit or 64-bit Linux syscalls? @@ -686,7 +689,8 @@ void BlockingMutex::Lock() { #elif SANITIZER_NETBSD sched_yield(); /* No userspace futex-like synchronization */ #else - internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT, MtxSleeping, 0, 0, 0); + internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT_PRIVATE, MtxSleeping, + 0, 0, 0); #endif } } @@ -701,7 +705,7 @@ void BlockingMutex::Unlock() { #elif SANITIZER_NETBSD /* No userspace futex-like synchronization */ #else - internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAKE, 1, 0, 0, 0); + internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); #endif } }