Skip to content

Commit 240a64d

Browse files
authored
Change profilers to use thread local evacuation counters (#59741)
* Change profilers to use thread local evacuation counters Change to prefix increment * get rid of lambdas * Fix jit inlining, fix R2R too * Remove VolatilePtr<> from helpers * Get rid of additionalData argument
1 parent 42a68e3 commit 240a64d

File tree

11 files changed

+922
-1003
lines changed

11 files changed

+922
-1003
lines changed

src/coreclr/inc/CrstTypes.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ End
381381
// between the thread executing DetachProfiler(), and the DetachThread
382382
// carrying out the evacuation order.
383383
Crst ProfilingAPIStatus
384+
AcquiredBefore ThreadStore
384385
End
385386

386387
Crst RCWCache
@@ -496,9 +497,8 @@ End
496497
Crst ThreadStore
497498
AcquiredBefore AvailableParamTypes DeadlockDetection DebuggerController
498499
DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
499-
JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
500-
ProfilerGCRefDataFreeList SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
501-
ThreadIdDispenser DebuggerMutex
500+
JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilerGCRefDataFreeList
501+
SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList ThreadIdDispenser DebuggerMutex
502502
End
503503

504504
Crst TypeIDMap

src/coreclr/inc/crsttypes.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//
22
// Licensed to the .NET Foundation under one or more agreements.
33
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for more information.
45
//
56

67
#ifndef __CRST_TYPES_INCLUDED
@@ -10,7 +11,7 @@
1011

1112
// This file describes the range of Crst types available and their mapping to a numeric level (used by the
1213
// runtime in debug mode to validate we're deadlock free). To modify these settings edit the
13-
// file:CrstTypes.def file and run the clr\artifacts\CrstTypeTool utility to generate a new version of this file.
14+
// file:CrstTypes.def file and run the clr\bin\CrstTypeTool utility to generate a new version of this file.
1415

1516
// Each Crst type is declared as a value in the following CrstType enum.
1617
enum CrstType
@@ -230,7 +231,7 @@ int g_rgCrstLevelMap[] =
230231
4, // CrstPgoData
231232
0, // CrstPinnedByrefValidation
232233
0, // CrstProfilerGCRefDataFreeList
233-
0, // CrstProfilingAPIStatus
234+
13, // CrstProfilingAPIStatus
234235
4, // CrstRCWCache
235236
0, // CrstRCWCleanupList
236237
10, // CrstReadyToRunEntryPointToMethodDescMap

src/coreclr/inc/profilepriv.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ class ProfilerInfo
109109

110110
EventMask eventMask;
111111

112-
//---------------------------------------------------------------
113-
// dwProfilerEvacuationCounter keeps track of how many profiler
114-
// callback calls remain on the stack
115-
//---------------------------------------------------------------
116-
// Why volatile?
117-
// See code:ProfilingAPIUtility::InitializeProfiling#LoadUnloadCallbackSynchronization.
118-
Volatile<DWORD> dwProfilerEvacuationCounter;
119-
120112
Volatile<BOOL> inUse;
121113

114+
DWORD slot;
115+
122116
// Reset those variables that is only for the current attach session
123117
void ResetPerSessionStatus();
124118
void Init();
@@ -150,19 +144,11 @@ class EvacuationCounterHolder
150144
{
151145
private:
152146
ProfilerInfo *m_pProfilerInfo;
147+
Thread *m_pThread;
153148

154149
public:
155-
EvacuationCounterHolder(ProfilerInfo *pProfilerInfo) :
156-
m_pProfilerInfo(pProfilerInfo)
157-
{
158-
_ASSERTE(m_pProfilerInfo != NULL);
159-
InterlockedIncrement((LONG *)(m_pProfilerInfo->dwProfilerEvacuationCounter.GetPointer()));
160-
}
161-
162-
~EvacuationCounterHolder()
163-
{
164-
InterlockedDecrement((LONG *)(m_pProfilerInfo->dwProfilerEvacuationCounter.GetPointer()));
165-
}
150+
EvacuationCounterHolder(ProfilerInfo *pProfilerInfo);
151+
~EvacuationCounterHolder();
166152
};
167153

168154
struct StoredProfilerNode
@@ -289,23 +275,26 @@ class ProfControlBlock
289275
BOOL IsMainProfiler(ProfToEEInterfaceImpl *pProfToEE);
290276
ProfilerInfo *GetProfilerInfo(ProfToEEInterfaceImpl *pProfToEE);
291277

292-
template<typename ConditionFunc, typename CallbackFunc, typename Data = void, typename... Args>
293-
FORCEINLINE HRESULT DoProfilerCallback(ProfilerCallbackType callbackType, ConditionFunc condition, Data *additionalData, CallbackFunc callback, Args... args)
278+
template<typename ConditionFunc, typename CallbackFunc, typename... Args>
279+
static void DoProfilerCallbackHelper(ProfilerInfo *pProfilerInfo, ConditionFunc condition, CallbackFunc callback, HRESULT *pHR, Args... args)
280+
{
281+
if (condition(pProfilerInfo))
282+
{
283+
HRESULT innerHR = callback(pProfilerInfo->pProfInterface, args...);
284+
if (FAILED(innerHR))
285+
{
286+
*pHR = innerHR;
287+
}
288+
}
289+
}
290+
291+
template<typename ConditionFunc, typename CallbackFunc, typename... Args>
292+
FORCEINLINE HRESULT DoProfilerCallback(ProfilerCallbackType callbackType, ConditionFunc condition, CallbackFunc callback, Args... args)
294293
{
295294
HRESULT hr = S_OK;
296295
IterateProfilers(callbackType,
297-
[](ProfilerInfo *pProfilerInfo, ConditionFunc condition, Data *additionalData, CallbackFunc callback, HRESULT *pHR, Args... args)
298-
{
299-
if (condition(pProfilerInfo))
300-
{
301-
HRESULT innerHR = callback(additionalData, pProfilerInfo->pProfInterface, args...);
302-
if (FAILED(innerHR))
303-
{
304-
*pHR = innerHR;
305-
}
306-
}
307-
},
308-
condition, additionalData, callback, &hr, args...);
296+
&DoProfilerCallbackHelper<ConditionFunc, CallbackFunc, Args...>,
297+
condition, callback, &hr, args...);
309298
return hr;
310299
}
311300

@@ -317,7 +306,6 @@ class ProfControlBlock
317306

318307
BOOL IsCallback3Supported();
319308
BOOL IsCallback5Supported();
320-
BOOL IsDisableTransparencySet();
321309
BOOL RequiresGenericsContextForEnterLeave();
322310
UINT_PTR EEFunctionIDMapper(FunctionID funcId, BOOL * pbHookFunction);
323311

0 commit comments

Comments
 (0)