Skip to content

Commit

Permalink
Change profilers to use thread local evacuation counters (#59741)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
davmason committed Oct 7, 2021
1 parent 42a68e3 commit 240a64d
Show file tree
Hide file tree
Showing 11 changed files with 922 additions and 1,003 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/inc/CrstTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ End
// between the thread executing DetachProfiler(), and the DetachThread
// carrying out the evacuation order.
Crst ProfilingAPIStatus
AcquiredBefore ThreadStore
End

Crst RCWCache
Expand Down Expand Up @@ -496,9 +497,8 @@ End
Crst ThreadStore
AcquiredBefore AvailableParamTypes DeadlockDetection DebuggerController
DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
ProfilerGCRefDataFreeList SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
ThreadIdDispenser DebuggerMutex
JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilerGCRefDataFreeList
SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList ThreadIdDispenser DebuggerMutex
End

Crst TypeIDMap
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/inc/crsttypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//

#ifndef __CRST_TYPES_INCLUDED
Expand All @@ -10,7 +11,7 @@

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

// Each Crst type is declared as a value in the following CrstType enum.
enum CrstType
Expand Down Expand Up @@ -230,7 +231,7 @@ int g_rgCrstLevelMap[] =
4, // CrstPgoData
0, // CrstPinnedByrefValidation
0, // CrstProfilerGCRefDataFreeList
0, // CrstProfilingAPIStatus
13, // CrstProfilingAPIStatus
4, // CrstRCWCache
0, // CrstRCWCleanupList
10, // CrstReadyToRunEntryPointToMethodDescMap
Expand Down
56 changes: 22 additions & 34 deletions src/coreclr/inc/profilepriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,10 @@ class ProfilerInfo

EventMask eventMask;

//---------------------------------------------------------------
// dwProfilerEvacuationCounter keeps track of how many profiler
// callback calls remain on the stack
//---------------------------------------------------------------
// Why volatile?
// See code:ProfilingAPIUtility::InitializeProfiling#LoadUnloadCallbackSynchronization.
Volatile<DWORD> dwProfilerEvacuationCounter;

Volatile<BOOL> inUse;

DWORD slot;

// Reset those variables that is only for the current attach session
void ResetPerSessionStatus();
void Init();
Expand Down Expand Up @@ -150,19 +144,11 @@ class EvacuationCounterHolder
{
private:
ProfilerInfo *m_pProfilerInfo;
Thread *m_pThread;

public:
EvacuationCounterHolder(ProfilerInfo *pProfilerInfo) :
m_pProfilerInfo(pProfilerInfo)
{
_ASSERTE(m_pProfilerInfo != NULL);
InterlockedIncrement((LONG *)(m_pProfilerInfo->dwProfilerEvacuationCounter.GetPointer()));
}

~EvacuationCounterHolder()
{
InterlockedDecrement((LONG *)(m_pProfilerInfo->dwProfilerEvacuationCounter.GetPointer()));
}
EvacuationCounterHolder(ProfilerInfo *pProfilerInfo);
~EvacuationCounterHolder();
};

struct StoredProfilerNode
Expand Down Expand Up @@ -289,23 +275,26 @@ class ProfControlBlock
BOOL IsMainProfiler(ProfToEEInterfaceImpl *pProfToEE);
ProfilerInfo *GetProfilerInfo(ProfToEEInterfaceImpl *pProfToEE);

template<typename ConditionFunc, typename CallbackFunc, typename Data = void, typename... Args>
FORCEINLINE HRESULT DoProfilerCallback(ProfilerCallbackType callbackType, ConditionFunc condition, Data *additionalData, CallbackFunc callback, Args... args)
template<typename ConditionFunc, typename CallbackFunc, typename... Args>
static void DoProfilerCallbackHelper(ProfilerInfo *pProfilerInfo, ConditionFunc condition, CallbackFunc callback, HRESULT *pHR, Args... args)
{
if (condition(pProfilerInfo))
{
HRESULT innerHR = callback(pProfilerInfo->pProfInterface, args...);
if (FAILED(innerHR))
{
*pHR = innerHR;
}
}
}

template<typename ConditionFunc, typename CallbackFunc, typename... Args>
FORCEINLINE HRESULT DoProfilerCallback(ProfilerCallbackType callbackType, ConditionFunc condition, CallbackFunc callback, Args... args)
{
HRESULT hr = S_OK;
IterateProfilers(callbackType,
[](ProfilerInfo *pProfilerInfo, ConditionFunc condition, Data *additionalData, CallbackFunc callback, HRESULT *pHR, Args... args)
{
if (condition(pProfilerInfo))
{
HRESULT innerHR = callback(additionalData, pProfilerInfo->pProfInterface, args...);
if (FAILED(innerHR))
{
*pHR = innerHR;
}
}
},
condition, additionalData, callback, &hr, args...);
&DoProfilerCallbackHelper<ConditionFunc, CallbackFunc, Args...>,
condition, callback, &hr, args...);
return hr;
}

Expand All @@ -317,7 +306,6 @@ class ProfControlBlock

BOOL IsCallback3Supported();
BOOL IsCallback5Supported();
BOOL IsDisableTransparencySet();
BOOL RequiresGenericsContextForEnterLeave();
UINT_PTR EEFunctionIDMapper(FunctionID funcId, BOOL * pbHookFunction);

Expand Down
Loading

0 comments on commit 240a64d

Please sign in to comment.