Component: `vm/boot-x86.sh` (the only rail with a sound device — the arm64 boot
script has none) and a new `scripts/audio-crackle-probe`.
The mechanism
-------------
QEMU refills its audio backend from `audio_run_out`, on a `QEMU_CLOCK_VIRTUAL`
timer at `timer-period` — 10 ms by default — on the **main loop**. Every backend
is therefore exposed to main-loop jitter; what differs is what each one does
when the refill is late:
- `sdl` holds `4 * 11610 us` and its callback fills the shortfall with
`audio_pcm_info_clear_buf` — **zeroes**. Zeroes in the middle of a waveform is
what a click is, and it neither logs nor counts them.
- `pipewire` runs its own thread over a fixed 1 MiB ring, defaults to 46440 us,
and `error_report`s an underrun when one happens.
- `pa` has its own threaded mainloop and the same 46440 us default.
- `alsa` has an `alsa_xrun_out` trace event.
So the backend this script pinned was the least tolerant of the jitter and the
only one that would not say it had lost anything.
There is a second, independent loss path on the way *in*: `usb-audio` rings 32
packets — 6144 bytes, about 32 ms at 48 kHz stereo — and `streambuf_put` drops a
whole isochronous packet, silently, whenever the ring is full when one lands.
What changed
------------
The audiodev is now chosen at boot from the first native host backend this build
has (`pipewire`, `pa`, `alsa` on Linux; `coreaudio` on Darwin), with `sdl` kept
as the last resort rather than the default. Both buffers are stated explicitly
rather than inherited — `AUDIO_BUFFER_US` (46440, what PipeWire and PulseAudio
pick for themselves, so the jitter budget is the same number on every backend)
and `AUDIO_USB_BUFFER` (64 KiB, ~340 ms, against QEMU's 32 ms). `AUDIODEV=`
forces one. The choice is printed on its own boot line, so a report says which
path it came from.
The probe
---------
`scripts/audio-crackle-probe` makes the symptom a number: the guest plays a
continuous 440 Hz sine, `parec` captures the host sink monitor, and
`silencedetect` counts the holes. A sine has no silence in it, so silence in the
capture is a hole the path introduced. It refuses a verdict when the capture has
no tone in it, because a silent capture would otherwise score as the worst
possible result while meaning only that nothing played.
Verification, and what it did NOT show
--------------------------------------
Four driven x86/PCI boots, macos-13 rail, machine quiesced:
```text
gaps total_gap_s
sdl, 11610 us, usb 6144, idle 0 0.000
pipewire, 46440 us, usb 65536, idle 0 0.000
sdl, 11610 us, usb 6144, driven 40 s 0 0.000
pipewire, 46440 us, usb 65536, driven 40 s 0 0.000
```
**This host does not reproduce the report** — not idle, not with the tone
playing inside a 40 s Safari drag, not on the backend the report implicates. So
this is hardening against a mechanism read out of the vendored source, and it is
not a fix with a before and after. Do not read it as one. The new default is
verified only to boot, play cleanly, and not cost frame rate (drag probe
`present_hz` med 68.6 alongside the tone).
`--interactive` and `--capture` boots share the same args and were not run.
Nothing here is verified on a macOS host, where the preference order selects
`coreaudio` and no boot was taken.
Two probe bugs are worth naming because both scored a clean run as a failure:
the capture originally opened before playback (one 0.354 s "gap" that was the
lead-in), and after that both backends reported one 0.00526077 s gap starting at
t=0 — identical to the sample across two unrelated audio paths, which is
`parec`'s first buffer and not a dropout. The analysis now starts 0.5 s in. A
number that reproduces exactly across the variable you changed is measuring the
instrument.
Co-Authored-By: Claude <noreply@anthropic.com>
vm/ — macOS guests for the reims-vgpu pathways
crates/reims-vgpu runs three backend pathways over two guest rails. Pick the boot script for the
guest you are on and the QEMU/reims-vgpu backend for the host GPU path.
| Pathway | Script | Host accel | Backend | Typical device |
|---|---|---|---|---|
| x86 macOS / Linux Vulkan | vm/boot-x86.sh |
KVM / OpenCore+OVMF | Vulkan via metal2vulkan |
reims-vgpu-pci |
| arm64 macOS / macOS Metal | vm/boot-arm64.sh |
HVF / vmapple |
Metal-direct | reims-vgpu-mmio (product) or apple-gfx-mmio (Apple reference A/B) |
| arm64 macOS / macOS Vulkan | vm/boot-arm64.sh |
HVF / vmapple |
Vulkan via metal2vulkan through MoltenVK |
reims-vgpu-mmio |
# arm64 macOS guest on Mac host (Metal or Vulkan/MoltenVK backend)
vm/boot-arm64.sh --testing # agent boot: GUI + serial-to-file, hard kill, reverts
vm/boot-arm64.sh --interactive # human boot: GUI, no time limit, reverts
vm/boot-arm64.sh --device reims-vgpu-mmio --testing
vm/boot-arm64.sh --device apple-gfx-mmio --testing # Apple-paravirt reference (arm only)
# x86 macOS guest on Linux host
vm/boot-x86.sh --testing
vm/boot-x86.sh --device reims-vgpu-pci --testing
vm/boot-x86.sh --device reims-vgpu-pci --testing --rail macos-11 # a specific guest OS line
Both scripts use a snapshot-revert lifecycle (testing vs interactive classes; testing hard kill).
QMP is a per-boot unix socket under the run dir for that pathway (scripts/qmp/qmp.py).
Networking is typically QEMU SLIRP with SSH hostfwd. Guest disks, IPSWs, OpenCore blobs, and runtime clones are gitignored - private and large; never commit them.
Rails
A rail is one guest OS line — macos-11 … macos-26 — and each rail owns its own snapshot
history. Two coordinates select what boots, each with its own current, and neither selection
repoints anything:
vm/disks/rails/<rail>/snapshots/<label>/ # x86: macos.img, OpenCore.qcow2, OVMF_VARS.fd
vm/disks/rails/<rail>/snapshots/current # (+ OVMF_CODE.fd when the guest needs its own)
vm/disks/rails/current -> <rail> # the rail a bare boot gets
vm/guest/rails/<rail>/snapshots/<label>/ # arm64: disk.img, aux.img.trimmed
vm/guest/rails/<rail>/vm.json # optional per-rail ECID
vm/boot-x86.sh --list-rails # * marks the default
vm/boot-x86.sh --rail macos-15 --list-snapshots
vm/boot-x86.sh --rail macos-15 --testing # boot that rail's snapshots/current
vm/boot-x86.sh --rail macos-15 --snapshot base --testing
vm/boot-x86.sh --rail macos-15 --capture # clean shutdown → new snapshot IN that rail
ln -sfn macos-15 vm/disks/rails/current # change the default
Snapshots are per-rail because they are not comparable across rails: a macOS 15 disk and a macOS 11
disk share no history, and one flat namespace makes current mean "whichever guest was captured
last" — which is how a measurement gets attributed to the wrong OS.
Importing a guest built elsewhere needs no boot: drop its disk and firmware into
rails/<rail>/snapshots/base/ under the names above, chmod 444, and point snapshots/current at
base. Copy with cp --reflink=auto on btrfs (or cp -c on APFS) and the import costs no disk.
Carry the guest's own OVMF_CODE.fd when it was installed under a different OVMF build — the NVRAM
in OVMF_VARS.fd only means anything to the code half that wrote it, and a snapshot that ships one
overrides vm/ovmf/OVMF_CODE_4M.fd for that boot.
Layout (gitignored runtime)
Pathway-specific trees hold provisioned disks, rails, and per-boot clones. The run dir
(vm/disks/run, vm/guest/run) is shared across rails: clones are stamped and thrown away, and
run/qmp.sock is the one path every driver script resolves.
Stop a wedged guest with the pathway's shutdown helper when available
(scripts/vmapple-shutdown on arm); otherwise use QMP quit plus a process kill.