Skip to content

Commit f5cb31c

Browse files
authored
[local gc] gc spinning part 1 (dotnet#17341)
Add an api so the VM can tell the GC how long to spin for to normalize across processor families.
1 parent c114224 commit f5cb31c

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

src/gc/gc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ extern "C" uint32_t g_num_processors;
138138

139139
extern VOLATILE(int32_t) g_fSuspensionPending;
140140

141+
extern uint32_t g_yieldProcessorScalingFactor;
142+
141143
::IGCHandleManager* CreateGCHandleManager();
142144

143145
namespace WKS {

src/gc/gccommon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ uint32_t* g_gc_card_table;
3737

3838
VOLATILE(int32_t) g_fSuspensionPending = 0;
3939

40+
uint32_t g_yieldProcessorScalingFactor = 1;
41+
4042
#ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES
4143
uint32_t* g_gc_card_bundle_table;
4244
#endif

src/gc/gcee.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ void GCHeap::SetSuspensionPending(bool fSuspensionPending)
615615
}
616616
}
617617

618+
void GCHeap::SetYieldProcessorScalingFactor(uint32_t yieldProcessorScalingFactor)
619+
{
620+
g_yieldProcessorScalingFactor = yieldProcessorScalingFactor;
621+
}
622+
618623
void GCHeap::ControlEvents(GCEventKeyword keyword, GCEventLevel level)
619624
{
620625
GCEventStatus::Set(GCEventProvider_Default, keyword, level);

src/gc/gcimpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class GCHeap : public IGCHeapInternal
9292
bool RuntimeStructuresValid();
9393

9494
void SetSuspensionPending(bool fSuspensionPending);
95+
96+
void SetYieldProcessorScalingFactor(uint32_t yieldProcessorScalingFactor);
9597

9698
void SetWaitForGCEvent();
9799
void ResetWaitForGCEvent();

src/gc/gcinterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ class IGCHeap {
735735
// Tells the GC when the VM is suspending threads.
736736
virtual void SetSuspensionPending(bool fSuspensionPending) = 0;
737737

738+
// Tells the GC how many YieldProcessor calls are equal to one scaled yield processor call.
739+
virtual void SetYieldProcessorScalingFactor(uint32_t yieldProcessorScalingFactor) = 0;
740+
738741
/*
739742
============================================================================
740743
Add/RemoveMemoryPressure support routines. These are on the interface

src/gc/gcpriv.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,3 +4346,13 @@ size_t gcard_of (uint8_t* object)
43464346
return (size_t)(object) / card_size;
43474347
}
43484348

4349+
inline
4350+
void YieldProcessorScalingFactor()
4351+
{
4352+
unsigned int n = g_yieldProcessorScalingFactor;
4353+
_ASSERTE(n != 0);
4354+
do
4355+
{
4356+
YieldProcessor();
4357+
} while (--n != 0);
4358+
}

src/vm/yieldprocessornormalized.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static void InitializeYieldProcessorNormalized()
9292
g_yieldsPerNormalizedYield = yieldsPerNormalizedYield;
9393
g_optimalMaxNormalizedYieldsPerSpinIteration = optimalMaxNormalizedYieldsPerSpinIteration;
9494
s_isYieldProcessorNormalizedInitialized = true;
95+
96+
97+
GCHeapUtilities::GetGCHeap()->SetYieldProcessorScalingFactor(yieldsPerNormalizedYield);
9598
}
9699

97100
void EnsureYieldProcessorNormalizedInitialized()

0 commit comments

Comments
 (0)