Skip to content
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

rt: pop at least one task from inject queue #5908

Merged
merged 1 commit into from Aug 4, 2023

Conversation

carllerche
Copy link
Member

When pulling a batch of tasks from the injection queue, ensure we set the cap to at least one.

When attempting to pull a batch of tasks from the injection queue,
ensure we set the cap to at least one.
@carllerche carllerche added A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels Aug 3, 2023
@github-actions github-actions bot added the R-loom-multi-thread Run loom multi-thread tests on this PR label Aug 3, 2023
@carllerche
Copy link
Member Author

The current behavior is not incorrect but will result in less-than-optimal execution behavior.

Comment on lines +790 to +792
// Take at least one task since the first task is returned directly
// and nto pushed onto the local queue.
let n = usize::max(1, n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you should add one to cap in the usize::min above instead, no?

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 could... I thought it would be clearer to split it out w/ a comment.

// Take at least one task since the first task is returned directly
// and nto pushed onto the local queue.
let n = usize::max(1, n);

let mut synced = worker.handle.shared.synced.lock();
// safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, maybe do this and drop the plus one in the first branch of usize::min?

Suggested change
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) };
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n + 1) };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that isn't the same. We don't want to always add 1; we want a min of 1

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you go for the solution you prefer.

@carllerche carllerche merged commit 7c54fdc into master Aug 4, 2023
73 checks passed
@carllerche carllerche deleted the rt-threaded-take-at-least-one-task branch August 4, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime R-loom-multi-thread Run loom multi-thread tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants