-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Description
Tracking #40537 (comment)
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Tracking issue for PR https://github.com/rust-lang/rust/pull/40537#issuecomment-292972023[/-][+]Tracking issue for PR 40537 (hint_core_should_pause)[/+]clarfonthey commentedon May 2, 2017
Reposting my comment from #41207: the
spin
crate calls this functioncpu_relax
; maybe we should do something similar?I'd much prefer
spin_loop_hint
or something similar to the current function name. We could even potentially have a warning that suggests using this function, or even better, have the compiler automatically add these instructions inside busy loops.ghost commentedon Oct 5, 2017
I like the
spin_loop_hint
name, but would be okay withspin_wait
as well.Java calls this
onSpinWait
, in .NET it'sSpinWait
, and Linux kernel hascpu_relax
.Would it be a good time to propose stabilization after some name bikeshedding?
I've wanted this function in stable Rust for quite a while. :)
alexcrichton commentedon Oct 5, 2017
@rfcbot fcp merge
Sounds like a great issue to consider for stabilization!
Proposed name
spin_loop_hint
rfcbot commentedon Oct 5, 2017
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed.
Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
alexcrichton commentedon Oct 5, 2017
To be clear I also don't have much of a preference on names, @stjepang's preference of
spin_loop_hint
also seems fine by mesfackler commentedon Oct 5, 2017
spin_loop_hint
orspin_wait
both seem reasonable.dtolnay commentedon Oct 8, 2017
I am on board with stabilizing a function with this behavior. But in general, the more a function's behavior may be confusing, the more careful we need to be in selecting a name.
spin_wait
because the spin loop code would read as though this call internally does a spin wait, rather than identifies the spin wait containing the call.cpu_relax
because the word "relax" is already claimed in the context of atomics forOrdering::Relaxed
.hint_core_should_pause
because "pause" means do nothing for a while, where doing something else for a while may be more what you want.spin_loop_hint
which is what the Intel® 64 and IA-32 Architectures Software Developer’s Manual names thepause
instruction.I also sort of like the naming that WebKit uses --
pause
is calledYIELD_PROCESSOR
andthread::yield_now
is calledYIELD_THREAD
. This frames them as a pair of lower/higher level instructions. Yield processor is a hint to the processor, and yield thread is a hint to the OS's scheduler. Go uses the same naming --pause
is calledruntime.procyield
. So I'll add another name:yield_processor
.clarfonthey commentedon Oct 8, 2017
👍 to
spin_loop_hint
dtolnay commentedon Oct 18, 2017
Looking at this again, I prefer
yield_processor
overspin_loop_hint
. It seems like both would need to be documented equally carefully, butyield_processor
results in code that is more pleasant to read. Unlessyield_processor
mischaracterizes how people conceptualize this instruction, I would go with that one. Also, precedent in Go and WebKit is encouraging.It could also work as
std::sync::atomic::yield
. Is everything that runs Rust a "processor"?6 remaining items
ghost commentedon Oct 21, 2017
@clarcharr
I don't think the compiler can automatically decide when and where to insert the instruction into a loop. This is something only the programmer knows, really.
Inserting the instruction into a loop is a very delicate matter. Consider how
parking_lot
does it:Here,
cpu_relax(t)
will execute the instructiont
times. Each successive step of the loop the instruction is executed twice as many times. There's a lot going on in that snippet - and is something that's very hard for the compiler to do correctly.There's no recipe for how to properly use the instruction. You just have to carefully tweak the parameters, profile the program, and see what works best. There's no other way. :)
Ixrec commentedon Oct 24, 2017
I'm not familiar with this function, but after spending a few minutes reading up on it, I believe
spin_loop_hint
is the only name suggested so far that would not be misleading to me. All of the others contain a word likeyield
,pause
,wait
,relax
, etc that implies significantly more impact on execution semantics than a merehint
to the CPU.main-- commentedon Oct 25, 2017
From the Intel Optimization Manual, section 8.4.7:
The instruction's original function (hint to avoid memory order violation) has been extended quite a bit. So yes, it does yield resources.
alexcrichton commentedon Oct 31, 2017
I'm going to go ahead an check @BurntSushi's checkbox as it's been awhile and I think he's quite busy!
rfcbot commentedon Oct 31, 2017
🔔 This is now entering its final comment period, as per the review above. 🔔
Option::filter
to the standard library rust-lang/rfcs#2124rfcbot commentedon Nov 10, 2017
The final comment period is now complete.
bstrie commentedon Nov 17, 2017
I marginally prefer
spin_loop_hint
overyield_processor
, if only because it has zero chance of confusion with, er, whatever theyield
keyword ends up doing.Rollup merge of rust-lang#46174 - stjepang:stabilize-spinloophint, r=…
ghost commentedon Jan 11, 2018
In #43751, there has been some talk of stabilizing module
std::intrinsics
or introducingstd::hints
. I wonder if such a module would be a better fit forspin_loop_hint
thanstd::sync::atomic
- what does everyone think?(just a reminder: this feature is currently in beta, scheduled for stabilization in 1.24)
ghost commentedon Apr 12, 2018
This feature was stabilized. Let's close the issue.