-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Preliminary prototype of #3439 #3572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It solves two problems: * Stealing into exclusively owned local queue does no longer require and CAS'es or atomic operations where they were previously not needed. It should save a few cycles on the stealing code path * The overall timing perturbations should be slightly better now: previously it was possible for the stolen task to be immediately got stolen again from the stealer thread because it was actually published to owner's queue, but its submission time was never updated Fixes #3416
…the overall code structure
Previously, a worker thread unconditionally processed tasks from its own local queue, even if tasks were CPU-intensive, but CPU token was not acquired. Fixes #3418
Previously, a worker thread unconditionally processed tasks from its own local queue, even if tasks were CPU-intensive, but CPU token was not acquired. Fixes #3418
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
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.
Only glanced through it quickly for now since it's still a draft.
public fun Thread.isIoDispatcherThread(): Boolean { | ||
if (this !is CoroutineScheduler.Worker) return false | ||
return isIo() | ||
} |
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.
Looks very similar to the functions at the bottom of CoroutineScheduler.kt
and would probably enjoy their company.
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.
I've put it here solely because processNextEventInCurrentThread
and I wanted to keep these "internal event loop spinners" in a single place to keep track of
val task = tryExtractBlockingTask(--end) | ||
// CPU or (BLOCKING & hasBlocking) | ||
val shouldProceed = !onlyBlocking || blockingTasksInBuffer.value > 0 | ||
while (start != end && shouldProceed) { |
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.
shouldProceed
doesn't update. It doesn't feel like it's intentional, but if it is, it can be moved to an if
wrapping the while
.
# Conflicts: # kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt # kotlinx-coroutines-core/jvm/src/scheduling/WorkQueue.kt
9554c01
to
4a6a0f3
Compare
Closing in the favor of #3641 |
No description provided.