[llvm-commits] [compiler-rt] r157252 - in /compiler-rt/trunk/lib/tsan: rtl/tsan_defs.h rtl/tsan_mman.h rtl/tsan_platform_linux.cc rtl/tsan_rtl.cc rtl/tsan_rtl.h rtl/tsan_rtl_report.cc rtl/tsan_rtl_thread.cc rtl/tsan_trace.h rtl_tests/tsan_test_util_linux.cc

Dmitry Vyukov dvyukov at google.com
Tue May 22 07:34:43 PDT 2012


Author: dvyukov
Date: Tue May 22 09:34:43 2012
New Revision: 157252

URL: http://llvm.org/viewvc/llvm-project?rev=157252&view=rev
Log:
tsan: reduce per-thread memory usage

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h
    compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h Tue May 22 09:34:43 2012
@@ -29,7 +29,7 @@
 typedef unsigned long uptr;  // NOLINT
 
 const uptr kPageSize = 4096;
-const int kTidBits = 15;
+const int kTidBits = 13;
 const unsigned kMaxTid = 1 << kTidBits;
 const unsigned kMaxTidInClock = kMaxTid * 2;  // This includes msb 'freed' bit.
 const int kClkBits = 40;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h Tue May 22 09:34:43 2012
@@ -39,6 +39,7 @@
   MBlockSync,
   MBlockClock,
   MBlockThreadContex,
+  MBlockDeadInfo,
   MBlockRacyStacks,
   MBlockRacyAddresses,
   MBlockAtExit,

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Tue May 22 09:34:43 2012
@@ -241,13 +241,8 @@
   if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
     CHECK_GT(*tls_addr + *tls_size, *stk_addr);
     CHECK_LE(*tls_addr + *tls_size, *stk_addr + *stk_size);
-    *stk_size = *tls_addr - *stk_addr;
-    *stk_size = RoundUp(*stk_size, kPageSize);
-    uptr stk_end = *stk_addr + *stk_size;
-    if (stk_end > *tls_addr) {
-      *tls_size -= *tls_addr - stk_end;
-      *tls_addr = stk_end;
-    }
+    *stk_size -= *tls_size;
+    *tls_addr = *stk_addr + *stk_size;
   }
 }
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue May 22 09:34:43 2012
@@ -76,6 +76,7 @@
   , reuse_count()
   , epoch0()
   , epoch1()
+  , dead_info()
   , dead_next() {
 }
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Tue May 22 09:34:43 2012
@@ -207,7 +207,7 @@
 // As if 8-byte write by thread 0xff..f at epoch 0xff..f, races with everything.
 const u64 kShadowFreed = 0xfffffffffffffff8ull;
 
-const int kSigCount = 1024;
+const int kSigCount = 128;
 const int kShadowStackSize = 1024;
 
 struct my_siginfo_t {
@@ -301,8 +301,8 @@
   u64 epoch0;
   u64 epoch1;
   StackTrace creation_stack;
-  ThreadDeadInfo dead_info;
-  ThreadContext* dead_next;  // In dead thread list.
+  ThreadDeadInfo *dead_info;
+  ThreadContext *dead_next;  // In dead thread list.
 
   explicit ThreadContext(int tid);
 };

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Tue May 22 09:34:43 2012
@@ -175,7 +175,9 @@
     trace = &tctx->thr->trace;
   } else if (tctx->status == ThreadStatusFinished
       || tctx->status == ThreadStatusDead) {
-    trace = &tctx->dead_info.trace;
+    if (tctx->dead_info == 0)
+      return;
+    trace = &tctx->dead_info->trace;
   } else {
     return;
   }

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Tue May 22 09:34:43 2012
@@ -20,7 +20,7 @@
 
 namespace __tsan {
 
-const int kThreadQuarantineSize = 100;
+const int kThreadQuarantineSize = 16;
 
 static void MaybeReportThreadLeak(ThreadContext *tctx) {
   if (tctx->detached)
@@ -93,8 +93,7 @@
     tctx->status = ThreadStatusInvalid;
     tctx->reuse_count++;
     tid = tctx->tid;
-    // The point to reclain dead_info.
-    // delete tctx->dead_info;
+    DestroyAndFree(tctx->dead_info);
   } else {
     StatInc(thr, StatThreadMaxTid);
     tid = ctx->thread_seq++;
@@ -207,13 +206,12 @@
   }
 
   // Save from info about the thread.
-  // If dead_info will become dynamically allocated again,
-  // it is the point to allocate it.
-  // tctx->dead_info = new ThreadDeadInfo;
-  internal_memcpy(&tctx->dead_info.trace.events[0],
+  tctx->dead_info = new(internal_alloc(MBlockDeadInfo, sizeof(ThreadDeadInfo)))
+      ThreadDeadInfo();
+  internal_memcpy(&tctx->dead_info->trace.events[0],
       &thr->trace.events[0], sizeof(thr->trace.events));
   for (int i = 0; i < kTraceParts; i++) {
-    tctx->dead_info.trace.headers[i].stack0.CopyFrom(
+    tctx->dead_info->trace.headers[i].stack0.CopyFrom(
         thr->trace.headers[i].stack0);
   }
   tctx->epoch1 = thr->clock.get(tctx->tid);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h Tue May 22 09:34:43 2012
@@ -20,7 +20,7 @@
 namespace __tsan {
 
 const int kTraceParts = 8;
-const int kTraceSize = 1024*1024;
+const int kTraceSize = 128*1024;
 const int kTracePartSize = kTraceSize / kTraceParts;
 
 // Must fit into 3 bits.

Modified: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc?rev=157252&r1=157251&r2=157252&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc Tue May 22 09:34:43 2012
@@ -352,6 +352,7 @@
     pthread_attr_t attr;
     pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr, detached);
+    pthread_attr_setstacksize(&attr, 64*1024);
     pthread_create(&impl_->thread, &attr,
         ScopedThread::Impl::ScopedThreadCallback, impl_);
   }





More information about the llvm-commits mailing list