T-028 — Raspberry Pi 3: cross-build for aarch64, USB audio and latency, quality levels, Wi-Fi hotspot, Bluetooth LE MIDI
Status: in progress — steps 1–2 done (aarch64 build; benchmark run on the maintainer’s Pi 3, tables on the T-011 page); steps 3–6 wait for T-026 · Area: rust, ops, nix · Depends on: T-026, T-011
Read for that: Standalone and remote (Raspberry Pi, Bluetooth), T-011 (the scenario benchmark and its measured Pi run, §4), Piano 14 (quality levels, measured Pi column), P-004, Toolchain (Nix).
What: make the instruments run standalone on a Raspberry Pi 3 (aarch64, 4 × Cortex-A53, 1 GB RAM):
- Cross-build: a Nix cross-build (or
cross) ofcrates/standaloneand the benchmark foraarch64-unknown-linux-gnu; until Nix is in the loop, a plaincargo build --release --target aarch64-unknown-linux-gnufrom an aarch64 host is the same architecture and was checked in a cloud session (see Outcome). glibc target:gnu, notmusl(Raspberry Pi OS is glibc). - Benchmark run on the Pi:
cargo run --release -p modal-bench --bin scenarioon the Pi (one core and four), results into the tables on the T-011 page; decides whether T-024 (multithreading) is needed and which quality level fits with headroom (P-004). - USB audio: cpal with a USB audio interface (or audio HAT), buffers 64–128 frames at 48 kHz,
PREEMPT_RTkernel and governorperformance; measure output latency. - Quality levels on the Pi: map Piano 14’s levels (Ultra/High/Medium/Low) to what fits the Pi, as a default setting of the standalone app. Step 2 measured the string banks only; decide with T-055’s numbers (whole engine, clock checked, real-time callback).
- Network: join Wi-Fi, or run a hotspot when there is none (for the web remote, T-027).
- Bluetooth LE MIDI in through BlueZ; controllers map to parameters via MIDI learn.
Done when: the standalone binary built for aarch64 runs on a Pi 3 and plays through a USB interface with a measured latency entered here; the T-011 scenario numbers from the Pi are on the T-011 page and P-004 is updated; the quality-level default is decided from those numbers; hotspot mode and BLE MIDI are demonstrated once.
Decisions
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | Build route | (a) Nix cross-build / cross; (b) plain cargo build --target aarch64-unknown-linux-gnu from an aarch64 host or any host with the target installed | (a) as the shipped route (reproducible, matches Toolchain); (b) is the quick check — same architecture, glibc gnu |
| D2 | libc target | (a) aarch64-unknown-linux-gnu (glibc, matches Raspberry Pi OS); (b) musl (static, but cpal/BlueZ integration suffers) | (a) |
| D3 | Kernel / latency | stock kernel vs PREEMPT_RT (mainline since Linux 6.12), governor performance | PREEMPT_RT + performance; measured 2026-12-06 (Outcome): the RT kernel cuts the worst wake-up latency under load 3.5× — the Pi runs it |
Pi setup
The maintainer’s Pi 3 (Raspberry Pi OS trixie, arm64), set up 2026-12-06 for this task and T-055:
- Real-time scheduling without sudo: user in
audio,/etc/security/limits.d/audio.confwith@audio - rtprio 95and@audio - memlock unlimited(chrt -f 80 …works;ulimit -rprints 95). perf(linux-perf,kernel.perf_event_paranoid = 1); governorperformancefrom boot by/etc/systemd/system/cpu-performance.service(a oneshot that writesperformanceto every core’sscaling_governor;cpufreq.default_governor=performanceincmdline.txtdid not take effect on the RT kernel’s boot — cause not confirmed, possibly the governor being a module there); core 3 isolated (isolcpus=3): pin measurements withtaskset -c 3.libasound2-dev,pkg-config,alsa-utils(cpal/midir build),zram-tools(compressed swap for builds),rt-tests(cyclictest), user inbluetooth.- Cooling: a small heatsink, no fan — log the clock (
scripts/pi-clock-log.sh) on every long or multi-threaded run. - PREEMPT_RT (D3): Raspberry Pi’s own RT kernel,
linux-image-rpi-v8-rt(6.18.65), booted withkernel=kernel8_rt.imgunder[all]in/boot/firmware/config.txt(uname -vshowsPREEMPT_RT); removing that line boots the stockkernel8.imgagain. Debian’slinux-image-rt-arm64is the generic kernel, not set up for the Pi’s firmware boot.
Outcome
-
2026-12-04, cloud session (aarch64 VM, 4 vCPU / 1 GB RAM, no Pi at hand, no Nix in the session):
CARGO_BUILD_JOBS=2 cargo build --release -p modal-bench --bin scenario --bin precisionsucceeds in 2 m 40 s and produces ELF 64-bit ARM aarch64, dynamically linked (glibc) binaries (target/release/scenario,target/release/precision) — the Pi 3’s architecture and libc, so they run on Raspberry Pi OS as built. The same command with--target aarch64-unknown-linux-gnufrom any host withrustup target add aarch64-unknown-linux-gnuis the cross-build check. A fullcargo build --release --workspacedoes not fit this 1 GB VM (rustc is OOM-killed on the egui/clack crates withcodegen-units = 1): cross-building off the Pi is not just reproducible, it is required — the same will hold on the 1 GB Pi 3 itself. The run on the Pi stays with the maintainer (see What 2); command:cargo run --release -p modal-bench --bin scenarioon the Pi, or copytarget/release/scenarioover. -
2026-12-05, on the maintainer’s Pi 3 Model B Rev 1.2 (idle, Raspberry Pi OS), from the copied binaries:
scenario(~25 min) andprecisionrun clean. Tables and conclusions on the T-011 page §4: ~2.25 ns per resonator-sample (pulp K=4, NEON; ~33× the desktop AVX-512 core, not the old 5× projection), Ultra peak 1.4 cores — T-024 or a High default (step 4’s decision; High peak 65 % of one core), subnormals free on the A53 (no FTZ penalty). Step 2 done, P-004 updated. Also on the Pi:target/release/build(299 MB of orphaned build-script output without fingerprints or deps, unusable for incremental builds) was deleted to save SD-card space; the benchmark binaries stay. -
2026-12-06, D3 on the Pi 3 (governor
performance, core 3 isolated):cyclictest -m -p 90 -i 200 -t 4 -a -D 5m -q(one thread per core, intervals 200/700/1200/1700 µs), withtaskset -c 0-2 target/release/scenarioas load on cores 0–2. Worst wake-up latency in µs, per core 0/1/2/3:Kernel Core 0 Core 1 Core 2 Core 3 (isolated, no load) stock kernel8.img(6.18)198 69 147 31 PREEMPT_RT kernel8_rt.img(6.18.65)57 45 45 24 Averages 6–9 µs on both. The block deadline at 64 frames / 48 kHz is 1,333 µs, so even the stock kernel’s 198 µs is ~15 %; the RT kernel brings the worst case on loaded cores to ≤ 57 µs (~4 %), and the isolated core is quiet on both (24–31 µs) — the audio thread goes there. Only 5 minutes: rare spikes need the long run of T-055 part B, which should also check whether the RT kernel costs engine throughput (re-run
pi_passageon it)./dev/cpu_dma_latencywas not writable (harmless on the Pi 3). -
2026-12-06, the throughput check (T-055 §2c): the RT kernel costs the engine nothing —
pi_passageon both kernels, same clean setup (governorperformance, isolated core 3,chrt -f 80): RTF 0.887–0.893 vs stock 0.885–0.887, 5.35–5.39 vs 5.34–5.35 ns per resonator-sample, block 0 still the slowest (warm 176–185 % of budget) — within run-to-run spread; no tail difference shown on the isolated core (one 2,958 µs warm outlier on stock is a single sample). D3 confirmed: the Pi stays on the RT kernel.