T-055 — Profiling on the Raspberry Pi 3: the whole engine, an A53 kernel, real-time behaviour and clock

Status: in progress — part A done (steps 1–4, on the maintainer’s Pi 3); part B waits for T-026 · Area: rust, piano · Depends on: T-028 (steps 1–2), T-008; part B also T-026

Read for that: T-011 §4 (the Pi run, its tables) and Decision, T-028 (build route D1, Outcome), Piano 13 (SIMD on stable Rust, Threads), Piano 14 (quality levels), P-004.

What: T-011 §4 measured only the string banks of the modal-bench spike on the Pi 3, without logging the CPU clock. Before T-028 step 4 fixes the Pi’s default quality level, measure what the instrument really costs there and whether the A53 can be made faster.

Part A — now (the engine crates/dsp exists; no standalone app needed):

  1. Clock and throttling: every Pi run logs vcgencmd measure_clock arm, vcgencmd measure_temp and vcgencmd get_throttled before, during (every 30 s) and after; governor performance. Repeat T-011’s scenario levels section with this log; if the clock dropped below 1.2 GHz or get_throttled is non-zero, the T-011 §4 numbers are corrected (heatsink/fan noted).
  2. The whole engine offline: a release binary in crates/dsp (an example next to chord_attack.rs) that renders the committed model through PianoEngine at 48 kHz, block 64, for T-011’s dense pedalled passage and a 10-note chord attack (hammer contact, dampers, pedal, per-key overhead included): RTF on one core, ns per resonator-sample, and the slowest block (not only the mean). Compare with modal-bench on the same Pi: what the engine adds over the bare banks.
  3. An A53 kernel: the in-order A53 ran plain loops as fast as pulp K=4 (2.25 ns both), i.e. latency-bound. In modal-bench, add pulp variants with more independent vectors in flight (K = 6, 8) and an interleaved update order, measure on the Pi and on the desktop. If one is clearly faster on the A53 without costing the desktop, propose it for crates/dsp (resonator.rs, K) — a real decision, so stop for the maintainer there.
  4. Where the time goes: perf record / perf stat (cycles, instructions, IPC, cache misses) on the engine binary on the Pi, if perf is available on Raspberry Pi OS; otherwise skip and say so.

Part B — after T-026 (standalone app) and T-028 step 3 (USB audio):

  1. Real-time callback: in the standalone app on the Pi, with a USB interface at 64 and 128 frames, 48 kHz: histogram of callback time against the deadline, xruns over a 30-minute dense passage, stock kernel vs PREEMPT_RT; with and without T-024’s threads if it exists by then.

Results go into a table here and, where they change a number, into T-011 §4, Piano 14’s Pi column, NS_PER_RES_SAMPLE in tools/piano_cost_model.py and P-004.

Done when: part A: the clock log shows the Pi ran at 1.2 GHz unthrottled (or T-011 §4 is corrected), the whole engine’s RTF and worst block on the Pi are entered here, the K = 6/8 kernels are measured on both machines with a recommendation; part B: callback-time histogram and xrun count at 64 and 128 frames are entered, and T-028 step 4 has the numbers it needs for the default level.

Outcome

Part A, measured 2026-12-05 on the maintainer’s Pi 3 Model B Rev 1.2 (4 × Cortex-A53 @ 1.2 GHz, 1 GB RAM, Raspberry Pi OS aarch64, idle; rustc 1.100.1; the binaries built on the Pi itself, baseline aarch64 target, pulp dispatches to NEON). The governor could not be set to performance (no sudo on the machine); it stayed ondemand, but the new scripts/pi-clock-log.sh (clock/temp/get_throttled before, every 30 s during, after) shows every run stayed at 1.2 GHz (lowest sample 1,199,998,000 Hz — measurement jitter, not a drop) with get_throttled = 0x0 throughout and a peak temperature of 62.3 °C. perf is not installed on this system — step 4 skipped (“perf not available”); raw outputs and clock logs are in spikes/modal-bench/results/2026-12-05-pi3-*.

1. Clock and throttling — T-011 §4 confirmed

The whole scenario binary re-run (11 min) under the clock log: clock 1.2 GHz, unthrottled, ≤ 62.3 °C. No T-011 §4 number needed correcting; the re-measured levels match within run-to-run variation (Ultra peak 1.40–1.43, High peak 0.63–0.65, both pulp and delta form; 50-key case 1.02–1.05). The “not logged” caveat on T-011 §4 is resolved.

