Skip to content

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

Closed
wants to merge 15 commits into from
Closed

Conversation

qwwdfsad
Copy link
Member

@qwwdfsad qwwdfsad commented Jan 3, 2023

No description provided.

qwwdfsad and others added 12 commits November 22, 2022 11:46
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
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
Base automatically changed from scheduler-improvement to develop January 16, 2023 16:08
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a 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()
}
Copy link
Collaborator

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.

Copy link
Member Author

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) {
Copy link
Collaborator

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
@qwwdfsad qwwdfsad force-pushed the scheduler-internal-api branch from 9554c01 to 4a6a0f3 Compare February 25, 2023 16:03
@qwwdfsad
Copy link
Member Author

Closing in the favor of #3641

@qwwdfsad qwwdfsad closed this Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants