Repository navigation
fix(esp32-s3,i2s): restore websocket throughput when I2S driver is active (#2254) - #2350
Conversation
…tive (#2254) Restores WiFi / Ethernet / lwIP throughput on ESP32-S3 when the I2S LCD_CAM channel driver (and any other driver that spin-waits on DMA via `task::run(us, ExecFlags::SYSTEM)`) is active. Addresses **Issue 1** of #2254. Two regressions made the cooperative yield path degenerate back into `taskYIELD()`, which does NOT yield to lower-priority tasks: 1. **Tick-rate truncation** in `pumpCoroutines()`. On the default ESP-IDF tick rate of 100 Hz, `tick_period_us = 10000`, so a sub-tick request such as `pumpCoroutines(1000)` computed `ticks = 0` and fell through to `taskYIELD()`. Arduino-ESP32 at 1000 Hz tick happened to work; ESP-IDF-native projects (MoonLight among them) hit the bad path and saw ~1 FPS websockets while LEDs rendered correctly. 2. **Over-narrow deep-yield gate** in `task::run(us, ExecFlags::SYSTEM)`. The SYSTEM yield only took the deep path when `esp_wifi_get_mode() != WIFI_MODE_NULL`. That condition misses: - Ethernet-only deployments (no WiFi mode, but lwIP is live). - The pre-`WiFi.begin()` window where the mode is still WIFI_MODE_NULL but network stacks may be initializing. - Weak-linkage edge cases where `esp_wifi_get_mode` resolves to nullptr even when WiFi is in use. Fix: - `src/platforms/esp/32/coroutine_esp32.impl.hpp`: `pumpCoroutines()` now rounds a non-zero microseconds request UP to at least 1 FreeRTOS tick. `us == 0` still just does `taskYIELD()`. - `src/fl/task/executor.cpp.hpp`: `task::run(us, ExecFlags::SYSTEM)` takes the deep-yield path whenever `microseconds > 0`, independent of WiFi mode. This is the path used by every driver's DMA spin-wait (I2S, SPI, LCD_SPI, LCD_CLOCKLESS, LCD_RGB, PARLIO, RMT, UART, I2S_SPI) and by `FastLED.show()`'s minFPS wait. Net effect: any spin-wait loop that calls `task::run(>0, SYSTEM)` now guarantees at least one FreeRTOS tick of delay per iteration on ESP32, freeing the CPU for lwIP / WiFi / Ethernet tasks. Validation on attached ESP32-S3: - `bash test --cpp`: 301/301 tests pass - `bash autoresearch esp32s3 --net`: 3/3 HTTP loopback tests PASS - `bash autoresearch esp32s3 --rmt --strip-sizes 100`: PASS (1 test, 103ms) - `bash autoresearch esp32s3 --spi --strip-sizes 100`: PASS (2/2 frames) - `bash autoresearch esp32s3 --lcd`: pre-existing harness RPC timeout (same behavior on master, unrelated to this fix) This is a re-application of the diff from the previously-closed PR #2290. Refs #2254 Co-Authored-By: Claude Opus 4.7 (1M context) <[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 (2)
📝 WalkthroughWalkthroughThis PR modifies SYSTEM-level yield behavior in the task executor and ESP32 coroutine runtime. The executor now unconditionally uses Changes
Possibly related issues
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 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 |
📊 Header Compilation PerformanceTotal Time: 1277.88ms Top 5 Slowest Headers
Warnings
Full Report |
Summary
Restores WiFi / Ethernet / lwIP throughput on ESP32-S3 when the I2S LCD_CAM channel driver (and any other driver that spin-waits on DMA via
task::run(us, ExecFlags::SYSTEM)) is active. Addresses Issue 1 of #2254.This is a re-application of the diff from the previously-closed PR #2290 — the code fix itself reviewed cleanly; this PR adds the on-device validation that was marked as "USER action required" in that PR.
Sub-issues from #2254
Root cause
Two regressions made the cooperative yield path degenerate back into
taskYIELD(), which does NOT yield to lower-priority tasks:Tick-rate truncation in
pumpCoroutines(). On the default ESP-IDF tick rate of 100 Hz,tick_period_us = 10000, so a sub-tick request such aspumpCoroutines(1000)computedticks = 0and fell through totaskYIELD(). Arduino-ESP32 at 1000 Hz tick happened to work; ESP-IDF-native projects (MoonLight among them) hit the bad path and saw ~1 FPS websockets while LEDs rendered correctly.Over-narrow deep-yield gate in
task::run(us, ExecFlags::SYSTEM). The SYSTEM yield only took the deep path whenesp_wifi_get_mode() != WIFI_MODE_NULL. That condition misses:WiFi.begin()window where mode is stillWIFI_MODE_NULLbut network stacks may be initializing.esp_wifi_get_moderesolves tonullptreven when WiFi is in use.Fix (2 files, +35 / -9)
src/platforms/esp/32/coroutine_esp32.impl.hpp—pumpCoroutines()now rounds a non-zero microseconds request UP to at least 1 FreeRTOS tick. Aus == 0request still just doestaskYIELD().src/fl/task/executor.cpp.hpp—task::run(us, ExecFlags::SYSTEM)takes the deep-yield path whenevermicroseconds > 0, independent of WiFi mode. This is the path used by every driver's DMA spin-wait (I2S, SPI, LCD_SPI, LCD_CLOCKLESS, LCD_RGB, PARLIO, RMT, UART, I2S_SPI) and byFastLED.show()'s minFPS wait.Net effect: any spin-wait loop that calls
task::run(>0, SYSTEM)now guarantees at least one FreeRTOS tick of delay per iteration on ESP32, freeing the CPU for lwIP / WiFi / Ethernet tasks.Validation on attached ESP32-S3
Run against the attached ESP32-S3 device over COM13 (all
--no-fbuild --skip-lint):bash test --cppbash autoresearch esp32s3 --netbash autoresearch esp32s3 --rmt --strip-sizes 100bash autoresearch esp32s3 --spi --strip-sizes 100bash autoresearch esp32s3 --lcd--lcdand--lcd-spiboth stall at RPC ID 3 on current master, before and after this patchThe fact that
--net(HTTP loopback) continues to PASS is the key signal for Issue 1: the lwIP path functions correctly while the device is continuously running tasks. RMT and SPI driver tests confirm the fix does not break any driver path that shares thetask::run(250, SYSTEM)spin-wait pattern.Per-iteration cost of the fix: one FreeRTOS tick (~10 ms on 100 Hz, ~1 ms on 1 kHz) per spin-wait pass vs. the old busy-spin degenerate path. This is a trade-off and should be a net win because DMA typically takes longer than one tick anyway, and the extra tick gives lwIP a chance to drain its socket queue.
Not addressed in this PR
Fixes Issue 1 of #2254.
🤖 Generated with Claude Code
Summary by CodeRabbit