Skip to content

Commit

Permalink
Do YieldProcessor normalization in preemptive GC mode (#45913)
Browse files Browse the repository at this point in the history
- The YieldProcessor normalization takes ~10 ms. In the finalizer thread start function, `Thread::HasStarted()` puts the thread into cooperative GC mode. Switch to preemptive GC mode for the normalization.

Fixes #42515
kouvel authored Dec 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 56ecd32 commit 6e33437
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/coreclr/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
@@ -370,7 +370,10 @@ DWORD WINAPI FinalizerThread::FinalizerThreadStart(void *args)
{
GetFinalizerThread()->SetBackground(TRUE);

EnsureYieldProcessorNormalizedInitialized();
{
GCX_PREEMP();
EnsureYieldProcessorNormalizedInitialized();
}

while (!fQuitFinalizer)
{
16 changes: 14 additions & 2 deletions src/coreclr/vm/yieldprocessornormalized.cpp
Original file line number Diff line number Diff line change
@@ -14,7 +14,13 @@ void InitializeYieldProcessorNormalizedCrst()

static void InitializeYieldProcessorNormalized()
{
WRAPPER_NO_CONTRACT;
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_PREEMPTIVE;
}
CONTRACTL_END;

CrstHolder lock(&s_initializeYieldProcessorNormalizedCrst);

@@ -92,7 +98,13 @@ static void InitializeYieldProcessorNormalized()

void EnsureYieldProcessorNormalizedInitialized()
{
WRAPPER_NO_CONTRACT;
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (!s_isYieldProcessorNormalizedInitialized)
{

0 comments on commit 6e33437

Please sign in to comment.