Skip to content

Commit 3a80b29

Browse files
authored
Added the ability to specify a Spin Count Unit via a GC Configuration to release/7.0 (#84495)
* Ported over changes from PR: 84339 to release/7.0 * used the MAX_YP_SPIN_COUNT_UNIT variable instead of the hardcoded value
1 parent 06e5b35 commit 3a80b29

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BOOL bgc_heap_walk_for_etw_p = FALSE;
9191

9292
#define UOH_ALLOCATION_RETRY_MAX_COUNT 2
9393

94+
#define MAX_YP_SPIN_COUNT_UNIT 32768
95+
9496
uint32_t yp_spin_count_unit = 0;
9597
uint32_t original_spin_count_unit = 0;
9698
size_t loh_size_threshold = LARGE_OBJECT_SIZE;
@@ -2287,6 +2289,7 @@ double gc_heap::short_plugs_pad_ratio = 0;
22872289

22882290
int gc_heap::generation_skip_ratio_threshold = 0;
22892291
int gc_heap::conserve_mem_setting = 0;
2292+
bool gc_heap::spin_count_unit_config_p = false;
22902293

22912294
uint64_t gc_heap::suspended_start_time = 0;
22922295
uint64_t gc_heap::end_gc_time = 0;
@@ -13744,6 +13747,14 @@ HRESULT gc_heap::initialize_gc (size_t soh_segment_size,
1374413747
yp_spin_count_unit = 32 * g_num_processors;
1374513748
#endif //MULTIPLE_HEAPS
1374613749

13750+
// Check if the values are valid for the spin count if provided by the user
13751+
// and if they are, set them as the yp_spin_count_unit and then ignore any updates made in SetYieldProcessorScalingFactor.
13752+
uint32_t spin_count_unit_from_config = (uint32_t)GCConfig::GetGCSpinCountUnit();
13753+
gc_heap::spin_count_unit_config_p = (spin_count_unit_from_config > 0) && (spin_count_unit_from_config <= MAX_YP_SPIN_COUNT_UNIT);
13754+
if (gc_heap::spin_count_unit_config_p)
13755+
{
13756+
yp_spin_count_unit = spin_count_unit_from_config;
13757+
}
1374713758
original_spin_count_unit = yp_spin_count_unit;
1374813759

1374913760
#if defined(__linux__)
@@ -45628,14 +45639,17 @@ size_t GCHeap::GetPromotedBytes(int heap_index)
4562845639

4562945640
void GCHeap::SetYieldProcessorScalingFactor (float scalingFactor)
4563045641
{
45631-
assert (yp_spin_count_unit != 0);
45632-
uint32_t saved_yp_spin_count_unit = yp_spin_count_unit;
45633-
yp_spin_count_unit = (uint32_t)((float)original_spin_count_unit * scalingFactor / (float)9);
45634-
45635-
// It's very suspicious if it becomes 0 and also, we don't want to spin too much.
45636-
if ((yp_spin_count_unit == 0) || (yp_spin_count_unit > 32768))
45642+
if (!gc_heap::spin_count_unit_config_p)
4563745643
{
45638-
yp_spin_count_unit = saved_yp_spin_count_unit;
45644+
assert (yp_spin_count_unit != 0);
45645+
uint32_t saved_yp_spin_count_unit = yp_spin_count_unit;
45646+
yp_spin_count_unit = (uint32_t)((float)original_spin_count_unit * scalingFactor / (float)9);
45647+
45648+
// It's very suspicious if it becomes 0 and also, we don't want to spin too much.
45649+
if ((yp_spin_count_unit == 0) || (yp_spin_count_unit > MAX_YP_SPIN_COUNT_UNIT))
45650+
{
45651+
yp_spin_count_unit = saved_yp_spin_count_unit;
45652+
}
4563945653
}
4564045654
}
4564145655

src/coreclr/gc/gcconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class GCConfigStringHolder
136136
INT_CONFIG (GCEnabledInstructionSets, "GCEnabledInstructionSets", NULL, -1, "Specifies whether GC can use AVX2 or AVX512F - 0 for neither, 1 for AVX2, 3 for AVX512F")\
137137
INT_CONFIG (GCConserveMem, "GCConserveMemory", "System.GC.ConserveMemory", 0, "Specifies how hard GC should try to conserve memory - values 0-9") \
138138
INT_CONFIG (GCWriteBarrier, "GCWriteBarrier", NULL, 0, "Specifies whether GC should use more precise but slower write barrier") \
139-
STRING_CONFIG(GCName, "GCName", "System.GC.Name", "Specifies the path of the standalone GC implementation.")
139+
STRING_CONFIG(GCName, "GCName", "System.GC.Name", "Specifies the path of the standalone GC implementation.") \
140+
INT_CONFIG (GCSpinCountUnit, "GCSpinCountUnit", NULL, 0, "Specifies the spin count unit used by the GC.")
141+
140142
// This class is responsible for retreiving configuration information
141143
// for how the GC should operate.
142144
class GCConfig

src/coreclr/gc/gcpriv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,6 +4859,9 @@ class gc_heap
48594859
PER_HEAP_ISOLATED
48604860
int conserve_mem_setting;
48614861

4862+
PER_HEAP_ISOLATED
4863+
bool spin_count_unit_config_p;
4864+
48624865
PER_HEAP
48634866
BOOL gen0_bricks_cleared;
48644867
PER_HEAP

0 commit comments

Comments
 (0)