News for hackers. Stuff that matters.
Re:Making the Tokio scheduler 10x faster by dunkelheit on Monday October 14, 2019 @02:04PM (#21251038)
What is the difference with Ordering::Relaxed?
Re:Making the Tokio scheduler 10x faster by ComputerGuru on Monday October 14, 2019 @02:10PM (#21251104)
Ordering::Relaxed guarantees atomicity (but not coherence). On 32-bit or 64-bit platforms, a (aligned) 32-bit read or write will always be atomic anyway.
Re:Making the Tokio scheduler 10x faster by comex on Monday October 14, 2019 @10:05PM (#21254940)
An assembly-level read or write will always be atomic anyway, and in fact a relaxed atomic read/write typically compiles down to the exact same assembly as a normal read/write. However, there are compiler optimizations that can break atomicity, such as splitting accesses into multiple parts; using (relaxed) atomics instructs the compiler not to perform those optimizations.
Re:Making the Tokio scheduler 10x faster by dunkelheit on Monday October 14, 2019 @02:22PM (#21251221)
What do you mean by coherence? If it is the property that all updates to a single memory location are seen in a consistent order by all threads then Relaxed guarantees that.
Re:Making the Tokio scheduler 10x faster by wilsonthewhale on Monday October 14, 2019 @03:00PM (#21251564)
it doesn't. From cppreference (whose model Rust roughly follows): "Relaxed operation: there are no synchronization or ordering constraints imposed on other reads or writes, only this operation's atomicity is guaranteed"
Re:Making the Tokio scheduler 10x faster by dunkelheit on Monday October 14, 2019 @03:21PM (#21251768)
Still I think I am correct. The docs (https://doc.rust-lang.org/std/sync/atomic/enum.Ordering.html...) point to https://llvm.org/docs/Atomics.html#monotonic which states that "It essentially guarantees that if you take all the operations affecting a specific address, a consistent ordering exists." which is what I've said.
Re:Making the Tokio scheduler 10x faster by ComputerGuru on Monday October 14, 2019 @03:34PM (#21251892)
Yes, a consistent ordering exists but that ordering isn’t necessarily what you think or want it to be. The consistency is present based off the order the reads and writes were executed in; you’ll never read back a value that wasn’t at some point stored there. Which can happen with non-atomic reads/writes, where you’ll read part of one write and part of the next. Reads can still be reordered before writes, as no memory barriers are issued.
Re:Making the Tokio scheduler 10x faster by dunkelheit on Monday October 14, 2019 @04:20PM (#21252418)
Well that doesn't contradict anything that I have said :) My question remains - what do you mean by coherence? I argue that it is precisely the property that there is a consistent order of operations a single memory memory location so you can't say that Relaxed operations don't satisfy coherence.
Re:Making the Tokio scheduler 10x faster by gpderetta on Monday October 14, 2019 @07:02PM (#21253794)
You are correct. IIRC Coherency is the only property of relaxed atomic operations, as opposed of plain load/stores where concurrent modification and access is just UB.
Re:Making the Tokio scheduler 10x faster by carllerche on Monday October 14, 2019 @02:16PM (#21251164)
Relaxed ordering impacts the compiler. There are a number of optimizations it cannot make. I am not sure exactly what those are, but it is measurable.
Re:Making the Tokio scheduler 10x faster by CodesInChaos on Tuesday October 15, 2019 @07:34AM (#21257443)
The only forbidden optimization I could come up with is:

    x = load-relaxed(a)
    ...
    f(x)
cannot be turned into

    x0 = load-relaxed(a)
    ...
    x1 = load-relaxed(a)
    f(x1)
while this would be possible with normal memory access.

so under register pressure the compiler would be required to spill something onto the stack instead of just reloading `x` from the original location.

Re:Making the Tokio scheduler 10x faster by carllerche on Tuesday October 15, 2019 @08:24AM (#21257663)
Last time I spoke about this topic w/ the rust compiler devs, they mentioned there were some LLVM "bugs" with regards to optimizations and Relaxed, as in LLVM is too conservative.
Re:Making the Tokio scheduler 10x faster by dunkelheit on Monday October 14, 2019 @02:54PM (#21251496)
Probably some reordering? Would be interesting to compare generated assembly.
Re:Making the Tokio scheduler 10x faster by carllerche on Monday October 14, 2019 @11:32PM (#21255331)
I believe there are some LLVM "bugs" with regards to Relaxed ordering. I don't know the specifics.