diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index fdac7d2dd080fd..5631645332aeef 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -92,6 +92,7 @@ BOOL bgc_heap_walk_for_etw_p = FALSE; #define UOH_ALLOCATION_RETRY_MAX_COUNT 2 uint32_t yp_spin_count_unit = 0; +uint32_t original_spin_count_unit = 0; size_t loh_size_threshold = LARGE_OBJECT_SIZE; #ifdef GC_CONFIG_DRIVEN @@ -13218,6 +13219,8 @@ HRESULT gc_heap::initialize_gc (size_t soh_segment_size, yp_spin_count_unit = 32 * g_num_processors; #endif //MULTIPLE_HEAPS + original_spin_count_unit = yp_spin_count_unit; + #if defined(__linux__) GCToEEInterface::UpdateGCEventStatus(static_cast(GCEventStatus::GetEnabledLevel(GCEventProvider_Default)), static_cast(GCEventStatus::GetEnabledKeywords(GCEventProvider_Default)), @@ -44300,11 +44303,11 @@ size_t GCHeap::GetPromotedBytes(int heap_index) void GCHeap::SetYieldProcessorScalingFactor (float scalingFactor) { assert (yp_spin_count_unit != 0); - int saved_yp_spin_count_unit = yp_spin_count_unit; - yp_spin_count_unit = (int)((float)yp_spin_count_unit * scalingFactor / (float)9); + 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 - if (yp_spin_count_unit == 0) + // 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)) { yp_spin_count_unit = saved_yp_spin_count_unit; }