[compiler-rt] r312992 - [XRay][compiler-rt] Use a single global volatile recursion guard for FDR handlers

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 18:37:59 PDT 2017


Author: dberris
Date: Mon Sep 11 18:37:59 2017
New Revision: 312992

URL: http://llvm.org/viewvc/llvm-project?rev=312992&view=rev
Log:
[XRay][compiler-rt] Use a single global volatile recursion guard for FDR handlers

Summary:
Before this change, the recursion guard for the flight data recorder
(FDR) mode handlers were independent. This change makes it so that when
a handler is already in the process of running and somehow the same or
another handler starts running -- say in a signal handler, while the
XRay handler is executing -- then we can use the same thread-local
recursion guard to stop the second handler from running.

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

Modified:
    compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
    compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h

Modified: compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_logging.cc?rev=312992&r1=312991&r2=312992&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_logging.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging.cc Mon Sep 11 18:37:59 2017
@@ -42,7 +42,7 @@ namespace __xray {
 // NOTE: This is a pointer to avoid having to do atomic operations at
 // initialization time. This is OK to leak as there will only be one bufferqueue
 // for the runtime, initialized once through the fdrInit(...) sequence.
-std::shared_ptr<BufferQueue>* BQ = nullptr;
+std::shared_ptr<BufferQueue> *BQ = nullptr;
 
 __sanitizer::atomic_sint32_t LogFlushStatus = {
     XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING};
@@ -207,7 +207,6 @@ void fdrLoggingHandleCustomEvent(void *E
   auto TSC_CPU = getTimestamp();
   auto &TSC = std::get<0>(TSC_CPU);
   auto &CPU = std::get<1>(TSC_CPU);
-  thread_local bool Running = false;
   RecursionGuard Guard{Running};
   if (!Guard) {
     assert(Running && "RecursionGuard is buggy!");
@@ -298,7 +297,9 @@ static auto UNUSED Unused = [] {
   using namespace __xray;
   if (flags()->xray_fdr_log) {
     XRayLogImpl Impl{
-        fdrLoggingInit, fdrLoggingFinalize, fdrLoggingHandleArg0,
+        fdrLoggingInit,
+        fdrLoggingFinalize,
+        fdrLoggingHandleArg0,
         fdrLoggingFlush,
     };
     __xray_set_log_impl(Impl);

Modified: compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h?rev=312992&r1=312991&r2=312992&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h (original)
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h Mon Sep 11 18:37:59 2017
@@ -571,6 +571,8 @@ inline void endBufferIfFull() XRAY_NEVER
   }
 }
 
+thread_local volatile bool Running = false;
+
 inline void processFunctionHook(
     int32_t FuncId, XRayEntryType Entry, uint64_t TSC, unsigned char CPU,
     int (*wall_clock_reader)(clockid_t, struct timespec *),
@@ -581,7 +583,6 @@ inline void processFunctionHook(
   // don't want to be clobbering potentially partial writes already happening in
   // the thread. We use a simple thread_local latch to only allow one on-going
   // handleArg0 to happen at any given time.
-  thread_local volatile bool Running = false;
   RecursionGuard Guard{Running};
   if (!Guard) {
     assert(Running == true && "RecursionGuard is buggy!");




More information about the llvm-commits mailing list