a2800276_ has quit [Remote host closed the connection]
bjc has joined #rust-embedded
starblue has quit [Ping timeout: 265 seconds]
starblue has joined #rust-embedded
<re_irc>
<@mciantyre:matrix.org> cr1901: Just guessing: "compiler_fence(Acquire)" prevents instruction movement up to the preceding read. If a read isn't happening within (or at the end of) "stop()", then the compiler could move the subsequent buffer and payload reads (https://github.com/stm32-rs/stm32f1xx-hal/blob/59777ecad18ff7ed3fca82ed5ee4860c94a0031b/src/dma.rs#L403-L404) before / interleaved with the "stop()" instructions.
emerent_ has joined #rust-embedded
emerent is now known as Guest1666
Guest1666 has quit [Killed (tungsten.libera.chat (Nickname regained by services))]
emerent_ is now known as emerent
Foxyloxy_ has quit [Remote host closed the connection]
Foxyloxy has joined #rust-embedded
dc740 has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
<cr1901>
AIUI, fence(Acquire) should prevent insns after the fence from being place before the fence. Is that incorrect?
<cr1901>
So the ptr::read_volatile(&0) seems redundant
<re_irc>
<@jamesmunns:beeper.com> the volatile read of a temporary definitely seems super out of place to me, and would be very sad if that was necessary for things to work correctly.
<re_irc>
<@ryan-summers:matrix.org> If that were the case, it would indicate to me that the fence is incorrectly selected
<re_irc>
<@jamesmunns:beeper.com> Yeah, the one after might want to be "Release"? Like you typically acquire before to make sure you "see" all changes, and you release after to make sure others "see" all changes.
<re_irc>
<@jamesmunns:beeper.com> I still haven't finished reading Mara's book tho 😅
<cr1901>
Well I feel a lot better just that other ppl think it's odd
<cr1901>
(for want of a better term)
<re_irc>
<@ryan-summers:matrix.org> To be frank, most code feels odd to me nowadays, and I immediately become suspicious when someone points me at any of it
<re_irc>
<@dirbaio:matrix.org> yeah that code is not right
<cr1901>
most code feels odd to me nowadays <-- most code was a mistake :'D
<re_irc>
<@dirbaio:matrix.org> you need an AcqRel fence between writing the buffer and starting DMA
<re_irc>
and another AcqRel fence between stopping the DMA and reading the buffer
<cr1901>
Idk enough about DMA to fix it
<cr1901>
About safe DMA in Rust*
<re_irc>
<@jamesmunns:beeper.com> : this matches my understanding as well
<re_irc>
<@dirbaio:matrix.org> that code is missing the 1st
<re_irc>
<@dirbaio:matrix.org> and the 2nd does an Acquire + dummy read instead... not sure what the point is because other memory accesses can be reordered with the dummy read
<re_irc>
<@jamesmunns:beeper.com> put an acqrel fence before the pac interaction in start, and put an acqrel fence after the interaction in stop
<re_irc>
<@dirbaio:matrix.org> also when you stop DMA you have to spin waiting for EN=0, I can't find that there :D
<re_irc>
<@jamesmunns:beeper.com> Yeah, I wonder if their volatile and fence (which issues a dmb!) is just long enough for en=0 to take
<re_irc>
<@jamesmunns:beeper.com> oh nvm
<re_irc>
<@jamesmunns:beeper.com> it's compiler fence not fence, no instruction emitted.
<re_irc>
<@dirbaio:matrix.org> dunno, maybe not because it's only if you forcefully stop it, not needed if it stops naturally
<cr1901>
>not sure what the point is because other memory accesses can be reordered with the dummy read <-- yea, but the Acquire fence is right after the dummy read. So only memory access before the Acquire can be reordered with--
* cr1901
sees the problem
<cr1901>
yea the dummy read stands out as not supposed to be there, but Idk what the fix should look like
<re_irc>
<@jamesmunns:beeper.com> > put an acqrel fence before the pac interaction in start, and put an acqrel fence after the interaction in stop
<re_irc>
IMO.
<re_irc>
<@dirbaio:matrix.org> idk
<re_irc>
<@dirbaio:matrix.org> just use embassy-stm23, it has no DMA bugs :)
<cr1901>
mciantyre: Yea, it makes sense under that definition
<re_irc>
<@jamesmunns:beeper.com> I don't think the fence on 346 actually _does_ anything. volatile ops are not reordered relative to each other, and 344 and 348 are basically both volatile ops.
jr-oss has quit [Ping timeout: 264 seconds]
<cr1901>
I thought the definition of Acquire was " subsequent reads and writes cannot be moved ahead preceding memory accessed period"
<cr1901>
>Intuitively, an acquire access ensures that every access after it stays after it.
<re_irc>
<@jamesmunns:beeper.com> Yeah, we want the reads of buffer and payload to stay AFTER stop.
<cr1901>
Sure, but my interpretation is that subsequent reads/writes won't be moved ahead of preceding reads AND writes
<cr1901>
and docs say that "subsequent reads/writes won't be moved ahead of preceding reads"
<re_irc>
<@jamesmunns:beeper.com> compiler fence docs at least say "with Acquire, subsequent reads and writes cannot be moved ahead of preceding reads."
<cr1901>
But it says nothing about writes
<cr1901>
>and volatile ops have no synchronization interaction with atomic operations, afaik. <-- I would think the fence would prevent things from being reordered before the volatile op
<cr1901>
The volatile in the code I linked appears to be there as a "do not optimize away" measure
<re_irc>
<@jamesmunns:beeper.com> Gotcha, I understand the point you are making better now
<re_irc>
<@jamesmunns:beeper.com> honestly it feels like just using seqcst would be better here: "with SeqCst, no re-ordering of reads and writes across this point is allowed."
<re_irc>
<@jamesmunns:beeper.com> (which is different than AcqRel)
<re_irc>
<@jamesmunns:beeper.com> but I dunno. I should finish reading Mara's book before pretending to know what I am talking about, despite trying to understand this all for 5 years :p
<cr1901>
Okay I think I get it: "However operations that occur before an acquire are free to be reordered to occur after it." <-- Actually, rereading this, this doesn't really contradict the fence docs.
<cr1901>
This would be the same thing as saying "preceding writes can be moved after the fence" (as long as reads before the fence don't depend on these writes)
Darius has quit [Ping timeout: 252 seconds]
<cr1901>
Anyway, atomics hard, brain bandwidth used for the day
Darius has joined #rust-embedded
<re_irc>
<@dngrs:matrix.org> I think it would be good to have concrete examples for each scenario
<re_irc>
<@dngrs:matrix.org> but I guess Mara's book covers that
<re_irc>
<@jamesmunns:beeper.com> Yeah, her book is also available online, so they could be referenced directly in the embedded book
<re_irc>
<@peter9477:matrix.org> : If that's correct, it's just about the first and only description of any of this stuff that I can comprehend and make use of.
<re_irc>
<@jamesmunns:beeper.com> Read Mara's book, it's 100% guaranteed to be more accurate than anything I said.
<re_irc>
<@peter9477:matrix.org> Yep, nice looking resource. Hadn't seen a reference to it before.
<re_irc>
<@jamesmunns:beeper.com> (sorry, that came off grumpy, atomics are one of those "every time I think I have it I am proven wrong", and I very much trust Mara's knowledge over mine :D)
<re_irc>
<@peter9477:matrix.org> Very timely too, as I just threw a random mixed of Orderings into my Pdm changes as placeholders, knowing half of them are probably very wrong...