Skip to content

perf(channels): add waitDone() virtual + manager N=1 fast path (Phase 2 of #2815, Closes #2819) - #2828

Merged
zackees merged 1 commit into
masterfrom
feat/channels-waitdone-2819-v2
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-waitdone-2819-v2

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 2 of #2815 / Closes #2819. Builds on #2817 (NetworkDetector gate) and #2827 (Tier-2 spin).

Adds the IChannelDriver::waitDone(u32 timeoutMs) virtual with a default delegate, and inserts a single-driver fast path in ChannelManager::waitForReady. Together they expose a hook for drivers to bypass the spin/yield loop and block directly on their existing ISR-driven completion primitive.

What the fast path does

bool ChannelManager::waitForReady(u32 timeoutMs) {
    // pre-pass: how many drivers are BUSY?
    IChannelDriver* onlyBusy = ...;
    int busyCount = ...;

    if (busyCount == 0)              return true;                       // nothing to wait for
    if (busyCount == 1 && onlyBusy)  return onlyBusy->waitDone(timeoutMs);  // FAST PATH (this PR)
    /* N > 1 */                       return waitForCondition(...);     // existing tiered loop
}

For a driver that overrides waitDone() to call its semaphore-backed wait (e.g. PARLIO -> parlio_tx_unit_wait_all_done, LCD_SPI -> existing xSemaphoreTake(mCompleteSem, ticks)), the wait wakes precisely when the DMA-done ISR fires (~µs) instead of paying the 250 us spin budget or the cooperator yield's tick floor.

The default waitDone() delegates to the existing waitForReady(timeoutMs), so drivers that haven't migrated continue to work identically to before. No regressions.

Survey: N=1 is the common case

Across examples/, ~83% of sketches register a single driver type (single chipset family, possibly multiple strips on the same driver). True multi-driver concurrency (e.g. SPI clockless + PARLIO simultaneously) is rare. The fast path covers the overwhelming majority of users.

Files

File Change
src/fl/channels/driver.h NEW virtual bool waitDone(u32 timeoutMs) with default-delegate to waitForReady
src/fl/channels/manager.cpp.hpp poll() pre-pass + N=1 short-circuit in waitForReady

What this PR does NOT do (deferred to follow-up PRs)

The fast path only delivers the latency win if drivers override waitDone(). The driver-side overrides are intentionally NOT in this PR - each one is small and self-contained, and they should land incrementally so a regression in any one is easy to bisect:

Driver Override targets the existing primitive
PARLIO parlio_tx_unit_wait_all_done() (parlio_peripheral_esp.cpp.hpp:334)
RMT5 rmt_tx_wait_all_done() (IDF semaphore)
LCD_SPI / LCD_CLOCKLESS existing xSemaphoreTake(mCompleteSem, ticks) (lcd_spi_peripheral_esp.cpp.hpp:452)
I2S_SPI existing xSemaphoreTake(mCompleteSem, ticks) (i2s_spi_peripheral_esp.cpp.hpp:556)
SPI clockless spi_device_get_trans_result() (spi_peripheral_esp.cpp.hpp:283)
I2S LCD_CAM currently polls mBusy - needs ~20 LOC to add a binary sem + give-in-ISR
LCD_RGB currently polls mBusy - needs ~20 LOC similar
Teensy ObjectFLED / FlexIO flag-poll override (no FreeRTOS)

Each driver override is essentially:

bool waitDone(u32 timeoutMs) FL_NOEXCEPT override {
    return mPeripheral.waitTransmitDone(timeoutMs);
}

Test plan

Host

  • Default-delegate path verified by existing manager tests (no behavioral change when no driver overrides waitDone).
  • Phase 1 tests still pass (309/310; the 310th is pre-existing spi_pingpong_pipeline_logic, independent of FastLED.* / waitFor* / ChannelManager).

Hardware (deferred until driver-side overrides land)

Cross-references

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Added a new driver completion hook to improve how drivers report completion, while preserving existing driver behavior by default.
    • Streamlined manager readiness checks with a single-driver fast path that directly awaits a lone busy driver, falling back to prior aggregate waiting for multiple drivers.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bc6f1ada-f9f5-4704-839e-2e5ff295416a

📥 Commits

Reviewing files that changed from the base of the PR and between 4e9c11d and f30a548.

📒 Files selected for processing (2)
  • src/fl/channels/driver.h
  • src/fl/channels/manager.cpp.hpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/fl/channels/driver.h
  • src/fl/channels/manager.cpp.hpp

📝 Walkthrough

Walkthrough

Adds IChannelDriver::waitDone(u32) with a default delegating implementation, and changes ChannelManager::waitForReady() to detect a single non-READY driver and call that driver's waitDone(timeoutMs) as a fast path; other cases fall back to the existing aggregate wait.

Changes

Single-Driver Wait Optimization

Layer / File(s) Summary
IChannelDriver waitDone API
src/fl/channels/driver.h
Adds virtual waitDone(u32 timeoutMs) method to the driver interface with a default implementation that delegates to waitForReady(). New method is documented to support ISR/semaphore-based completion overrides by driver implementations.
ChannelManager single-driver fast path
src/fl/channels/manager.cpp.hpp
waitForReady() now performs a pre-pass over enabled drivers: returns true if all are READY; if exactly one driver is non-READY (and none are ERROR) it calls that driver's waitDone(timeoutMs) and returns its result (logging a timeout on false); otherwise falls back to existing tiered aggregate wait.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 I wait with a twitchy nose and grin,
One driver hums, the others dim.
No spin, no yield — a semaphore's song,
Quick wake, bright strips, the show goes on!
✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding waitDone() virtual method and implementing an N=1 fast path in the manager.
Linked Issues check ✅ Passed The implementation covers the core API and manager requirements from #2819: waitDone() virtual method with default delegation, poll pre-pass, and N=1 fast path short-circuit.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the PR objectives: IChannelDriver::waitDone() addition and ChannelManager::waitForReady() fast-path logic. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/channels-waitdone-2819-v2

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… 2 of #2815, Closes #2819)

Adds IChannelDriver::waitDone(u32 timeoutMs) as a virtual with a
default delegate to the existing waitForReady(timeoutMs). Drivers that
have an ISR-driven completion primitive (FreeRTOS semaphore, IDF
wait-all-done call, event-group) can override this to block directly
on it - bypassing both the spin tier (from #2818) and the cooperator
yield loop. Drivers that haven't migrated continue to work unchanged
via the default delegate.

ChannelManager::waitForReady now does a poll() pre-pass to classify
drivers, and when exactly one driver is BUSY it delegates to
driver->waitDone(timeoutMs) - the single-driver fast path. The N=1
case covers ~83% of FastLED sketches per a survey of examples/.

For N > 1 (multi-driver aggregate wait) the manager falls through to
the existing tiered waitForCondition loop. Phase 3 of #2815 will add
a shared-sem / task-notification fan-in for that case.

This PR does NOT add the per-driver waitDone() overrides themselves.
Each driver-side override (PARLIO -> parlio_tx_unit_wait_all_done,
RMT5 -> rmt_tx_wait_all_done, LCD_SPI -> existing xSemaphoreTake on
mCompleteSem, etc.) is incremental and can land as a separate small
PR per driver, gradually unlocking the ISR-exact wait for each.

Closes #2819. Refs #2815, #2818.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees force-pushed the feat/channels-waitdone-2819-v2 branch from 4e9c11d to f30a548 Compare June 5, 2026 19:57
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@zackees
zackees merged commit 5714085 into master Jun 5, 2026
6 of 7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the feat/channels-waitdone-2819-v2 branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf(channels): Phase 2 of #2815 - waitDone() virtual + per-driver ISR fast path

1 participant