TECHNOLOGY

DMA cache maintenance: the cache line can contain more than your sensor buffer

In this article
THE QUICK TAKE

Qualify the actual DMA coherency contract and isolate maintenance ranges at the required line granularity; an aligned start alone does not protect neighboring data at the end.

The sample is correct but neighboring state changes

A DMA sensor buffer feeds an embedded classifier. After cache invalidation, the new sample becomes visible but an adjacent application field loses its recent CPU update. The maintainer checked the buffer’s starting alignment and assumed the operation touched only its requested bytes. Cache maintenance operates at cache-line granularity. Diagnose the full affected span and ownership of neighboring bytes before blaming preprocessing or a model kernel. Correct sensor values alone do not prove the handoff preserved other live application state.

Identify the actual coherence arrangement

The Zephyr caching guide explains that external bus masters such as DMA can require explicit coherence management. Establish whether the selected memory and driver path are coherent, uncached or require maintenance. Do not infer that CPU-core coherence automatically covers the peripheral. Equally, do not add maintenance blindly where another supported layer already owns it. Preserve which component performs the operation and the event that establishes the transfer has reached the required completion boundary.

Direction and ownership determine the operation

The guide distinguishes flushing modified CPU data before another bus master reads it from invalidating stale CPU cache before reading peripheral-written data. This is not a universal instruction to clean every receive buffer afterward. A late writeback of an old dirty line can conflict with newer external data. Follow the platform’s complete handoff sequence, including any required preparation before DMA and ordering guarantees. Keep the buffer unavailable to unsynchronized CPU modification during the device-owned phase.

Isolate both boundaries of the maintained range

The Zephyr guide warns that unrelated data packed into a line can be destroyed during invalidation. Reserve a suitable complete span, accounting for both beginning and end, or use a supported uncached placement. The CMSIS D-cache reference specifies a 32-byte address boundary for its documented functions. That requirement belongs to that API and target family; it is not a universal constant for every processor. Verify the actual line and range contract instead of copying the number into all firmware.

Propose sample and neighbor integrity checks

Use harmless recognizable DMA payloads and adjacent CPU-owned markers in a controlled fixture. Compare the supported isolated layout with a diagnostic layout that exposes shared-line risk without accessing unowned memory. Check actual transfer completion, sample contents and marker preservation through repeated handoffs. Acceptance requires correct data on both sides and documented maintenance ownership. No DMA transfer or cache-control operation ran here; this fixture defines a correctness investigation, not a measured bandwidth result or permission to alter production memory attributes.

Keep software-view synchronization separate

Embree host/device views address another synchronization model. Device-buffer ownership explains why a pointer needs a valid lifetime. DMA cache maintenance adds cache-line granularity and memory-attribute requirements to that reasoning. Record transfer direction, actual memory path and neighbor ownership so a classifier’s input error can be investigated without assuming every shared address is automatically coherent or every range operation preserves unrelated bytes.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles