[all-commits] [llvm/llvm-project] 1fa4c1: sanitizer_common: optimize Mutex for high contention
Dmitry Vyukov via All-commits
all-commits at lists.llvm.org
Tue Aug 10 11:03:20 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1fa4c188b5a4187dba7e3809d8fd6d6eccff99f4
https://github.com/llvm/llvm-project/commit/1fa4c188b5a4187dba7e3809d8fd6d6eccff99f4
Author: Dmitry Vyukov <dvyukov at google.com>
Date: 2021-08-10 (Tue, 10 Aug 2021)
Changed paths:
M compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
Log Message:
-----------
sanitizer_common: optimize Mutex for high contention
After switching tsan from the old mutex to the new sanitizer_common mutex,
we've observed a significant degradation of performance on a test.
The test effectively stresses a lock-free stack with 4 threads
with a mix of atomic_compare_exchange and atomic_load operations.
The former takes write lock, while the latter takes read lock.
It turned out the new mutex performs worse because readers don't
use active spinning, which results in significant amount of thread
blocking/unblocking. The old tsan mutex used active spinning
for both writers and readers.
Add active spinning for readers.
Don't hand off the mutex to readers, and instread make them
compete for the mutex after wake up again.
This makes readers and writers almost symmetric.
Reviewed By: melver
Differential Revision: https://reviews.llvm.org/D107824
More information about the All-commits
mailing list