Skip to content

Commit

Permalink
Fixed the yp_spin_count_unit to be a factor of the original_spin_coun…
Browse files Browse the repository at this point in the history
…t_unit rather than a continually increasing value (#68879)

* Fixed the yp_spin_count_unit to be a factor of the original_spin_count_unit rather than a continually increasing value

* Added upper bounds on the spin count

* Fixed the type of the unit spin counts
  • Loading branch information
mrsharm committed May 5, 2022
1 parent 874c6a9 commit 6ca8c9b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(GCEventStatus::GetEnabledLevel(GCEventProvider_Default)),
static_cast<int>(GCEventStatus::GetEnabledKeywords(GCEventProvider_Default)),
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6ca8c9b

Please sign in to comment.