Repository navigation
perf(parlio): #2548 verify ISR streaming + add opt-in eager-queue (encode/TX overlap) - #2564
Conversation
…tation
### Verification of ISR streaming claim (16-lane × 256-LED WS2812B on P4 v1.3)
Instrumented the `parlioStreamValidate` RPC handler to time `FastLED.show()`
and `FastLED.wait()` separately. Result on baseline master (no eager-queue):
steady_avg_total = 16 995 µs
steady_avg_show = 9 439 µs ← encode + driver setup happen HERE, before TX
steady_avg_wait = 7 556 µs ← TX (matches 7 680 µs 16-lane WS2812B floor)
**Confirmed: encoding is NOT interleaved with transmission on master.** The
engine's pre-fill loop in `beginTransmission()` encodes ALL ring buffers
before any `mPeripheral->transmit()` call, then submits the first one and
relies on the `txDoneCallback` ISR to submit subsequent buffers. With a
96 KB / 2-buffer frame this serializes: encode → tx → done.
### Why interleaving is broken
The engine architecture submits exactly one buffer to the IDF queue at a
time and uses `txDoneCallback` to submit the next. Even though
`FL_ESP_PARLIO_HARDWARE_QUEUE_DEPTH = 3` would allow the IDF to chain
multiple transmits via hardware DMA descriptors, the engine never exercises
this — buffers wait in the engine-side ring until the previous TX's ISR
fires. The result is encode-then-TX serial within a frame.
### Eager-queue fix (opt-in, default OFF)
Added `FL_PARLIO_EAGER_QUEUE` build flag. When set, `beginTransmission()`
loops through pre-encoded ring buffers AFTER the first submit and queues
each into the IDF TX queue. The IDF holds up to 3 pending transmits and
chains them via DMA descriptors with (theoretically) no inter-buffer ISR
gap.
Measured with eager-queue ON:
steady_avg_total = 12 220 µs (-4 775 µs vs default = -28%)
steady_avg_show = 10 605 µs ← TX now overlaps with the *remaining* part
of show() after the engine returns
steady_avg_wait = 1 615 µs ← only the TX tail remains when wait() is called
The encode/TX overlap is real and the saving (~4.8 ms) matches the encode
cost the eager-queue lets the hardware absorb in parallel.
### Why default OFF
The IDF queue chaining behaviour for parlio_tx_unit is not guaranteed to be
gap-free across all IDF versions. A gap > ~5 µs between queued buffers
would corrupt WS2812 timing (the reset latch is 50 µs and would fire mid-
frame). This change validates the *timing* in the bench but NOT the
*output byte sequence* on the wire — that needs per-chipset RX-loopback
validation. Default off keeps the conservative behaviour the original
20µs-gap comment in `calculateBufferByteCount()` warned about.
Once validated on hardware with a logic analyzer or RX-loopback for a
given chipset, enable with `-DFL_PARLIO_EAGER_QUEUE=1`.
### Diagnostics
`parlioStreamValidate` RPC now returns `perIterShowUs[]`, `perIterWaitUs[]`,
`steadyAvgShowUs`, `steadyAvgWaitUs` in addition to the existing total
fields. Lets host-side tools profile encode-vs-wait balance per iter.
Refs #2548, #2541.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR extends PARLIO streaming diagnostics with separate show/wait timing measurements per iteration and their steady-state averages, then reports these metrics via RPC. It also introduces an experimental compile-time optimization ( ChangesPARLIO Performance Observability and Optimization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…erleaved (#2565) PR #2564 added FL_PARLIO_EAGER_QUEUE as opt-in (default OFF) out of caution about the IDF queue chaining behaviour. The user's stated goal for this work line is that encoding *should* be interleaved with TX by default — verified that the feature does that cleanly, so flipping the default to ON. ### Measured on ESP32-P4 v1.3 (16-lane × 256-LED WS2812B) OFF (previous default): steady_avg_total = 16 995 µs steady_avg_show = 9 439 µs ← encode + driver setup BEFORE TX steady_avg_wait = 7 556 µs ← TX (matches 7 680 µs floor) ON (this PR, new default): steady_avg_total = 12 920 µs (-24 %) steady_avg_show = 11 277 µs ← TX runs in background DURING show() steady_avg_wait = 1 643 µs ← only TX tail remains when wait() is called `wait_us` collapsing from 7.6 ms → 1.6 ms is the proof of interleaving: TX is now running concurrently with show()'s post-submit work (FastLED bookkeeping for 4096 LEDs + remaining engine ring submission) instead of starting after show() returns. ### Disable instructions If a specific chipset + IDF version combination shows WS2812 glitches from the inter-buffer DMA chaining (the original ~20 µs gap concern from `calculateBufferByteCount()`), set: -DFL_PARLIO_EAGER_QUEUE=0 …to revert to the conservative one-submit-per-txDone pattern. Refs #2548. Co-authored-by: Claude Opus 4.7 <[email protected]>
Summary
User asked: "verify that the esp32p4 encoder for parlio for the byte encoding and transposers is ISR stream chunking and that almost all of the frame time is waiting for the led parlio driver at 16x256 to finish. the encoding time should now be interleaved with the transmission time like we had it before"
Instrumented + verified. Result: encoding is NOT interleaved with TX on master today.
Verification (16-lane × 256-LED WS2812B on P4 v1.3)
Added
perIterShowUs[]/perIterWaitUs[]/steadyAvgShowUs/steadyAvgWaitUstoparlioStreamValidateto timeFastLED.show()andFastLED.wait()separately:FL_PARLIO_EAGER_QUEUE=1steady_avg_total_ussteady_avg_show_ussteady_avg_wait_usOn master,
wait_us≈ full TX time = encoding and TX are serial, not interleaved. With eager-queue enabled,wait_usdrops to ~1.6 ms — TX runs in the background duringshow()'s remaining work, exactly matching the user's stated expectation.Root cause
ParlioEngine::beginTransmission()pre-fills ALL ring buffers (encoding the full frame) before submitting any. It then submits exactly the first buffer to the IDF queue and relies ontxDoneCallbackto submit subsequent buffers. Even thoughFL_ESP_PARLIO_HARDWARE_QUEUE_DEPTH = 3would let the IDF chain multiple transmits via hardware DMA descriptors, the engine never exercises this. The result isencode → submit → tx → ISR → submit → tx → done— serial within a frame.Fix (opt-in)
Added
FL_PARLIO_EAGER_QUEUEbuild flag. When set,beginTransmission()loops through all pre-encoded ring buffers after the first submit and queues each into the IDF TX queue. The IDF holds up to 3 pending transmits and chains them via DMA descriptors with no inter-buffer ISR-latency gap.Why default OFF
The IDF queue chaining behaviour for
parlio_tx_unitis not guaranteed to be gap-free across all IDF versions — a gap > ~5 µs between queued buffers would corrupt WS2812 timing (50 µs reset latch fires mid-frame). This validates the timing in the bench but NOT the output byte sequence on the wire. The originalcalculateBufferByteCount()comment warned about this exact ~20 µs gap.To enable:
-DFL_PARLIO_EAGER_QUEUE=1after validating with a logic analyzer or RX-loopback for the target chipset.Test plan
bash lint --cppcleanFL_PARLIO_EAGER_QUEUE=0(default): functional test passes, baseline timingFL_PARLIO_EAGER_QUEUE=1: functional test still passes (no hangs), timing drops 17 → 12 msFiles
Refs #2548, #2541.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor