From b660790427c52a8d11734e41bf73fcfd9d3fc81b Mon Sep 17 00:00:00 2001 From: mrsharm Date: Wed, 4 May 2022 16:53:20 -0700 Subject: [PATCH 1/3] Fixed the yp_spin_count_unit to be a factor of the original_spin_count_unit rather than a continually increasing value --- src/coreclr/gc/gc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index fdac7d2dd080fd..fbc4e9227d4e38 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)), @@ -44301,7 +44304,7 @@ 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); + yp_spin_count_unit = (int)((float)original_spin_count_unit * scalingFactor / (float)9); // It's very suspicious if it becomes 0 if (yp_spin_count_unit == 0) From 1631aa90c23825ee674be96fb63c332763e25ff5 Mon Sep 17 00:00:00 2001 From: mrsharm Date: Wed, 4 May 2022 19:03:57 -0700 Subject: [PATCH 2/3] Added upper bounds on the spin count --- src/coreclr/gc/gc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index fbc4e9227d4e38..25aedd7ab5efd9 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -44306,8 +44306,8 @@ void GCHeap::SetYieldProcessorScalingFactor (float scalingFactor) int saved_yp_spin_count_unit = yp_spin_count_unit; yp_spin_count_unit = (int)((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; } From c202f4a6933c4c28af2827366f9a384452c58849 Mon Sep 17 00:00:00 2001 From: mrsharm Date: Wed, 4 May 2022 22:07:57 -0700 Subject: [PATCH 3/3] Fixed the type of the unit spin counts --- src/coreclr/gc/gc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 25aedd7ab5efd9..5631645332aeef 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -44303,8 +44303,8 @@ 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)original_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 and also, we don't want to spin too much. if ((yp_spin_count_unit == 0) || (yp_spin_count_unit > 32768))