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

Add a spin loop hint for Arc::downgrade #76649

Merged
merged 1 commit into from
Oct 24, 2020

Conversation

nicbn
Copy link
Contributor

@nicbn nicbn commented Sep 12, 2020

Adds hint::spin_loop() to the case where Arc::downgrade spins.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 12, 2020
@pickfire
Copy link
Contributor

pickfire commented Sep 13, 2020

Will this affect performance? Or improve it somehow?

@nicbn
Copy link
Contributor Author

nicbn commented Sep 15, 2020

It will hint to the proccessor that there will be a spin loop, using for example the PAUSE instruction:

Worst case, this boils down to a no-op and speed isn't affected.
Best case, processor enters low-power mode, which saves lots of time and energy that would be spent doing basically nothing in a loop. Also, it reduces the chances for contention on the atomic unlock operation if it is done by another processor, which could slightly increase performace.

This stackoverflow answer provides some more reasoning on what it will do

@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 7, 2020
@camelid camelid added T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Oct 23, 2020

Most usages of hint::spin_loop that I've seen first spin without the hint, and only use it after a few iterations. For example: here in parking_lot. Edit: Nope. I misread that.

However, the Intel optimization manual advises to always insert the spin loop hint (the PAUSE instruction) like this PR does, and has no mention of delaying its use. Not sure about other processors/architectures.

@Amanieu With your experience from parking_lot, do you have an opinion on this?

@Amanieu
Copy link
Member

Amanieu commented Oct 23, 2020

That's not what that code does: it first spins with PAUSE and then after a few iterations switches to sched_yield.

@m-ou-se
Copy link
Member

m-ou-se commented Oct 23, 2020

That's not what that code does: it first spins with PAUSE and then after a few iterations switches to sched_yield.

Oops, apparently I misread. Thanks!

In that case:

@bors r+ rollup

@bors

This comment has been minimized.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Oct 23, 2020

Oh, can you first remove the merge commit by rebasing/squashing?

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 23, 2020
@bors

This comment has been minimized.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 23, 2020
@nicbn
Copy link
Contributor Author

nicbn commented Oct 23, 2020

Rebased

@m-ou-se
Copy link
Member

m-ou-se commented Oct 23, 2020

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 23, 2020

📌 Commit 929f80e has been approved by m-ou-se

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2020
…as-schievink

Rollup of 15 pull requests

Successful merges:

 - rust-lang#76649 (Add a spin loop hint for Arc::downgrade)
 - rust-lang#77392 (add `insert` to `Option`)
 - rust-lang#77716 (Revert "Allow dynamic linking for iOS/tvOS targets.")
 - rust-lang#78109 (Check for exhaustion in RangeInclusive::contains and slicing)
 - rust-lang#78198 (Simplify assert terminator only if condition evaluates to expected value)
 - rust-lang#78243 (--test-args flag description)
 - rust-lang#78249 (improve const infer error)
 - rust-lang#78250 (Document inline-const)
 - rust-lang#78264 (Add regression test for issue-77475)
 - rust-lang#78274 (Update description of Empty Enum for accuracy)
 - rust-lang#78278 (move `visit_predicate` into `TypeVisitor`)
 - rust-lang#78292 (Loop instead of recursion)
 - rust-lang#78293 (Always store Rustdoc theme when it's changed)
 - rust-lang#78300 (Make codegen coverage_context optional, and check)
 - rust-lang#78307 (Revert "Set .llvmbc and .llvmcmd sections as allocatable")

Failed merges:

r? `@ghost`
@bors bors merged commit 8e75669 into rust-lang:master Oct 24, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 24, 2020
@nicbn nicbn deleted the arc-spin-loop-hint branch October 24, 2020 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants