Skip to content

fix(channels): skip vTaskDelay(1) floor in wait-loop on ESP32-P4 (#2493 follow-up) - #2503

Merged
zackees merged 1 commit into
masterfrom
channels-p4-wait-loop-yield-2493
May 24, 2026
Merged

zackees merged 1 commit into
masterfrom
channels-p4-wait-loop-yield-2493

Conversation

@zackees

@zackees zackees commented May 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Root cause walk

FastLED.show()
 └─ ChannelManager::waitForReady()                  manager.cpp.hpp:402
     └─ waitForCondition()                          manager.cpp.hpp:349
         └─ task::run(250, SYSTEM)                  manager.cpp.hpp:362  ◄── per iter
             └─ pumpCoroutines(250)                 coroutine_esp32.impl.hpp:62
                 ├─ tick_period_us = 1_000_000 / CONFIG_FREERTOS_HZ
                 │                 = 1_000          (P4 ships 1 kHz)
                 ├─ ticks = 250 / 1000 = 0
                 ├─ if (ticks == 0) ticks = 1;
                 └─ vTaskDelay(1)                   = 1 ms minimum sleep

For 12 strips × 256 WS2812B: DMA drain ≈ 7.7 ms, wait-loop polls once per ms → ~8 iterations × 1 ms ≈ 8 ms wasted on top of DMA → total ≈ 16 ms. Matches #2493 reported timing exactly.

Expected impact

Workload Before After
P4, 12×256 PARLIO FastLED.show() ~16.7 ms ~7.7 ms (DMA only)
Other platforms unchanged unchanged

Test plan

Context

#2493 was closed by #2498 (8d4e8ef), which addressed the driver-registration symptom (LEDs not pushing data). That commit did not touch the wait-loop timing path. This PR addresses the residual timing issue called out in the issue thread by @zackees (P4 doesn't need the deep yield).

Discovered while looking at #2493 on attached hardware. The companion build-system PR is #2502 (library.json srcFilter for fast_isr.S), needed to even link P4 builds on a clean tree.

Refs: #2493, #2254, #2420, #2498, #2502

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized polling behavior for platform-specific performance. Different hardware platforms now implement tailored yielding strategies to improve responsiveness and efficiency during channel operations.

Review Change Stack

… follow-up)

ChannelManager::waitForCondition and IChannelDriver::waitForCondition
call task::run(250, SYSTEM) once per iteration to keep WiFi/lwIP alive
while polling. On ESP32-P4 at CONFIG_FREERTOS_HZ=1000 this floor-rounds
to vTaskDelay(1) = 1 ms minimum per iteration (see
coroutine_esp32.impl.hpp:65-86, the "if (ticks == 0) ticks = 1" branch
added for the #2254 I2S websocket starvation fix).

For 12-strip x 256-LED PARLIO sketches the wait loop iterates ~7-8
times during DMA drain, adding ~8 ms per frame on top of the ~7.7 ms
hardware DMA -- matching the ~16.7 ms FastLED.show() time reported in
issue #2493.

ESP32-P4 ships with no built-in WiFi, no Bluetooth, and no lwIP, so
the original "let lwIP run" rationale does not apply. taskYIELD()
(task::run(0, SYSTEM)) is sufficient: equal-priority tasks still get
CPU, the PARLIO ISR keeps draining DMA, and the per-iteration cost
drops from 1 ms to sub-microsecond.

Other platforms keep the existing vTaskDelay(1) floor unchanged so the
#2254 fix remains in place wherever WiFi/lwIP can actually run.

Refs: #2493, #2254, #2420

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown

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: 94d8f58f-f18a-4c81-9f4a-6d0963e623a1

📥 Commits

Reviewing files that changed from the base of the PR and between d252b35 and 9d71de0.

📒 Files selected for processing (2)
  • src/fl/channels/driver.cpp.hpp
  • src/fl/channels/manager.cpp.hpp

📝 Walkthrough

Walkthrough

Both driver and manager channel components add platform-aware polling yield logic. When the FL_IS_ESP_32P4 macro is active, the polling loops yield with zero delay; otherwise they yield with 250 microseconds to maintain OS and network stack responsiveness.

Changes

ESP32-P4 Polling Yield Optimization

Layer / File(s) Summary
Driver polling yield optimization
src/fl/channels/driver.cpp.hpp
Driver waitForCondition includes platforms/is_platform.h and conditionally applies task::run(0, ...) on ESP32-P4 or task::run(250, ...) on other platforms within its polling loop.
Manager polling yield optimization
src/fl/channels/manager.cpp.hpp
Manager waitForCondition includes platforms/is_platform.h and conditionally applies task::run(0, task::ExecFlags::SYSTEM) on ESP32-P4 or task::run(250, task::ExecFlags::SYSTEM) on other platforms within its polling loop.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • FastLED/FastLED#2350: Both PRs modify task::run(...) yielding behavior in polling loops; this PR changes call-site microsecond values conditionally on FL_IS_ESP_32P4, while the related PR refines executor semantics for the microsecond parameter.

Poem

🐰 On ESP32-P4, we yield with zero—
speedy, responsive, the platform's hero!
For other boards, 250 keeps the stack alive,
balanced and thoughtful, the channels thrive.
A conditional yield, both fair and bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 change: replacing task::run(250) with task::run(0) to skip the 1ms vTaskDelay floor in wait-loops on ESP32-P4, which directly addresses the timing regression documented in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 channels-p4-wait-loop-yield-2493

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.

@zackees
zackees merged commit fee2372 into master May 24, 2026
6 of 8 checks passed
zackees added a commit that referenced this pull request May 24, 2026
Adds an end-to-end sweep that does not depend on host-side serial
(which is the second blocker in #2507 — USB-Serial-JTAG produces no
host-visible bytes after Arduino boot on this dev board).

examples/PerfTraceBench/PerfTraceBench.ino:
  - 12 lanes × 256 LEDs WS2812B (override NUM_STRIPS / NUM_LEDS / NUM_FRAMES)
  - Per-frame: clear/enable fl::PerfTrace, FastLED.show(), snapshot the
    event log + show_us into a packed binary buffer
  - After NUM_FRAMES frames, write the buffer to the first writable data
    partition (esp_partition_find_first) and halt

ci/perf_trace_decode.py:
  - Parses the flash dump (magic-tagged header / frame / event records +
    string-interned name table) and renders a per-frame table

Usage:
  pio run -e esp32p4 --target upload  (with PLATFORMIO_SRC_DIR=examples/PerfTraceBench)
  esptool --chip esp32p4 --port COMxx read-flash <part_offset> <size> dump.bin
  uv run ci/perf_trace_decode.py dump.bin

Result on ESP32-P4-EV (12×256, build off this branch):
  show_us steady-state ≈ 1,058,000 µs per frame
  ChannelManager::waitForCondition (manager.cpp.hpp:353) ≈ 755,000 µs of that
  showLedsInternal ≈ 3,200 µs, onBeginFrame ≈ 30 µs, all other scopes <10 µs

The #2503 fix targeted the polling-loop yield (driver.cpp.hpp:23), but
the per-frame budget is dominated by the OTHER waitForCondition (line
353 in manager.cpp.hpp), so the PARLIO blocking issue from #2493 IS NOT
fully resolved. ~755 ms per frame is 100× the expected WS2812B PARLIO
drain time (~7.6 ms for 256 LEDs).

Refs: #2493 #2494 #2503 #2507

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the channels-p4-wait-loop-yield-2493 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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant