Skip to content

test(autoresearch): report instructions per show() from the RISC-V perf counter (#5375) #5376

Closed

Description

@zackees

Sub-issue of #5375 (meta), part of #5356.

Problem

Every other sub-issue under this meta issue changes show() by about 5–10% of its instructions. Code layout alone moves wall time by 10–20 µs between builds, so a single change of that size can't be shown on wall time. #5362 merged on a layout-only "win" that disappeared on the next build of master.

The ESP32-C6's custom performance counter gives an instruction count per show() that layout doesn't change. #5364's 14,439 → 12,953 was measured this way. Today the counter only exists as a scratch patch that has never been committed.

The standard minstret/mcycle CSRs can't be used: reading them traps on the C6 and the board reboots.

Fix

Add an opt-in counter to AutoResearch's timingDriftTest:

  • Read the Espressif RISC-V counter CSRs around each FastLED.show():
    • PCER 0x7E0 selects the event (bit 0 cycles, bit 1 instructions);
    • PCMR 0x7E1 enables counting;
    • PCCR 0x7E2 holds the count.
  • Return the mean cycles and mean instructions per show() in the RPC result.
  • Compile it only on ESP32 RISC-V targets that have these CSRs (C3, C6, H2). The ESP32-P4 has a different core and counter set; it is out of scope here and reports no counter fields. Every other target returns no counter fields.
  • Print the means from ci/autoresearch/show_latency.py next to the mean wall time. Optionally add a bash autoresearch ... --show-ipc style flag so a PR can paste the numbers.

Acceptance

  • On the C6, the AutoResearch run prints instructions per show() and the number is stable within ±1% across two runs of the same build.
  • Rebuilding with an unrelated change that only moves code doesn't change the instruction count by more than ±1%.
  • Other boards are unaffected; their runs still pass.

Rules for this sub-issue (from the meta issue)

  • Keep the layered architecture. Fix this inside its layer. Don't bypass ChannelManager or the channel engine.
  • Accept on instructions, not wall time. Measure instructions per show() on the ESP32-C6 before and after. Use bash autoresearch esp32c6 --legacy --rmt with the counter from the measurement sub-issue. Put both numbers in the PR. Code layout alone moves wall time by 10–20 µs between builds, so a wall-time number on its own can't show a 5–10% cut.
  • Usual gates:
    • bash test --cpp;
    • bash lint;
    • a passing AutoResearch run with the show() latency gate on;
    • bash bloat esp32s3 --build, with no growth past the ratchet.
  • Keep it small. Don't grow the binary on small-memory tiers (AVR, ATtiny). If a new bulk kernel doesn't pay for itself on FL_PLATFORM_HAS_TINY_MEMORY builds, compile it out of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions