From 48e5d4a2d3a53a189fd97715e75f22ce34684282 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 21 Mar 2013 07:02:36 +0000 Subject: [PATCH] tsan: flush symbolizer cache if not symbolized for more than 5 seconds llvm-svn: 177629 --- compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 21 +++++++++++++++++---- compiler-rt/lib/tsan/rtl/tsan_rtl.h | 1 + compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index b39b836..7c73289 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -23,6 +23,7 @@ #include "tsan_rtl.h" #include "tsan_mman.h" #include "tsan_suppressions.h" +#include "tsan_symbolize.h" volatile int __tsan_resumed = 0; @@ -95,12 +96,11 @@ ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch, , tls_size(tls_size) { } -static void MemoryProfiler(int i, fd_t fd) { - Context *ctx = CTX(); - InternalScopedBuffer buf(4096); +static void MemoryProfiler(Context *ctx, fd_t fd, int i) { uptr n_threads; uptr n_running_threads; ctx->thread_registry->GetNumberOfThreads(&n_threads, &n_running_threads); + InternalScopedBuffer buf(4096); internal_snprintf(buf.data(), buf.size(), "%d: nthr=%d nlive=%d\n", i, n_threads, n_running_threads); internal_write(fd, buf.data(), internal_strlen(buf.data())); @@ -110,6 +110,7 @@ static void MemoryProfiler(int i, fd_t fd) { static void BackgroundThread(void *arg) { ScopedInRtl in_rtl; + Context *ctx = CTX(); fd_t mprof_fd = kInvalidFd; if (flags()->profile_memory && flags()->profile_memory[0]) { @@ -128,6 +129,7 @@ static void BackgroundThread(void *arg) { SleepForSeconds(1); u64 now = NanoTime(); + // Flush memory if requested. if (flags()->flush_memory_ms) { if (last_flush + flags()->flush_memory_ms * 1000*1000 > now) { FlushShadowMemory(); @@ -135,8 +137,19 @@ static void BackgroundThread(void *arg) { } } + // Write memory profile if requested. if (mprof_fd != kInvalidFd) - MemoryProfiler(i, mprof_fd); + MemoryProfiler(ctx, mprof_fd, i); + +#ifndef TSAN_GO + // Flush symbolizer cache if not symbolized for more than 5 seconds. + u64 last = atomic_load(&ctx->last_symbolize_time_ns, memory_order_relaxed); + if (last != 0 && last + 5*1000*1000 > now) { + Lock l(&ctx->report_mtx); + SymbolizeFlush(); + atomic_store(&ctx->last_symbolize_time_ns, 0, memory_order_relaxed); + } +#endif } } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index 2b9aaf4..e57fcc7 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -516,6 +516,7 @@ struct Context { Mutex report_mtx; int nreported; int nmissed_expected; + atomic_uint64_t last_symbolize_time_ns; ThreadRegistry *thread_registry; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index b343ff3..18ab18e 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -495,6 +495,7 @@ bool OutputReport(Context *ctx, const ScopedReport &srep, const ReportStack *suppress_stack1, const ReportStack *suppress_stack2) { + atomic_store(&ctx->last_symbolize_time_ns, NanoTime(), memory_order_relaxed); const ReportDesc *rep = srep.GetReport(); uptr suppress_pc = IsSuppressed(rep->typ, suppress_stack1); if (suppress_pc == 0) -- 2.7.4