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

macros: make select! budget-aware #7164

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maminrayej
Copy link
Member

Resolves #7108.

@maminrayej maminrayej added A-tokio Area: The main tokio crate M-macros Module: macros in the main Tokio crate labels Feb 17, 2025
@maminrayej maminrayej requested a review from Darksonn February 17, 2025 16:12
@Darksonn Darksonn added the M-coop Module: tokio/coop label Feb 17, 2025
@maminrayej
Copy link
Member Author

Previously the test would hang on the master branch. Although this indicates a failure of some sort, it's undesirable for a test to hang. The test is improved to immediately fail if select! does not respect the budget.

Comment on lines +663 to +669
// Return `Pending` when the task budget is depleted since budget-aware futures
// are going to yield anyway and other futures will not cooperate.
if !$crate::macros::support::has_budget_remaining() {
cx.waker().wake_by_ref();

return ::std::task::Poll::Pending;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is really the best way to go about it. Does our other coop logic run cx.waker().wake_by_ref() directly, or do they stash the waker in the array used by yield_now()?

Copy link
Member Author

Choose a reason for hiding this comment

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

poll_proceed calls wake_by_ref directly instead of going through context::defer.

Copy link
Member

Choose a reason for hiding this comment

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

I looked at poll_proceed, and it does use wake_by_ref. However, I don't know if that is intentional or if we forgot to update that code when yield_now() switched to the defer strategy. My guess is that it is an intentional artifact, and we should update it.

I think the logic (if no budget remaining, then yield) should be wrapped up as a utility that lives in the coop module, so we keep the logic in one place. Separately, we should determine if coop yielding should use the defer path.

Copy link
Member

Choose a reason for hiding this comment

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

This PR is where the defer list was introduced. It feels like coop yielding should use the same path. We can fix this after this PR lands, though. However, it would be nice if all coop code uses a single method that does the actual yielding.

Copy link
Member

Choose a reason for hiding this comment

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

I filed #7185 to fix the coop issue.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

At a high level, I think the direction of this PR is good. I left one comment inline.

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-coop Module: tokio/coop M-macros Module: macros in the main Tokio crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MPSC queue hangs on repeated polling
3 participants