[release/6.0] Fixed the yp_spin_count_unit to be a factor of the original_spin_count_unit rather than a continually increasing value #68881
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #68879 to release/6.0.
Customer Impact
Reported by Cosmos; the associated bug can be found here: #68839
Details
This PR is to address #68839 where it's clear that
SetYieldProcessorScalingFactor
is called multiple times thereby increasing the value ofyp_spin_count_unit
and as a result the spin counts are monotonically increasing each timeSetYieldProcessorScalingFactor
is called; this function was previously assumed to be called only once but that changed with the following PR: #55295.The fix is to store the original spin count unit and use that value to set the
yp_spin_count_unit
rather than adjusting the value based on the lastyp_spin_count_unit
.Testing
Tested on a simple console app that has Server GC enabled and made sure the spin lock count is constrained. The repro code as a simple console app is:
Thread.SpinWait
eventually callsSetYieldProcessorScalingFactor
; the result of the testing indicated that theyp_spin_count
wasn't monotonically increasing like before.Risk
This PR mitigates a high-risk issue and reduces the risk of the spin count growing by constraining max count.