Repository navigation
Description
Phase 2 of #2815 — waitDone() virtual + per-driver ISR fast path
Once Phase 1 (#2818) lands the tiered-spin safety net, Phase 2 collapses the single-driver wait path to a direct ISR-driven semaphore Take, bypassing both the spin tier and the deep yield entirely. Target: ≥83% of FastLED sketches (single-driver per examples/ survey) wake on ISR within ~µs of DMA completion, with no tick floor and no microsecond spin.
Design rationale and the multi-strategy comparison live in #2815.
Scope (one PR, depends on #2818)
IChannelDriver API additions
// src/fl/channels/driver.h
class IChannelDriver {
public:
/// Block until this driver is READY, or timeoutMs elapses.
/// Default delegates to waitForReady() — preserves existing slow loop
/// for drivers that haven't overridden.
virtual bool waitDone(u32 timeoutMs) FL_NOEXCEPT {
return waitForReady(timeoutMs);
}
};Per-driver overrides (one-line thin wrappers for 5 of 7; ~20 LOC each for 2)
| Driver | Underlying primitive (already exists) | File | Effort |
|---|---|---|---|
| PARLIO | parlio_tx_unit_wait_all_done(unit, ms) |
src/platforms/esp/32/drivers/parlio/parlio_peripheral_esp.cpp.hpp:334 |
thin wrapper |
| RMT5 | rmt_tx_wait_all_done(channel, ms) |
src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp |
thin wrapper |
| LCD_SPI / LCD_CLOCKLESS | xSemaphoreTake(mCompleteSem, ticks) |
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp:452 |
thin wrapper |
| I2S_SPI | xSemaphoreTake(mCompleteSem, ticks) |
src/platforms/esp/32/drivers/i2s_spi/i2s_spi_peripheral_esp.cpp.hpp:556 |
thin wrapper |
| SPI clockless | spi_device_get_trans_result(handle, &t, ms) |
src/platforms/esp/32/drivers/spi/spi_peripheral_esp.cpp.hpp:283 |
thin wrapper |
| I2S LCD_CAM | currently polls mBusy with vTaskDelay(1) |
src/platforms/esp/32/drivers/i2s/i2s_lcd_cam_peripheral_esp.cpp.hpp:278 |
add binary sem, give-in-ISR, take-in-wait (~20 LOC) |
| LCD_RGB | currently polls mBusy with task::run(250, SYSTEM) |
src/platforms/esp/32/drivers/lcd_cam/lcd_rgb_peripheral_esp.cpp.hpp:248 |
add binary sem, give-in-ISR, take-in-wait (~20 LOC) |
Teensy / bare-metal overrides
Teensy drivers (ObjectFLED, FlexIO, OctoWS2811 path) already set a volatile completion flag in their DMA-done ISR. waitDone override is a busy-poll on that flag:
bool waitDone(u32 timeoutMs) FL_NOEXCEPT override {
u32 start = millis();
while (!mDmaComplete) {
if (timeoutMs && (millis() - start) >= timeoutMs) return false;
yield();
}
return true;
}No FreeRTOS dependency. Future enhancement: replace yield() with a __WFE/__SEV block-until-interrupt for low-power (see #2815 "Future / orthogonal work").
Manager-side fast-path
// src/fl/channels/manager.cpp.hpp
bool ChannelManager::waitForReady(u32 timeoutMs) FL_NOEXCEPT {
// Pre-pass: classify drivers via cheap poll().
IChannelDriver* active[8];
size_t n = 0;
for (const auto& e : mDrivers) {
if (!e.enabled) continue;
auto s = e.driver->poll();
if (s.state == DriverState::READY) continue;
if (s.state == DriverState::ERROR) return false;
if (n < 8) active[n++] = e.driver.get();
}
if (n == 0) return true;
if (n == 1) return active[0]->waitDone(timeoutMs); // FAST PATH — direct ISR-driven Take
// N > 1 — fall through to Phase-1 tiered wait until Phase 3 lands.
return waitForCondition(/* same as today */, timeoutMs);
}Test plan
Host-side (tests/test_channel_wait_done.cpp, new file):
- Mock
IChannelDriverwith awaitDoneoverride that returns after a configurable delay. - Assert: 1 active mock → manager bypasses tiered loop, returns within mock's delay + 50 µs.
- Assert: 2 active mocks → manager falls through to tiered wait, returns when both done.
- Assert: default
waitDone(no override) delegates to legacywaitForReady.
On-device (extend examples/AutoResearch/AutoResearch.ino):
--timing-driftmode from Phase 1 should improve further: single-driver 35-LED WS2812BFastLED.show()latency drops from "transmit + ε" to "transmit + ε (ISR-bounded)".- New
--multi-drivermode: register two drivers (e.g. RMT5 + PARLIO on ESP32-S3 alternatives, or LCD_SPI + RMT5 on ESP32-S3), kick off concurrent transmits, verify aggregate wait still works via the tiered fallback. - Measure ESP32-S3 with WiFi connected: confirm websocket throughput unchanged from ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 baseline.
Acceptance criteria
IChannelDriver::waitDone(u32 timeoutMs)exists as a virtual; default delegates towaitForReady.- All 7 ESP32 drivers override
waitDoneas semaphore-backed wait (or thin wrapper over IDF semaphore-backed primitives). - Teensy 4 drivers (ObjectFLED at minimum) override
waitDoneas flag-polling. ChannelManager::waitForReadyshort-circuits toactive[0]->waitDone(timeoutMs)when exactly one driver is BUSY.- ESP32-S3 single-strip 35-LED WS2812B
show()wall time ≤ 1.1 ms (Phase 1 acceptance was ≤ 1.3 ms — Phase 2 tightens by skipping the 250 µs spin). - ESP32-S3 with WiFi connected → no regression vs Phase 1.
- Multi-driver case (N≥2) on ESP32-S3 falls through to Phase 1 tiered wait — no regression.
- Teensy 4 ObjectFLED: no regression;
waitDonebusy-poll matches current behavior. - RMT4 path (legacy IDF v4 platforms): default
waitDonedelegates to existingwaitForReady— no regression.
Out of scope (Phase 3+)
- Multi-driver fan-in via shared sem or task notification → Phase 3 (sem-assisted poll preferred per perf(channels): replace =1 FreeRTOS-tick busy-sleep in waitForReady with ISR-completion + NetworkDetector-gated yield (refs #2420, #2254, #2493) #2815 Option A).
- Decoupled async
show()→ Phase 4.
Cross-references
- perf(channels): replace =1 FreeRTOS-tick busy-sleep in waitForReady with ISR-completion + NetworkDetector-gated yield (refs #2420, #2254, #2493) #2815 — design rationale
- perf(channels): Phase 1 of #2815 - tiered wait + NetworkDetector-gated yield #2818 — Phase 1 (must land first; provides the spin/yield fallback that Phase 2 still uses for N>1)
- [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 — reporter's bug (Phase 2 is the ultimate fix; Phase 1 brings it to ~1.3 ms, Phase 2 brings it to ~1.05 ms)
- ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 — WiFi cooperator invariant (preserved via sem Take semantics; see perf(channels): replace =1 FreeRTOS-tick busy-sleep in waitForReady with ISR-completion + NetworkDetector-gated yield (refs #2420, #2254, #2493) #2815 synthesis comment)
- ESP32-P4 PARLIO: FastLED.show() appears to block for ~16.7 ms before WS2812 data burst begins #2493 — PARLIO timing (already addressed by Phase 1; Phase 2 further tightens)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(channels): add waitDone() virtual + manager N=1 fast path (Phase…
Merge pull request #2828 from FastLED/feat/channels-waitdone-2819-v2