summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-06-06 16:27:38 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-06-06 16:27:38 +0000
commitcdf34921914fdffb5575f4820b8754b60b38a980 (patch)
treeb8f107ed78c4aa7ff9e97b357ee66de244dc52ac
parent2e26d9faac0826d9ff9b7a5f2b85ce6c34e24e67 (diff)
downloadbcm5719-llvm-cdf34921914fdffb5575f4820b8754b60b38a980.tar.gz
bcm5719-llvm-cdf34921914fdffb5575f4820b8754b60b38a980.zip
[tsan] On OS X, optimize main thread’s ThreadState accesses
This is a very simple optimization that gets about 10% speedup for certain programs. We’re currently storing the pointer to the main thread’s ThreadState, but we can store the state directly in a static variable, which avoid the load acquire. Differential Revision: http://reviews.llvm.org/D20910 llvm-svn: 271906
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
index 4a8b9217780..0cc02ab87a3 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
@@ -67,20 +67,18 @@ static void *SignalSafeGetOrAllocate(uptr *dst, uptr size) {
// when TLVs are not accessible (early process startup, thread cleanup, ...).
// The following provides a "poor man's TLV" implementation, where we use the
// shadow memory of the pointer returned by pthread_self() to store a pointer to
-// the ThreadState object. The main thread's ThreadState pointer is stored
-// separately in a static variable, because we need to access it even before the
+// the ThreadState object. The main thread's ThreadState is stored separately
+// in a static variable, because we need to access it even before the
// shadow memory is set up.
static uptr main_thread_identity = 0;
-static ThreadState *main_thread_state = nullptr;
+ALIGNED(64) static char main_thread_state[sizeof(ThreadState)];
ThreadState *cur_thread() {
- ThreadState **fake_tls;
uptr thread_identity = (uptr)pthread_self();
if (thread_identity == main_thread_identity || main_thread_identity == 0) {
- fake_tls = &main_thread_state;
- } else {
- fake_tls = (ThreadState **)MemToShadow(thread_identity);
+ return (ThreadState *)&main_thread_state;
}
+ ThreadState **fake_tls = (ThreadState **)MemToShadow(thread_identity);
ThreadState *thr = (ThreadState *)SignalSafeGetOrAllocate(
(uptr *)fake_tls, sizeof(ThreadState));
return thr;
OpenPOWER on IntegriCloud