2. The whole engine (committed model, PianoEngine, 48 kHz, block 64, one core)

New example crates/dsp/examples/pi_passage.rs (structure of chord_attack.rs): the committed model salamander-c5/2026-12-04 through the whole engine (bank: 7,904 modes; the model has 1 polarisation) — hammer contact, dampers, pedal, activity tracking and per-key overhead included, resonator counts mirrored from CoeffSet’s layout (modes below fs/2, spans padded to 16).

CaseResonators (real / padded)RTF one corens per resonator-sampleSlowest block
Dense pedalled passage (40 keys C2..C6 struck together, pedal down, 10 s)3,453 / 3,7440.887 (best of 3)5.35 (real)2,777 µs = 208 % of the 1.333 ms budget (block 0: all 40 keys in hammer contact)
10-note chord attack (first 5 ms, in contact), median of 1,000831 / 9120.32 (attack) / 0.21 (after contact)7.92 (attack) / 5.33 (after)734 µs = 55 % of budget
same chord, 5 ms after contact831 / 9120.2125.33—
  • All 40 passage keys were still sounding after 10 s (pedal down, no culling); the numbers are the sustained load, not a peak that decays away.
  • What the engine adds over the bare banks: ~5.3 ns per resonator-sample vs modal-bench’s 2.6–2.7 at comparable loads — ~2×: per-key block overhead (40 spans per block instead of one big bank), two output channels with four gains per mode, the contact kernel during the attack (chord ratio 1.49), and activity checks.
  • The worst block, not the mean, is the Pi’s problem: a 40-key peak attack (both hands, dense chord, pedal) takes 2.08× the 64-frame deadline on one core even though the mean RTF (0.887) fits. A single audio thread will drop out on such peaks; either T-024’s threads or the adaptive-quality safety net (Piano 14, saving 10) must cover the attack spikes.
  • Review (2026-12-05): the 208 % is one maximum over three runs, the cold first run included, and a single maximum also catches OS preemption: on the desktop VM the slowest block was 5–20× the mean at random block positions. The mean and the chord’s contact ratio gave a warm estimate of ≈ 0.887 × 1.49 ≈ 1.3× the deadline for a block with all 40 keys in contact — still over budget, so the conclusion stands. pi_passage now prints the slowest block per run (run 1 marked cold) and the chord’s 99.9th percentile; the re-run (§2b) replaces the 1.3× estimate with a measured warm value of 177–199 % of the deadline — the estimate was too low; the over-budget conclusion is unchanged.
  • Review (2026-12-05): what this means for the levels. The passage has ~86 resonators per key (3,453 / 40), close to Piano 14’s High at attack (4,580 / 40 ≈ 115), so the per-key overhead hardly amortises further at High. With 5.35 ns, tools/piano_cost_model.py gives (one core, peak / average, strings and sympathetic only, outside hammer contact): Ultra 304 / 161 %, High 126 / 56 %, Medium 69 / 25 %, Low 26 / 8 %. So on one thread Medium is the highest level that fits at peak; T-011 §4’s “High fits” holds for the bare banks only. T-028 step 4 decides between Medium and T-024.
  • Caveat: stage-1 engine — no sympathetic banks, soundboard or phantom partials yet, and the committed model has fewer resonators than the synthetic levels below. These numbers are the engine’s cost, not directly comparable to the level table’s bank counts.

2b. Re-run (2026-12-06) — the slowest block per run, warm vs cold

The updated pi_passage (no code change since; same binary behaviour, rebuilt) prints the slowest block of each of its three internal passage runs (run 1 cold) and the chord’s 99.9th percentile. Run three times on the Pi (idle, taskset -c 3, each under scripts/pi-clock-log.sh); every run valid: min_clock = 1.2 GHz, throttled_nonzero=none. Raw outputs and clock logs: spikes/modal-bench/results/2026-12-06-pi3-pi-passage-rerun-{1,2,3}-* (clock-log timestamps 2026-12-05 23:36–23:39 local). RTF 0.882–0.883, 5.32–5.33 ns per resonator-sample — the §2 means reproduce. Slowest block of the dense passage (budget 1.333 ms):

