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):

  1. Cross-build: a Nix cross-build (or cross) of crates/standalone and the benchmark for aarch64-unknown-linux-gnu; until Nix is in the loop, a plain cargo build --release --target aarch64-unknown-linux-gnu from an aarch64 host is the same architecture and was checked in a cloud session (see Outcome). glibc target: gnu, not musl (Raspberry Pi OS is glibc).
  2. Benchmark run on the Pi: cargo run --release -p modal-bench --bin scenario on 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).
  3. USB audio: cpal with a USB audio interface (or audio HAT), buffers 64–128 frames at 48 kHz, PREEMPT_RT kernel and governor performance; measure output latency.
  4. 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).
  5. Network: join Wi-Fi, or run a hotspot when there is none (for the web remote, T-027).
  6. 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

QuestionOptionsProposal
D1Build 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
D2libc target(a) aarch64-unknown-linux-gnu (glibc, matches Raspberry Pi OS); (b) musl (static, but cpal/BlueZ integration suffers)(a)
D3Kernel / latencystock kernel vs PREEMPT_RT (mainline since Linux 6.12), governor performancePREEMPT_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.conf with @audio - rtprio 95 and @audio - memlock unlimited (chrt -f 80 … works; ulimit -r prints 95).
  • perf (linux-perf, kernel.perf_event_paranoid = 1); governor performance from boot by /etc/systemd/system/cpu-performance.service (a oneshot that writes performance to every core’s scaling_governor; cpufreq.default_governor=performance in cmdline.txt did 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 with taskset -c 3.
  • libasound2-dev, pkg-config, alsa-utils (cpal/midir build), zram-tools (compressed swap for builds), rt-tests (cyclictest), user in bluetooth.
  • 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 with kernel=kernel8_rt.img under [all] in /boot/firmware/config.txt (uname -v shows PREEMPT_RT); removing that line boots the stock kernel8.img again. Debian’s linux-image-rt-arm64 is 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 precision succeeds 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-gnu from any host with rustup target add aarch64-unknown-linux-gnu is the cross-build check. A full cargo build --release --workspace does not fit this 1 GB VM (rustc is OOM-killed on the egui/clack crates with codegen-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 scenario on the Pi, or copy target/release/scenario over.

  • 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) and precision run 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), with taskset -c 0-2 target/release/scenario as load on cores 0–2. Worst wake-up latency in µs, per core 0/1/2/3:

    KernelCore 0Core 1Core 2Core 3 (isolated, no load)
    stock kernel8.img (6.18)1986914731
    PREEMPT_RT kernel8_rt.img (6.18.65)57454524

    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_passage on it). /dev/cpu_dma_latency was not writable (harmless on the Pi 3).

  • 2026-12-06, the throughput check (T-055 §2c): the RT kernel costs the engine nothing — pi_passage on both kernels, same clean setup (governor performance, 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.