Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add back contention history, ETW events, and logging in the wait path
Browse files Browse the repository at this point in the history
  • Loading branch information
kouvel committed Oct 6, 2017
1 parent 2e48f9d commit 4bb7a6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion src/vm/syncblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,28 @@ BOOL AwareLock::EnterEpilog(Thread* pCurThread, INT32 timeOut)
return EnterEpilogHelper(pCurThread, timeOut);
}

#ifdef _DEBUG
#define _LOGCONTENTION
#endif // _DEBUG

#ifdef _LOGCONTENTION
inline void LogContention()
{
WRAPPER_NO_CONTRACT;
#ifdef LOGGING
if (LoggingOn(LF_SYNC, LL_INFO100))
{
LogSpewAlways("Contention: Stack Trace Begin\n");
void LogStackTrace();
LogStackTrace();
LogSpewAlways("Contention: Stack Trace End\n");
}
#endif
}
#else
#define LogContention()
#endif

BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)
{
STATIC_CONTRACT_THROWS;
Expand All @@ -3080,6 +3102,13 @@ BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)
// the object associated with this lock.
_ASSERTE(pCurThread->PreemptiveGCDisabled());

COUNTER_ONLY(GetPerfCounters().m_LocksAndThreads.cContention++);

// Fire a contention start event for a managed contention
FireEtwContentionStart_V1(ETW::ContentionLog::ContentionStructs::ManagedContention, GetClrInstanceId());

LogContention();

OBJECTREF obj = GetOwningObject();

// We cannot allow the AwareLock to be cleaned up underneath us by the GC.
Expand Down Expand Up @@ -3223,6 +3252,9 @@ BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)
GCPROTECT_END();
DecrementTransientPrecious();

// Fire a contention end event for a managed contention
FireEtwContentionStop(ETW::ContentionLog::ContentionStructs::ManagedContention, GetClrInstanceId());

if (ret == WAIT_TIMEOUT)
{
return false;
Expand Down Expand Up @@ -3273,7 +3305,6 @@ BOOL AwareLock::Leave()
}
}


LONG AwareLock::LeaveCompletely()
{
WRAPPER_NO_CONTRACT;
Expand Down
2 changes: 1 addition & 1 deletion src/vm/syncblk.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class AwareLock
}

private:
bool IncrementSpinnerCount()
bool TryIncrementSpinnerCount()
{
WRAPPER_NO_CONTRACT;

Expand Down
2 changes: 1 addition & 1 deletion src/vm/syncblk.inl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FORCEINLINE AwareLock::EnterHelperResult AwareLock::LockState::InterlockedTry_Lo
{
newState.InvertIsLocked();
}
else if (!newState.IncrementSpinnerCount())
else if (!newState.TryIncrementSpinnerCount())
{
return EnterHelperResult_UseSlowPath;
}
Expand Down

0 comments on commit 4bb7a6f

Please sign in to comment.