InvocationInternal runSlowest block% of budgetBlock index
11 (cold)2,657.8 µs199.3 %0
122,380.8 µs178.6 %0
132,376.9 µs178.3 %0
21 (cold)2,667.2 µs200.0 %0
222,646.0 µs198.5 %0
232,429.0 µs182.2 %0
31 (cold)2,630.4 µs197.3 %0
322,376.8 µs178.3 %0
332,361.6 µs177.1 %0

The 10-note chord’s contact blocks (4,000 blocks per invocation): 99.9th percentile 686.4 / 704.5 / 705.0 µs = 51.5 / 52.8 / 52.9 % of the budget (invocations 1/2/3), slowest 726.1 / 890.0 / 764.2 µs (54.5 / 66.7 / 57.3 %).

  • The warm slowest block is block 0 in all nine internal runs — a block with all 40 keys in hammer contact, a deterministic cost of the attack, not OS jitter. Its warm value is 2,362–2,646 µs = 177–199 % of the deadline (median 2,379 µs ≈ 178 %): the review’s ~1.3× estimate was too low — the 40-key contact block costs ~1.8–2.0× the deadline, and the chord’s 10-key ratio (1.49) does not extrapolate to 40 keys. Review: the estimate’s error was the averaging, not the key count — 1.49 is the mean over the 4-block contact window, during which keys leave contact, while block 0 has every key in contact (and takes the note-ons). Scaling the chord’s own block-0 cost instead (99.9th percentile ~700 µs × 3,453 / 831 resonators ≈ 2.9 ms ≈ 2.2× the deadline) predicts the passage’s block 0 to within ~20 %: the attack block grows about linearly with the resonators struck in it.
  • Cold vs warm: the cold run is the highest in invocations 1 and 3 (199.3 % and 197.3 % vs 178 % warm), but only ~10 % above the best warm run — and in invocation 2 one warm run (198.5 %) nearly matched the cold one. The cold/warm difference is small next to the over-budget gap itself.
  • Jitter: the chord’s slowest block is close to its 99.9th percentile (726 vs 686 µs, 764 vs 705 µs) except for one outlier (890 vs 705 µs, invocation 2) — one OS preemption among 4,000 blocks. Contact-block times are otherwise tight, so the passage’s block-0 values above are engine cost, not preemption.

2c. RT vs stock kernel (2026-12-06)

