Avoid long busy-waiting between hijack retries.#103212
Conversation
| return; | ||
| } | ||
| #else | ||
| if (usecs > 10) |
There was a problem hiding this comment.
This is the actual fix. When we need to pause for longer than 10 microseconds, we sleep instead of spinning, thus freeing compute resources to other threads (including ones that we want to progress towards suspending).
There was a problem hiding this comment.
10 is a somewhat arbitrary number in the order of context switch cost. (2-10 microseconds).
We are not very sensitive to the exact value. It just means "too short for the sleep to have any advantages".
There was a problem hiding this comment.
The other reason for 10 is that the default timer slack on Linux is 50 microseconds. So the shortest sleep could be on average 25 microseconds anyways if our wakeups are bunched up with other sleepers.
Thus 10 seems like a reasonable threshold to use sleep.
|
Performance impact on Stage1 ASP.Net benchmark. ======================================================== arm64 ======================================================= x64 commands used: |
|
Tagging subscribers to this area: @mangod9 |
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
Thanks! |
Fixes: #102832
minipal_microdelay- to have the same implementation for CoreCLR and NativeAOT(not responsible for the regression, just possible corner cases noticed while investigating)