Repository navigation
fix(parlio): size DMA ring and TX descriptors to the frame (#5161) - #5232
Conversation
A frame that fits in one ring buffer is always sent from slot 0, yet the engine allocated three full-frame DMA buffers and created the TX unit with max_transfer_size=65534. Allocate one slot when the frame fits (growing to the full ring on demand), and pass the ring capacity as max_transfer_size. ESP32-C6, 12 WS2812B: first show 3668 -> 2484 B, total 4520 -> 3328 B.
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
Memory usage (this PR vs. its merge base)Change in
|
Summary
On ESP32-C6 a
WS2812Bstrip is driven by PARLIO (priority 4, above RMT), not RMT, and PARLIO uses GDMA. Most of the first-show()heap reported in #5161 came from two oversized PARLIO allocations:calculateRingBufferCapacity()sizes one buffer to hold the full frame whenever it fits (any strip below ~87 KB of encoded data per buffer), andcalculateBufferByteCount()then always sends that frame from slot 0 as a single transfer. Slots 1 and 2 were allocated but never written. The engine now allocates one slot when the frame fits, and the full ring only when it streams. The grow path reallocates when the slot count goes up, even if the streaming capacity per buffer is smaller.max_transfer_size = 65534. IDF sizes its DMA descriptor lists from this value. The largest singletransmit()is one ring buffer, so the clockless paths now pass the ring-buffer capacity, capped at 65534. Ring sizing moves ahead ofparlio_new_tx_unit()so the value is known when the unit is created.ChannelDriverPARLIOsizes the ring from a capped LED count (FL_ESP_PARLIO_MAX_LEDS_PER_CHANNEL, bytes/3). SobeginTransmission()now checks the real per-lane frame against the same fit test thatcalculateBufferByteCount()uses. If the frame does not fit, it allocates the missing slots before encoding, and longer strips stream as before.SPI mode keeps the 3-slot ring and the 65534 ceiling. Its sizing uses the wave8 calculator, so it should not rely on the single-buffer fit test.
Evidence
ESP32-C6 (no PSRAM), 12 x WS2812B on GPIO 5. Values are
heap_caps_get_free_size(MALLOC_CAP_8BIT)deltas from the issue's probe sketch, in bytes:Per-allocation breakdown of master's first
show(), from an instrumented build that hooks FastLED's allocator and walks frame pointers:parlio_new_tx_unit()(IDF): 1720 B. This PR cuts it by about 384 B.The
addLeds828 B (ChannelData 208, PARLIO driver 148, manager driver-list 72, callback 12, plus allocations that are not in FastLED) is unchanged.Wire check:
bash autoresearch esp32c6 --parlio:TEST PARLIO lanes=1 leds=100 PASS,RESULT PASS 2 test(s)(RX loopback through the normal LED API) on the final code.Host tests:
bash test parlio_driver(and--debug) pass. The newringBufferCounttest fails on RED (a mutant that always returns 3 makes it fail). The new engine tests cover three cases: growing from one slot to the streaming ring (max_transfer_sizetracks the small frame), and a 40000-LED frame sent after sizing for 12 LEDs. A mutant that skipsensureRingSlotsFor()makes the test binary fail.Limits
show(). The existing "reinitialize for clean DMA state" path does this; it is heap-neutral but costs time. Not changed here.max_transfer_sizecap for very large streaming frames. On the PSRAM-fallback path the TX unit keeps the largermax_transfer_size(that only wastes heap).addLedsoverhead (channel manager, ChannelData, driver singletons) is unchanged.Part of #5161
Summary by CodeRabbit