-
Notifications
You must be signed in to change notification settings - Fork 506
Implement APIs for some threading metrics (CoreRT) #7066
Conversation
|
There is a slightly noticeable decrease in throughput of local work items queued to the thread pool in raw overhead per work item. It is very small and when a very short delay is added to the work item the difference is almost not measurable, so it should be acceptably small. |
I am not sure I understand your motivation for the change. I believe the whole point was to split the queues and process them separately in separate threads. Now you are trying to undo that at lower level. Am I missing something? |
Only one thread was created and the |
The ID was not ignored, it just was not necessary since the instance variables could be used in the pure managed code implementation. The corert/src/System.Private.CoreLib/shared/System/Threading/Timer.cs Lines 46 to 54 in a8cb34b
Each
Ok, for reference: dotnet/coreclr#14527.
This is the part I missed. I saw the code in I am not sure if the change back to one thread is actually beneficial, but if it matches CoreCLR then it's probably ok. Would be nice to have a benchmark, there is a simple one in dotnet/coreclr#20302. |
It only started one thread for all It could be fixed with fewer changes and more threads (changing some static variables to instance variables, and some such), and it would still be unfortunate to have 32 timer threads on a 32-core machine all for just the purpose of a very small improvement at best. Timers can only request to tick once per millisecond, which is already long, and the resolution is actually about 15+ ms on Windows, any gain with having multiple threads serving those timer requests would be squashed just by the timer resolution. |
Ah, that is a bug I missed. It should have been changed to an instance variable. It is called from under lock (
I'm not convinced that the improvement is so small for a case where the timers are heavily used. However, I do believe that for the common case it will likely be overkill to have multiple threads. There are couple other small concerns I have with the change so it would have been nice if it was split off into separate PR. |
Timer on Unixes|
The RT implementation in latest commit is broken, will fix and retest |
|
Updated perf numbers are here |
|
Ping for review please |
|
@dotnet-bot test OSX10.12 Debug and CoreFX tests |
|
The API review was approved. Couple of pending items is:
|
…ad (dotnet#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (mono#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (dotnet#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
…ad (dotnet#7071) * Change Timer implementation on Unixes to use only one scheduling thread - Separated from dotnet/corert#7066 * Address feedback from dotnet/corert#7066 * Remove reference to s_lock * Reduce work inside lock * Move _id * Fix duplicate timers in scheduled timer list, move info to TimerQueue Signed-off-by: dotnet-bot <[email protected]>
|
The perf difference from adding |
|
I have updated to remove local/global versions of PendingWorkItemCount. They can be added in the future if they would be useful. I think all three PRs (CoreCLR, CoreRT, and CoreFX) are now ready for review. @jkotas / @stephentoub, would you be able to take a look? |
| { | ||
| get | ||
| { | ||
| // Make sure up-to-date thread-local node state is visible to this thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be needed.
| { | ||
| get | ||
| { | ||
| // Make sure up-to-date thread-local node state is visible to this thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be needed.
| LinkedSlot linkedSlot = _linkedSlot; | ||
| int id = ~_idComplement; | ||
| if (id == -1) | ||
| if (id == -1 || linkedSlot == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this fixing a bug when _linkedSlot? Do we need a test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a possibility that after Dispose is called and another thread calls this method, because there are no restrictions on the loads here, the other thread could read an old value for _idComplement (where id != 0) and a new value for _linkedSlot (== null), then it would throw NullReferenceException instead of ObjectDisposedException. I didn't see anything that would prevent that, and thought it would be difficult to repro but it seems to be fairly easy, will add a test to the CoreFX PR.
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
…etect thread exit
|
Rebased |
|
* Implement APIs for some threading metrics (CoreRT) - API review: https://github.com/dotnet/corefx/issues/35500 - May depend on dotnet#22754 * Use thread-locals for counting, use finalizer instead of runtime to detect thread exit * Don't let the count properties throw OOM * Remove some flushes Signed-off-by: dotnet-bot <[email protected]>
* Implement APIs for some threading metrics (CoreRT) - API review: https://github.com/dotnet/corefx/issues/35500 - May depend on dotnet/coreclr#22754 * Use thread-locals for counting, use finalizer instead of runtime to detect thread exit * Don't let the count properties throw OOM * Remove some flushes Signed-off-by: dotnet-bot <[email protected]>
* Implement APIs for some threading metrics (CoreRT) - API review: https://github.com/dotnet/corefx/issues/35500 - May depend on dotnet/coreclr#22754 * Use thread-locals for counting, use finalizer instead of runtime to detect thread exit * Don't let the count properties throw OOM * Remove some flushes Signed-off-by: dotnet-bot <[email protected]>
* Implement APIs for some threading metrics (CoreRT) - API review: https://github.com/dotnet/corefx/issues/35500 - May depend on #22754 * Use thread-locals for counting, use finalizer instead of runtime to detect thread exit * Don't let the count properties throw OOM * Remove some flushes Signed-off-by: dotnet-bot <[email protected]>
* Expose and test APIs for some threading metrics (CoreFX) - API review: https://github.com/dotnet/corefx/issues/35500 - Depends on dotnet/coreclr#22754, dotnet/corert#7066 * Separate and expose pending local vs global work item count * Remove local/global variants of PendingWorkItemCount * Remove unrelated test * Add test for a fix to ThreadLocal.Values property throwing NullReferenceException when disposed Fix is in dotnet/corert#7066 * Fix build * Fix test * Add API compat baselines for uapaot * Fix test * Use RemoteExecutor for MetricsTest * Address feedback
Uh oh!
There was an error while loading. Please reload this page.