[llvm-commits] [compiler-rt] r170427 - in /compiler-rt/trunk/lib/tsan/rtl: tsan_fd.cc tsan_flags.cc tsan_flags.h

Dmitry Vyukov dvyukov at google.com
Tue Dec 18 04:20:55 PST 2012


Author: dvyukov
Date: Tue Dec 18 06:20:55 2012
New Revision: 170427

URL: http://llvm.org/viewvc/llvm-project?rev=170427&view=rev
Log:
tsan: add io_sync flag that controls amount of IO synchronization

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc?rev=170427&r1=170426&r2=170427&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_fd.cc Tue Dec 18 06:20:55 2012
@@ -92,7 +92,15 @@
   // See e.g. libc __res_iclose().
   if (d->sync)
     unref(thr, pc, d->sync);
-  d->sync = s;
+  if (flags()->io_sync == 0) {
+    unref(thr, pc, s);
+    d->sync = 0;
+  } else if (flags()->io_sync == 1) {
+    d->sync = s;
+  } else if (flags()->io_sync == 2) {
+    unref(thr, pc, s);
+    d->sync = &fdctx.globsync;
+  }
   d->creation_tid = thr->tid;
   d->creation_stack = CurrentStackId(thr, pc);
   // To catch races between fd usage and open.
@@ -171,8 +179,9 @@
 void FdPipeCreate(ThreadState *thr, uptr pc, int rfd, int wfd) {
   DPrintf("#%d: FdCreatePipe(%d, %d)\n", thr->tid, rfd, wfd);
   FdSync *s = allocsync();
-  init(thr, pc, rfd, s);
+  init(thr, pc, rfd, ref(s));
   init(thr, pc, wfd, ref(s));
+  unref(thr, pc, s);
 }
 
 void FdEventCreate(ThreadState *thr, uptr pc, int fd) {

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=170427&r1=170426&r2=170427&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Tue Dec 18 06:20:55 2012
@@ -58,6 +58,7 @@
   f->running_on_valgrind = false;
   f->external_symbolizer_path = "";
   f->history_size = kGoMode ? 1 : 2;  // There are a lot of goroutines in Go.
+  f->io_sync = 1;
 
   // Let a frontend override.
   OverrideFlags(f);
@@ -83,6 +84,7 @@
   ParseFlag(env, &f->stop_on_start, "stop_on_start");
   ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path");
   ParseFlag(env, &f->history_size, "history_size");
+  ParseFlag(env, &f->io_sync, "io_sync");
 
   if (!f->report_bugs) {
     f->report_thread_leaks = false;
@@ -95,6 +97,12 @@
            " (must be [0..7])\n");
     Die();
   }
+
+  if (f->io_sync < 0 || f->io_sync > 2) {
+    Printf("ThreadSanitizer: incorrect value for io_sync"
+           " (must be [0..2])\n");
+    Die();
+  }
 }
 
 }  // namespace __tsan

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=170427&r1=170426&r2=170427&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Tue Dec 18 06:20:55 2012
@@ -77,6 +77,11 @@
   // the amount of memory accesses, up to history_size=7 that amounts to
   // 4M memory accesses.  The default value is 2 (128K memory accesses).
   int history_size;
+  // Controls level of synchronization implied by IO operations.
+  // 0 - no synchronization
+  // 1 - reasonable level of synchronization (write->read)
+  // 2 - global synchronization of all IO operations
+  int io_sync;
 };
 
 Flags *flags();





More information about the llvm-commits mailing list