Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
nicbn:arc-spin-loop-hint
Oct 24, 2020
Merged

Add a spin loop hint for Arc::downgrade#76649
bors merged 1 commit into
rust-lang:masterfrom
nicbn:arc-spin-loop-hint

Conversation

@nicbn

Copy link
Copy Markdown
Contributor

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

@rust-highfive

Copy link
Copy Markdown
Contributor

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-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 12, 2020
@pickfire

pickfire commented Sep 13, 2020

Copy link
Copy Markdown
Contributor

Will this affect performance? Or improve it somehow?

@nicbn

nicbn commented Sep 15, 2020

Copy link
Copy Markdown
ContributorAuthor

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

@camelidcamelid 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
@camelidcamelid added T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api [DEPRECATED; DO NOT USE] 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

m-ou-se commented Oct 23, 2020

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

m-ou-se commented Oct 23, 2020

Copy link
Copy Markdown
Member

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.

@borsbors 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

m-ou-se commented Oct 23, 2020

Copy link
Copy Markdown
Member

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

@bors r-

@borsbors 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.

@borsbors 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
nicbnforce-pushed the arc-spin-loop-hint branch from b58db1b to 929f80eCompareOctober 23, 2020 19:11
@nicbn

Copy link
Copy Markdown
ContributorAuthor

Rebased

@m-ou-se

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Oct 23, 2020

Copy link
Copy Markdown
Collaborator

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

@borsbors 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:masterOct 24, 2020
@rustbotrustbot 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
@m-ou-sem-ou-se mentioned this pull request Oct 26, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@nicbn@rust-highfive@pickfire@m-ou-se@Amanieu@bors@withoutboats@camelid@rustbot