Skip to content

perf(parlio) + lint: gate eager-queue to fits-in-ring frames + ban esp_rom_printf - #2581

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-eager-queue-preserve-streaming
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-eager-queue-preserve-streaming

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Two related changes

1 — Engine: gate eager-queue so chunked streaming still works for large frames

#2565 turned eager-queue ON by default to overlap encode with TX. That's correct for frames that fit in the engine's 3-buffer ring — encoding completes before any TX submit, the loop drains mRingCount → 0, IDF chains buffers via DMA descriptors, all good.

But for larger frames (long LED strips that exceed the ring's capacity), the engine relies on chunked streaming: beginTransmission() encodes one chunk per ring slot, leaves mNextByteOffset < mTotalBytes, and expects txDoneCallback → workerIsrCallback to encode + submit the rest as TX drains. Eager-queue's drain-to-zero pattern corrupts this:

After eager-queue: mRingCount = 0 (engine ring empty) BUT IDF still has buffers in flight.
txDone for buf 0:  sees count==0 AND bytes_transmitted < total
                   → takes "ring empty but more data pending" branch
                   → sets mHardwareIdle = true / mTransmitting = false
                   → ❌ wrong: IDF is currently transmitting buf 1, hardware is NOT idle

Fix: only fire the eager-queue loop when mNextByteOffset >= mTotalBytes (whole frame already encoded). For streaming frames, fall back to one-submit-per-txDone.

Verified on P4 v1.3 16-lane × 256-LED (fits in ring):

steady_avg_total = 12 431 µs
steady_avg_show  = 10 817 µs
steady_avg_wait  =  1 613 µs   ← TX still overlaps with show()

Same as #2565 — fits-in-ring path preserved, large-frame streaming path no longer trips the broken state machine.

2 — Lint: ban raw esp_rom_printf

esp_rom_printf is a low-level ROM printf intended for very early boot diagnostics. It's been creeping into general code as a workaround for #2541 (testSimd RPC routing on P4). New checker ci/lint_cpp/esp_rom_printf_checker.py flags it anywhere in src/ / examples/ / tests/. Suppress with // ok esp_rom_printf - <reason> on the same line.

Applied opt-out comments to 36 existing legitimate uses:

Smoke-tested: a fake violation in a scratch .cpp file is correctly flagged; the same line with the opt-out marker is not.

Test plan

  • bash lint --cpp clean (existing legitimate uses are suppressed, no new violations).
  • Standalone checker run: zero false positives across the whole tree.
  • Smoke test: fake violation correctly flagged; opt-out comment correctly allows.
  • Live device (ESP32-P4 v1.3) 16-lane × 256-LED bench shows encode/TX still interleaves with the new gate in place.

Files

 ci/lint_cpp/esp_rom_printf_checker.py                           +165
 ci/lint_cpp/run_all_checkers.py                                 +2
 src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp       +27 / −10
 src/platforms/esp/32/drivers/usb_serial_jtag_esp32_idf.hpp      (suppressions, no logic change)
 src/platforms/esp/32/detail/io_esp_jtag_or_uart.hpp             (suppressions, no logic change)
 examples/AutoResearch/AutoResearchParlioEncode.h                (suppressions, no logic change)
 examples/AutoResearch/AutoResearchWave8Expand.h                 (suppressions, no logic change)

Refs #2548, #2565.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Enhanced ESP32 USB-Serial JTAG initialization with improved diagnostic logging for backend selection and error detection.
    • Refined PARLIO transmission queue behavior for more efficient frame encoding and transmission.
  • Code Quality

    • Added new code linter to enforce logging best practices across the codebase.

Review Change Stack

…p_rom_printf

### 1. parlio_engine.cpp.hpp — gate eager-queue

PR #2565 turned eager-queue on by default to overlap encode with TX. That
works correctly for frames that FIT entirely in the engine's 3-buffer
ring — encoding completes before any TX submit, the loop drains
`mRingCount` to 0, IDF chains them via DMA descriptors, all good.

But for LARGER frames (long LED strips that exceed the ring's capacity)
the engine relies on chunked streaming: `populateDmaBuffer` encodes one
chunk per ring slot in `beginTransmission()`, leaves `mNextByteOffset <
mTotalBytes`, and expects `txDoneCallback` → `workerIsrCallback` to
encode + submit the rest as TX drains. Eager-queue's "drain mRingCount
to 0" pattern corrupts this:

  - After eager-queue, mRingCount = 0 but IDF still has buffers in flight.
  - txDoneCallback for buffer 0 sees count = 0 AND bytes_transmitted <
    total, takes the "ring empty but more data pending" branch.
  - That branch sets mHardwareIdle = true and mTransmitting = false even
    though IDF is currently transmitting buffer 1 — corrupting the state
    machine.

Fix: only fire the eager-queue loop when `mNextByteOffset >= mTotalBytes`
(i.e., the whole frame is already encoded). For streaming frames, fall
back to the existing one-submit-per-txDone pattern.

Verified on P4 v1.3 16-lane × 256-LED (fits in ring):

  steady_avg_total = 12 431 µs
  steady_avg_show  = 10 817 µs
  steady_avg_wait  =  1 613 µs   ← TX still overlaps with show()

Same numbers as PR #2565 — the fits-in-ring path is preserved. Large-
frame streaming path now no longer trips the broken state machine.

### 2. esp_rom_printf checker

Adds `ci/lint_cpp/esp_rom_printf_checker.py` to the custom-checker
chain. Flags any raw `esp_rom_printf(...)` call in `src/`, `examples/`,
or `tests/`. Suppress with `// ok esp_rom_printf - <reason>` on the
same line for legitimate cases.

Applied opt-out comments to the existing 36 legitimate uses:
  - `src/platforms/esp/32/drivers/usb_serial_jtag_esp32_idf.hpp` (17):
    USB-Serial-JTAG driver bootstrap, runs before logging is up.
  - `src/platforms/esp/32/detail/io_esp_jtag_or_uart.hpp` (2): same.
  - `examples/AutoResearch/AutoResearchParlioEncode.h` (10) and
    `AutoResearchWave8Expand.h` (7): boot-time bench output to COM25
    (testSimd RPC routing blocked by #2541).

Smoke-tested: a fake `esp_rom_printf` violation in a temp .cpp file is
correctly flagged; the same line with the opt-out comment is not.

Rationale (in checker docstring): esp_rom_printf bypasses FastLED's
logging infrastructure, blocks on a slow peripheral, and was creeping
into general code as a workaround for #2541. The opt-out keeps the
legitimate bootstrap callers explicit.

Refs #2548, #2565.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a4c3178-ae1f-4144-8d9b-02d850325baa

📥 Commits

Reviewing files that changed from the base of the PR and between 064354e and 950a931.

📒 Files selected for processing (7)
  • ci/lint_cpp/esp_rom_printf_checker.py
  • ci/lint_cpp/run_all_checkers.py
  • examples/AutoResearch/AutoResearchParlioEncode.h
  • examples/AutoResearch/AutoResearchWave8Expand.h
  • src/platforms/esp/32/detail/io_esp_jtag_or_uart.hpp
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • src/platforms/esp/32/drivers/usb_serial_jtag_esp32_idf.hpp

📝 Walkthrough

Walkthrough

This PR introduces a new C/C++ linter to detect direct esp_rom_printf() calls, enforces it across the codebase via annotated opt-out markers, and refines PARLIO's eager-queue transmission behavior to gate buffer draining on whether the full frame fits within the engine's ring.

Changes

ESP ROM Printf Linter and Compliance

Layer / File(s) Summary
Linter Implementation and Integration
ci/lint_cpp/esp_rom_printf_checker.py, ci/lint_cpp/run_all_checkers.py
Introduces EspRomPrintfChecker class with regex pattern matching, multi-line comment-state tracking, and opt-out marker (// ok esp_rom_printf) recognition. Adds standalone CLI entry point for single-file checking and registration in the unified CI lint runner.
Boot Diagnostic Logging Compliance
examples/AutoResearch/AutoResearchParlioEncode.h, examples/AutoResearch/AutoResearchWave8Expand.h, src/platforms/esp/32/detail/io_esp_jtag_or_uart.hpp, src/platforms/esp/32/drivers/usb_serial_jtag_esp32_idf.hpp
Updates benchmark output and diagnostic logging across examples and platform drivers. Annotates approved esp_rom_printf calls with inline opt-out markers, adds detailed initialization/detection logging in USB-Serial JTAG driver, and reformats boot-time metric reporting while preserving computed values.

PARLIO Eager-Queue Refinement

Layer / File(s) Summary
Eager-Queue Frame-Fit Guard
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
Conditionally gates eager buffer draining in beginTransmission() on a frame_fits_in_ring check computed from ISR state (mNextByteOffset vs mTotalBytes). When true, remaining buffers are eagerly submitted; when false, chunked streaming path handles them. Updates surrounding compile-time documentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • FastLED/FastLED#2547: Updates printParlioEncodeResultRom output formatting and esp_rom_printf boot markers in the same benchmark file.
  • FastLED/FastLED#2565: Modifies PARLIO eager-queue enablement defaults and documentation in parlio_engine.cpp.hpp.
  • FastLED/FastLED#2564: Introduces the opt-in eager-queue implementation for encode/TX overlap that this PR refines.

Poem

🐰 A linter hops through code and calls,
To catch esp_rom_printf walls,
With comments wise: "ok, this one's blessed,"
While PARLIO queues pass the test!
Frame-fit and eager, transmitting with pride. ✨

✨ 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 perf/parlio-eager-queue-preserve-streaming

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 7df5ac9 into master May 30, 2026
6 of 7 checks passed
@zackees
zackees deleted the perf/parlio-eager-queue-preserve-streaming branch May 30, 2026 15:18
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