Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ BOOL bgc_heap_walk_for_etw_p = FALSE;

#define UOH_ALLOCATION_RETRY_MAX_COUNT 2

#define MAX_YP_SPIN_COUNT_UNIT 32768

uint32_t yp_spin_count_unit = 0;
uint32_t original_spin_count_unit = 0;
size_t loh_size_threshold = LARGE_OBJECT_SIZE;
Expand Down Expand Up @@ -2288,6 +2290,7 @@ double gc_heap::short_plugs_pad_ratio = 0;

int gc_heap::generation_skip_ratio_threshold = 0;
int gc_heap::conserve_mem_setting = 0;
bool gc_heap::spin_count_unit_config_p = false;

uint64_t gc_heap::suspended_start_time = 0;
uint64_t gc_heap::end_gc_time = 0;
Expand Down Expand Up @@ -13839,6 +13842,15 @@ HRESULT gc_heap::initialize_gc (size_t soh_segment_size,
yp_spin_count_unit = 32 * g_num_processors;
#endif //MULTIPLE_HEAPS

// Check if the values are valid for the spin count if provided by the user
// and if they are, set them as the yp_spin_count_unit and then ignore any updates made in SetYieldProcessorScalingFactor.
int64_t spin_count_unit_from_config = GCConfig::GetGCSpinCountUnit();
gc_heap::spin_count_unit_config_p = (spin_count_unit_from_config > 0) && (spin_count_unit_from_config <= MAX_YP_SPIN_COUNT_UNIT);
if (gc_heap::spin_count_unit_config_p)
{
yp_spin_count_unit = static_cast<int32_t>(spin_count_unit_from_config);
}

original_spin_count_unit = yp_spin_count_unit;

#if defined(__linux__)
Expand Down Expand Up @@ -45860,14 +45872,17 @@ size_t GCHeap::GetPromotedBytes(int heap_index)

void GCHeap::SetYieldProcessorScalingFactor (float scalingFactor)
{
assert (yp_spin_count_unit != 0);
uint32_t saved_yp_spin_count_unit = yp_spin_count_unit;
yp_spin_count_unit = (uint32_t)((float)original_spin_count_unit * scalingFactor / (float)9);

// It's very suspicious if it becomes 0 and also, we don't want to spin too much.
if ((yp_spin_count_unit == 0) || (yp_spin_count_unit > 32768))
if (!gc_heap::spin_count_unit_config_p)
{
yp_spin_count_unit = saved_yp_spin_count_unit;
assert (yp_spin_count_unit != 0);
uint32_t saved_yp_spin_count_unit = yp_spin_count_unit;
yp_spin_count_unit = (uint32_t)((float)original_spin_count_unit * scalingFactor / (float)9);

// It's very suspicious if it becomes 0 and also, we don't want to spin too much.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's suspicious should it assert (yp_spin_count_unit != 0); again here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense to assert once more. Will work on adding an additional protective assert.

if ((yp_spin_count_unit == 0) || (yp_spin_count_unit > MAX_YP_SPIN_COUNT_UNIT))
{
yp_spin_count_unit = saved_yp_spin_count_unit;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/gc/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class GCConfigStringHolder
INT_CONFIG (GCEnabledInstructionSets, "GCEnabledInstructionSets", NULL, -1, "Specifies whether GC can use AVX2 or AVX512F - 0 for neither, 1 for AVX2, 3 for AVX512F")\
INT_CONFIG (GCConserveMem, "GCConserveMemory", "System.GC.ConserveMemory", 0, "Specifies how hard GC should try to conserve memory - values 0-9") \
INT_CONFIG (GCWriteBarrier, "GCWriteBarrier", NULL, 0, "Specifies whether GC should use more precise but slower write barrier") \
STRING_CONFIG(GCName, "GCName", "System.GC.Name", "Specifies the path of the standalone GC implementation.")
STRING_CONFIG(GCName, "GCName", "System.GC.Name", "Specifies the path of the standalone GC implementation.") \
INT_CONFIG (GCSpinCountUnit, "GCSpinCountUnit", 0, 0, "Specifies the spin count unit used by the GC.")
// This class is responsible for retreiving configuration information
// for how the GC should operate.
class GCConfig
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,8 @@ class gc_heap
PER_HEAP_ISOLATED_FIELD_INIT_ONLY int generation_skip_ratio_threshold;
PER_HEAP_ISOLATED_FIELD_INIT_ONLY int conserve_mem_setting;

PER_HEAP_ISOLATED_FIELD_INIT_ONLY bool spin_count_unit_config_p;

// For SOH we always allocate segments of the same
// size unless no_gc_region requires larger ones.
PER_HEAP_ISOLATED_FIELD_INIT_ONLY size_t soh_segment_size;
Expand Down