[PATCH] D51278: [XRay][compiler-rt] Remove uses of internal allocator in profiling mode
Dean Michael Berris via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 28 03:42:34 PDT 2018
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340814: [XRay][compiler-rt] Remove uses of internal allocator in profiling mode (authored by dberris, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D51278?vs=162609&id=162821#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51278
Files:
compiler-rt/trunk/lib/xray/xray_profiling.cc
Index: compiler-rt/trunk/lib/xray/xray_profiling.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_profiling.cc
+++ compiler-rt/trunk/lib/xray/xray_profiling.cc
@@ -40,51 +40,56 @@
SpinMutex ProfilerOptionsMutex;
struct alignas(64) ProfilingData {
- FunctionCallTrie::Allocators *Allocators = nullptr;
- FunctionCallTrie *FCT = nullptr;
+ FunctionCallTrie::Allocators *Allocators;
+ FunctionCallTrie *FCT;
};
static pthread_key_t ProfilingKey;
+thread_local std::aligned_storage<sizeof(FunctionCallTrie::Allocators)>::type
+ AllocatorsStorage;
+thread_local std::aligned_storage<sizeof(FunctionCallTrie)>::type
+ FunctionCallTrieStorage;
thread_local std::aligned_storage<sizeof(ProfilingData)>::type ThreadStorage{};
+
static ProfilingData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {
thread_local auto ThreadOnce = [] {
new (&ThreadStorage) ProfilingData{};
+ auto *Allocators =
+ reinterpret_cast<FunctionCallTrie::Allocators *>(&AllocatorsStorage);
+ new (Allocators) FunctionCallTrie::Allocators();
+ *Allocators = FunctionCallTrie::InitAllocators();
+ auto *FCT = reinterpret_cast<FunctionCallTrie *>(&FunctionCallTrieStorage);
+ new (FCT) FunctionCallTrie(*Allocators);
+ auto &TLD = *reinterpret_cast<ProfilingData *>(&ThreadStorage);
+ TLD.Allocators = Allocators;
+ TLD.FCT = FCT;
pthread_setspecific(ProfilingKey, &ThreadStorage);
return false;
}();
(void)ThreadOnce;
- auto &TLD = *reinterpret_cast<ProfilingData *>(&ThreadStorage);
+ auto &TLD = *reinterpret_cast<ProfilingData*>(&ThreadStorage);
- // We need to check whether the global flag to finalizing/finalized has been
- // switched. If it is, then we ought to not actually initialise the data.
- auto Status = atomic_load(&ProfilerLogStatus, memory_order_acquire);
- if (Status == XRayLogInitStatus::XRAY_LOG_FINALIZING ||
- Status == XRayLogInitStatus::XRAY_LOG_FINALIZED)
- return TLD;
-
- // If we're live, then we re-initialize TLD if the pointers are not null.
- if (UNLIKELY(TLD.Allocators == nullptr && TLD.FCT == nullptr)) {
- TLD.Allocators = reinterpret_cast<FunctionCallTrie::Allocators *>(
- InternalAlloc(sizeof(FunctionCallTrie::Allocators)));
- new (TLD.Allocators) FunctionCallTrie::Allocators();
- *TLD.Allocators = FunctionCallTrie::InitAllocators();
- TLD.FCT = reinterpret_cast<FunctionCallTrie *>(
- InternalAlloc(sizeof(FunctionCallTrie)));
- new (TLD.FCT) FunctionCallTrie(*TLD.Allocators);
+ if (UNLIKELY(TLD.Allocators == nullptr || TLD.FCT == nullptr)) {
+ auto *Allocators =
+ reinterpret_cast<FunctionCallTrie::Allocators *>(&AllocatorsStorage);
+ new (Allocators) FunctionCallTrie::Allocators();
+ *Allocators = FunctionCallTrie::InitAllocators();
+ auto *FCT = reinterpret_cast<FunctionCallTrie *>(&FunctionCallTrieStorage);
+ new (FCT) FunctionCallTrie(*Allocators);
+ TLD.Allocators = Allocators;
+ TLD.FCT = FCT;
}
- return TLD;
+ return *reinterpret_cast<ProfilingData *>(&ThreadStorage);
}
static void cleanupTLD() XRAY_NEVER_INSTRUMENT {
auto &TLD = *reinterpret_cast<ProfilingData *>(&ThreadStorage);
if (TLD.Allocators != nullptr && TLD.FCT != nullptr) {
TLD.FCT->~FunctionCallTrie();
TLD.Allocators->~Allocators();
- InternalFree(TLD.FCT);
- InternalFree(TLD.Allocators);
TLD.FCT = nullptr;
TLD.Allocators = nullptr;
}
@@ -181,13 +186,14 @@
return;
auto Status = atomic_load(&ProfilerLogStatus, memory_order_acquire);
- auto &TLD = getThreadLocalData();
if (UNLIKELY(Status == XRayLogInitStatus::XRAY_LOG_FINALIZED ||
Status == XRayLogInitStatus::XRAY_LOG_FINALIZING)) {
+ auto &TLD = getThreadLocalData();
postCurrentThreadFCT(TLD);
return;
}
+ auto &TLD = getThreadLocalData();
switch (Entry) {
case XRayEntryType::ENTRY:
case XRayEntryType::LOG_ARGS_ENTRY:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51278.162821.patch
Type: text/x-patch
Size: 3987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180828/7594b449/attachment-0001.bin>
More information about the llvm-commits
mailing list