Note that there are some explanatory texts on larger screens.

plurals
  1. POcombining packed data with aligned memory access
    primarykey
    data
    text
    <p>I'm trying to perform a memory optimization that should be theoretically possible but that I'm starting to doubt is within arm-elf-gcc's capability. Please show me that I'm wrong.</p> <p>I have an embedded system with a very small amount of main memory, and an even smaller amount of battery-backed nvram. I am storing checksummed configuration data in the nvram so that on boot I can validate the checksum and continue a previous run or start a new run if the checksum is invalid. During the run, I update various fields of various sizes in this configuration data (and it's okay that this invalidates the checksum until it is later recalculated).</p> <p>All of this runs in physical address space - the normal sram is mapped at one location and the nvram is mapped at another. Here's the rub - all access to the nvram must be done in 32-bit words; no byte or halfword access is allowed (although it's obviously fine in main memory).</p> <p>So I can either a) store a working copy of all of my configuration data in main memory, and memcpy it out to the nvram when I recalculate the checksum or b) work with it directly in nvram but somehow convince the compiler that all structs are packed and all accesses must not only be 32-bit <em>aligned</em>, but also 32-bit <em>wide</em>.</p> <p>Option a) wastes precious main memory, and I would much rather make the runtime tradeoff to save it (although not if the code size ends up wasting more than I save on data size) via option b).</p> <p>I was hoping that <code>__attribute__ ((packed, aligned(4)))</code> or some variation thereof could help here, but all of the reading and experimenting I have done so far has let me down.</p> <p>Here's a toy example of the sort of configuration data I'm dealing with:</p> <pre><code>#define __packed __attribute__ ((packed)) struct __packed Foo { uint64_t foo; struct FooFoo foofoo; } struct __packed Bar { uint32_t something; uint16_t somethingSmaller; uint8_t evenSmaller; } struct __packed PersistentData { struct Foo; struct Bar; /* ... */ struct Baz; uint_32 checksum; } </code></pre> <p>You can imagine different threads (one each to perform functions Foo, Bar, and Baz) updating their own structures as appropriate, and synchronizing at some point to declare it time to recalculate the checksum and go to sleep.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload