Repository navigation
perf(channels): add Tier-2 microsecond spin to waitForCondition (Phase 1 of #2815, Closes #2818) - #2827
Conversation
…e 1 of #2815, Closes #2818) Builds on #2817 (runtime NetworkDetector-gated yield) by inserting a bounded microsecond spin tier *before* the cooperator yield. The combined wait now has three tiers: Tier 1 - instant non-blocking condition check (free fast path) Tier 2 - bounded microsecond spin (FASTLED_WAIT_SPIN_BUDGET_US, default 250 us) [NEW] Tier 3 - NetworkDetector-gated cooperator yield (already merged via #2817) Tier 2 catches short DMA tails (APA102 small strips, WS2812B <=8 LEDs) without paying even the no-radio fast yield's per-iteration overhead. For the #2420 reporter's 35-LED WS2812B sketch (~1.05 ms transmit), the new tier eliminates the residual drift around the transmit boundary. Public API on CFastLED (per the Public Settings Pattern): - setWaitSpinBudgetUs(N) / getWaitSpinBudgetUs() runtime setter. - FASTLED_WAIT_SPIN_BUDGET_US compile-time default (250 us). - Set to 0 to disable the spin tier entirely. Implementation lives in fl/channels/detail/wait_spin_budget.{h,cpp.hpp} with atomic storage (fl::atomic<u32>) so concurrent reads in the wait loop do not race against a writer in setWaitSpinBudgetUs. Also fixes a small lint regression from #2817's fl/net/network_detector.h (IWYU pragma blocks around platform headers, FL_NOEXCEPT on deleted special members). Closes #2818. Refs #2815. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Linter diff in the way? Review this PR in Change Stack to focus on meaningful changes and expand context only when needed. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR introduces a tiered-wait spin budget mechanism that allows channel-manager and driver wait loops to spend up to 250 µs (by default, configurable) spinning before entering the FreeRTOS cooperator yield tier. The feature reduces latency for short-duration waits without incurring the minimum ≥1 ms FreeRTOS tick floor. ChangesTiered-wait spin budget
Sequence DiagramsequenceDiagram
participant Caller
participant WaitLoop
participant SpinBudget
participant YieldLoop
Caller->>WaitLoop: waitForCondition(condition, timeoutMs)
WaitLoop->>WaitLoop: Tier 1: instant check condition()
alt condition satisfied immediately
WaitLoop-->>Caller: return true
else
WaitLoop->>SpinBudget: getWaitSpinBudgetUs()
SpinBudget-->>WaitLoop: budget_us (default 250)
WaitLoop->>WaitLoop: Tier 2: spin up to budget_us
alt condition satisfied in spin phase
WaitLoop-->>Caller: return true
else
alt timeout exceeded in spin phase
WaitLoop-->>Caller: return false (timeout error)
else
WaitLoop->>YieldLoop: Tier 3: existing yield/cooperator loop
YieldLoop-->>Caller: return true or false
end
end
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly Related Issues
Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Summary
Phase 1 of #2815 / Closes #2818. Builds on the already-merged #2817 by inserting a Tier-2 microsecond spin between the instant check and the cooperator yield.
The combined wait in
ChannelManager::waitForConditionandIChannelDriver::waitForConditionnow has three tiers:condition()check (free fast path)FASTLED_WAIT_SPIN_BUDGET_US, default 250 us)vTaskDelaywhen radio active)Tier 2 catches short DMA tails - APA102 small strips and WS2812B <=8 LEDs complete entirely inside the spin without paying the cooperator yield's per-iteration overhead. For the #2420 reporter's 35-LED WS2812B sketch (~1.05 ms transmit), Tier 2 + #2817's no-radio fast yield eliminate the residual drift around the transmit boundary.
Public API (Public Settings Pattern on CFastLED)
Files
src/fl/channels/detail/wait_spin_budget.hfl::detail::{get,set}WaitSpinBudgetUssrc/fl/channels/detail/wait_spin_budget.cpp.hppfl::atomic<u32>), default 250 ussrc/fl/channels/detail/_build.cpp.hppsrc/fl/channels/manager.cpp.hppsrc/fl/channels/driver.cpp.hppsrc/FastLED.hsetWaitSpinBudgetUs(N)/getWaitSpinBudgetUs()setters onCFastLEDvia forward shimssrc/FastLED.cpp.hppfl::detail::{get,set}WaitSpinBudgetUssrc/fl/net/network_detector.hTest plan
Host
bash test --cpp- 309/310 pass. The one failure (spi_pingpong_pipeline_logic) is pre-existing in feat(spi,esp32): pre-queue alternate-buffer SPI chunk for >680-LED strips (refs #2304) #2810 and is a pure simulation-model loop that does not exerciseFastLED.*,waitFor*, orChannelManager- verified independent.bash lint --cpp- down from 12 violations on master baseline to 1 (a pre-existingSubdirNamespaceCheckercomplaint aboutfl/net/network_detector.husingfl::instead offl::net::; that would be an API rename for perf(channels): runtime NetworkDetector-gated yield in waitForCondition (refs #2815) #2817's facade and is out of scope here).Hardware (to follow / Phase 2)
WiFi.begin()- confirm timing drift fix from [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420.yield()).Cross-references
Phase 2 (#2819) -
waitDone()virtual + per-driver ISR fast path - is a separate follow-up PR.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
setWaitSpinBudgetUs()andgetWaitSpinBudgetUs()). Default is 250 µs; set to 0 to disable spinning.Performance