[compiler-rt] 05ca57a - tsan: better maintain current time in the background thread

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 21 10:51:44 PST 2021


Author: Dmitry Vyukov
Date: 2021-12-21T19:51:39+01:00
New Revision: 05ca57a0543bacfead83a870db900a90134c6d00

URL: https://github.com/llvm/llvm-project/commit/05ca57a0543bacfead83a870db900a90134c6d00
DIFF: https://github.com/llvm/llvm-project/commit/05ca57a0543bacfead83a870db900a90134c6d00.diff

LOG: tsan: better maintain current time in the background thread

Update now after long operations so that we don't use
stale value in subsequent computations.

Depends on D113981.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D113982

Added: 
    

Modified: 
    compiler-rt/lib/tsan/rtl/tsan_rtl.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
index 688f93148619..596199cb2adc 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
@@ -450,7 +450,7 @@ static void *BackgroundThread(void *arg) {
   const u64 kMs2Ns = 1000 * 1000;
   const u64 start = NanoTime();
 
-  u64 last_flush = NanoTime();
+  u64 last_flush = start;
   uptr last_rss = 0;
   for (int i = 0;
       atomic_load(&ctx->stop_background_thread, memory_order_relaxed) == 0;
@@ -463,7 +463,7 @@ static void *BackgroundThread(void *arg) {
       if (last_flush + flags()->flush_memory_ms * kMs2Ns < now) {
         VPrintf(1, "ThreadSanitizer: periodic memory flush\n");
         FlushShadowMemory();
-        last_flush = NanoTime();
+        now = last_flush = NanoTime();
       }
     }
     if (flags()->memory_limit_mb > 0) {
@@ -476,6 +476,7 @@ static void *BackgroundThread(void *arg) {
         VPrintf(1, "ThreadSanitizer: flushing memory due to RSS\n");
         FlushShadowMemory();
         rss = GetRSS();
+        now = NanoTime();
         VPrintf(1, "ThreadSanitizer: memory flushed RSS=%llu\n", (u64)rss>>20);
       }
       last_rss = rss;


        


More information about the llvm-commits mailing list