From 3ffcd2dab007e5353aac1d53bb9131c7fd6c3c5f Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 17 May 2025 09:27:47 +0000 Subject: [PATCH 1/2] Explain how fences interact with volatile operations This was the result of a discussion with Amanieu at RustWeek. It would be nice to add more details about the planned updates (some ticket for example), and I'm not sure if this is the best place to add it to the embedonomicon. But for now, I think mentioning it here is better than nothing. --- src/dma.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/dma.md b/src/dma.md index ab5078a..e7a2579 100644 --- a/src/dma.md +++ b/src/dma.md @@ -245,6 +245,27 @@ of `compiler_fence`. That should generate a DMB instruction on Cortex-M devices. [`atomic::fence`]: https://doc.rust-lang.org/core/sync/atomic/fn.fence.html +## Don't we need atomics? + +The documentation on fences states that they only work in combination with atomics: + +> A fence ‘A’ which has (at least) Release ordering semantics, synchronizes with +> a fence ‘B’ with (at least) Acquire semantics, if and only if there exist +> operations X and Y, both operating on some atomic object ‘m’ such that A is +> sequenced before X, Y is sequenced before B and Y observes the change to m. + +The same is true for `compiler_fence`: + +> Note that just like fence, synchronization still requires atomic operations +> to be used in both threads – it is not possible to perform synchronization +> entirely with fences and non-atomic operations. + +So how does this work when not talking to another thread, but to +some hardware like the DMA engine? The answer is that in the current +implementation, volatiles happen to work just like relaxed atomic +operations. There's work going on to actually guarantee this behavior +for future versions of rust. + ## Generic buffer Our API is more restrictive that it needs to be. For example, the following From 622f16e38cd8f1779a95253e210568bb6d6f634c Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 17 May 2025 23:20:12 +0200 Subject: [PATCH 2/2] Fix typo Co-authored-by: Daniel Egger --- src/dma.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dma.md b/src/dma.md index e7a2579..59f741f 100644 --- a/src/dma.md +++ b/src/dma.md @@ -264,7 +264,7 @@ So how does this work when not talking to another thread, but to some hardware like the DMA engine? The answer is that in the current implementation, volatiles happen to work just like relaxed atomic operations. There's work going on to actually guarantee this behavior -for future versions of rust. +for future versions of Rust. ## Generic buffer