[compiler-rt] r345489 - [XRay] Guard call to postCurrentThreadFCT()
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 28 22:39:43 PDT 2018
Author: dberris
Date: Sun Oct 28 22:39:43 2018
New Revision: 345489
URL: http://llvm.org/viewvc/llvm-project?rev=345489&view=rev
Log:
[XRay] Guard call to postCurrentThreadFCT()
Summary:
Some cases where `postCurrentThreadFCT()` are not guarded by our
recursion guard. We've observed that sometimes these can lead to
deadlocks when some functions (like memcpy()) gets outlined and the
version of memcpy is XRay-instrumented, which can be materialised by the
compiler in the implementation of lower-level components used by the
profiling runtime.
This change ensures that all calls to `postCurrentThreadFCT` are guarded
by our thread-recursion guard, to prevent deadlocks.
Reviewers: mboerger, eizan
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53805
Modified:
compiler-rt/trunk/lib/xray/xray_profiling.cc
Modified: compiler-rt/trunk/lib/xray/xray_profiling.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_profiling.cc?rev=345489&r1=345488&r2=345489&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_profiling.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_profiling.cc Sun Oct 28 22:39:43 2018
@@ -133,7 +133,7 @@ XRayLogFlushStatus profilingFlush() XRAY
if (Verbosity())
Report("profiling: No data to flush.\n");
} else {
- LogWriter* LW = LogWriter::Open();
+ LogWriter *LW = LogWriter::Open();
if (LW == nullptr) {
if (Verbosity())
Report("profiling: Failed to flush to file, dropping data.\n");
@@ -227,10 +227,15 @@ XRayLogInitStatus profilingFinalize() XR
// Wait a grace period to allow threads to see that we're finalizing.
SleepForMillis(profilingFlags()->grace_period_ms);
- // We also want to make sure that the current thread's data is cleaned up,
- // if we have any.
+ // We also want to make sure that the current thread's data is cleaned up, if
+ // we have any. We need to ensure that the call to postCurrentThreadFCT() is
+ // guarded by our recursion guard.
auto &TLD = getThreadLocalData();
- postCurrentThreadFCT(TLD);
+ {
+ RecursionGuard G(ReentranceGuard);
+ if (G)
+ postCurrentThreadFCT(TLD);
+ }
// Then we force serialize the log data.
profileCollectorService::serialize();
@@ -284,7 +289,13 @@ profilingLoggingInit(UNUSED size_t Buffe
if (TLD.Allocators == nullptr && TLD.FCT == nullptr)
return;
- postCurrentThreadFCT(TLD);
+ {
+ // If we're somehow executing this while inside a non-reentrant-friendly
+ // context, we skip attempting to post the current thread's data.
+ RecursionGuard G(ReentranceGuard);
+ if (G)
+ postCurrentThreadFCT(TLD);
+ }
});
// We also need to set up an exit handler, so that we can get the profile
More information about the llvm-commits
mailing list