T-028’s D3 put the Pi on the PREEMPT_RT kernel for latency; this addendum measures whether that costs engine throughput (T-028 Outcome, the D3 bullet’s open question). Same clean setup on both kernels: governor performance, core 3 isolated (isolcpus=3), chrt -f 80 taskset -c 3, machine idle, every run under the clock log — all six runs valid (min_clock 1.2 GHz, throttled_nonzero=none). Kernels: RT kernel8_rt.img (6.18.65-rt; uname -v = #1 SMP PREEMPT_RT Debian 1:6.18.65-1+rpt1 (2026-11-27)) vs stock kernel8.img (6.18.65; uname -v = #1 SMP PREEMPT Debian 1:6.18.65-1+rpt1 (2026-11-27)). Same binary as §2b (no code change, rebuilt). (The RT kernel’s first boot came up with governor ondemand despite cpufreq.default_governor=performance in cmdline.txt; a reboot brought it up as performance — no measurement was taken on the ondemand boot. Raw outputs and clock logs: spikes/modal-bench/results/2026-12-06-pi3-pi-passage-{rt,stock}-{1,2,3}-*.)

RT kernel (PREEMPT_RT 6.18.65):

InvocationRTFns/res-sampleSlowest warm block (runs 2/3)% of budgetChord p99.9
10.8935.392,382.1 / 2,407.3 µs178.7 / 180.6 %660.8 µs (49.6 %)
20.8875.352,462.9 / 2,362.2 µs184.7 / 177.2 %642.7 µs (48.2 %)
30.8875.352,378.9 / 2,377.7 µs178.4 / 178.3 %667.4 µs (50.1 %)

Cold run 1: 2,710.3 / 2,620.1 / 2,637.0 µs = 203.3 / 196.5 / 197.8 % (invocations 1/2/3). Chord’s slowest block: 787.7 / 657.7 / 695.4 µs.

Stock kernel (6.18.65):

InvocationRTFns/res-sampleSlowest warm block (runs 2/3)% of budgetChord p99.9
10.8855.342,359.7 / 2,349.1 µs177.0 / 176.2 %696.0 µs (52.2 %)
20.8865.342,358.6 / 2,958.4 µs176.9 / 221.9 %679.6 µs (51.0 %)
30.8875.352,356.3 / 2,347.5 µs176.7 / 176.1 %708.9 µs (53.2 %)

Cold run 1: 2,590.2 / 2,598.8 / 2,557.1 µs = 194.3 / 194.9 / 191.8 %. Chord’s slowest block: 744.0 / 718.2 / 722.4 µs.

  • The RT kernel costs no measurable engine throughput. RTF 0.887–0.893 vs 0.885–0.887, 5.35–5.39 vs 5.34–5.35 ns per resonator-sample (min-max over the invocations) — the ranges overlap within the day’s between-invocation spread (RTF varied 0.885–0.893 across all six runs); the worst-case difference is ~0.5 %. D3’s RT kernel is free for the engine — the Pi keeps it.
  • Block 0 unchanged; no tail difference shown. The slowest block is block 0 (all 40 keys in hammer contact) in all 18 internal runs on both kernels, warm 2,348–2,463 µs = 176–185 % — deterministic engine cost, kernel-independent. The stock kernel produced one warm outlier (2,958.4 µs = 221.9 %, invocation 2, run 3), and the chord’s 99.9th percentile is ~5 % lower on RT (643–667 vs 680–709 µs), but the RT runs also had the single slowest chord block (787.7 µs) — with nine warm blocks per kernel, one outlier is not evidence that RT tightens the block-time tail. On the isolated core at FIFO 80 both kernels are quiet; RT’s latency advantage on loaded cores is D3’s cyclictest result, and T-055 part B’s 30-minute run is the test for the tail. (Review 2026-12-06: this bullet first claimed RT removes the spikes.)
  • The clean stock setup changes no §2b mean. §2b (stock kernel, governor ondemand, no isolated core, no chrt) measured RTF 0.882–0.883, 5.32–5.33 ns per resonator-sample; the clean stock runs give 0.885–0.887 and 5.34–5.35 — differences of ≤ 0.5 %, within run-to-run spread. The performance governor, the isolated core and FIFO 80 buy nothing for throughput because ondemand already held 1.2 GHz under this load (every clock log confirmed it); §2b’s numbers stand as a baseline for the means, and the warm block-0 range matches too (§2b 177–199 % vs 176–177 % here bar the one outlier — §2b’s 198.5 % top end was probably jitter). Piano 14 and P-004 keep their numbers: nothing moved by more than the spread.

3. A53 kernels: K = 6 and 8 (delta form) — K = 4 stays

Added DeltaPulp6/DeltaPulp8 to modal-bench (the same generic kernel, more vectors in flight); the kernel-correctness tests iterate Kernel::ALL, and the engine test list. Measured on the Pi (bank throughput, N = 10k, one core; and the 50-key scenario):

Kernelns/res-sample (N = 10k)50-key RTF 1 core
pulp K=4 (pole form)2.2571.021
delta pulp K=42.3131.048
delta pulp K=64.0201.795
delta pulp K=84.3941.953

Recommendation: keep K = 4; do not change crates/dsp. More vectors in flight do not fill pipelines on the in-order A53 — they spill: K = 4 already keeps ~20 vectors (states, coefficients, accumulators) live and K = 6/8 nearly double that (−74 %). (Review: AArch64 has 32 128-bit V registers, not 16 — that is AArch32; with ~20 live at K = 4, spills at K = 6/8 are plausible but were not checked in the disassembly. The measurement and the recommendation stand.)

Desktop comparison (review, x86 cloud VM, Xeon @ 2.3 GHz, scenario; raw output spikes/modal-bench/results/2026-12-05-cloud-x86-scenario-output.md, ±20 % noise): bank throughput at N = 10k, ns per resonator-sample — delta K=4 0.055 / K=6 0.049 / K=8 0.061 (AVX-512), 0.084 / 0.080 / 0.108 (AVX2); 50-key scenario RTF on one core — 0.032 / 0.035 / 0.042 (AVX-512), 0.044 / 0.045 / 0.061 (AVX2). K = 6 is within noise of K = 4 on the desktop, K = 8 is slower everywhere: K = 4 stays, confirmed on both machines. The desktop comparison was not measured (this session ran on the Pi), but it cannot rescue the proposal: the premise was “faster on the A53 without costing the desktop”, and on the A53 K = 6/8 lose by 1.7–1.9×. Pulp K = 4 (delta form in the engine) remains the choice everywhere.

Part B

Waits for T-026 (standalone) and T-028 step 3 (USB audio).