Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0caee95

Browse files
kouvelKoundinya Veluri
authored andcommitted
Don't multiply YieldProcessor count by proc count (#13556)
Port of #13556 to release/2.0.0 Related to issue mentioned in https://github.com/dotnet/coreclr/issues/13388 Fixes https://github.com/dotnet/coreclr/issues/13630 - Multipying the YieldProcessor count by proc count can cause excessive delays that are not fruitful on machines with a large number of procs. Even on a 12-proc machine (6-core), the heuristics as they are without the multiply seem to perform much better. - The issue above also mentions that the delay of PAUSE on Intel Skylake+ processors have a significantly larger delay (140 cycles vs 10 cycles). Simulating that by multiplying the YieldProcessor count by 14 shows that in both tests tested, it begins crawling at low thread counts. - I did most of the testing on ManualResetEventSlim, and since Task is using the same spin heuristics, applied the same change there as well.
1 parent 089fe7b commit 0caee95

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/mscorlib/src/System/Threading/ManualResetEventSlim.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
584584
}
585585
else
586586
{
587-
Thread.SpinWait(PlatformHelper.ProcessorCount * (4 << i));
587+
Thread.SpinWait(4 << i);
588588
}
589589
}
590590
else if (i % HOW_MANY_YIELD_EVERY_SLEEP_1 == 0)

src/mscorlib/src/System/Threading/Tasks/Task.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,7 @@ private bool SpinWait(int millisecondsTimeout)
29862986
}
29872987
else
29882988
{
2989-
Thread.SpinWait(PlatformHelper.ProcessorCount * (4 << i));
2989+
Thread.SpinWait(4 << i);
29902990
}
29912991
}
29922992

0 commit comments

Comments
 (0)