Inspiration

Carmakers are moving infotainment and safety onto one computer, so a misbehaving music app must never be able to silence a safety chime. On a shared processor and a shared speaker, the operating system decides whether the seatbelt chime gets the CPU, survives a crashed audio driver, and avoids getting stuck behind lower-priority work. Software chimes do fail in practice: in 2022, NHTSA recall 22V-045 covered 817,143 vehicles because a software error could stop the seat belt chime from sounding, in a year when 11,302 unbelted passenger-vehicle occupants died in US crashes (NHTSA DOT HS 813 573). Chime tests whether QNX keeps that sound on time when everything around it goes wrong.

What it does

Chime is a safety-sound service for QNX 8.0, plus the two pieces it needed:

  • A new io-snd driver for QEMU's virtio sound card (sndrv-ctrl-virtio_snd.so). QNX 8.0 has no driver for it on AArch64, so an emulated QNX system has no sound at all. With the driver, any QNX 8.0 image in QEMU can play audio through the standard io-snd and ALSA stack.
  • chimed, a resource manager at /dev/chime with a SCHED_FIFO audio thread. Turn-signal ticks, seatbelt, door and collision chimes are requested by writing to it. It shares the speaker with an ordinary low-priority music player through io-snd's software mixer, and both are launched and supervised by QNX's System Launch and Monitor.
  • An inversion detector (program name blockwatch). It reads every thread's blocking state through QNX 8.0's libintrospection, builds a system-wide wait-for graph, and names a priority-inversion chain live: who waits on whom, at what priority, and who is preempting them.

The demo then attacks the chime three ways, on QNX 8.0 in QEMU:

  1. Starve it: two FIFO threads flood both cores. The music stutters, as designed, and every chime and tick stays on the beat.
  2. Crash it: kill -9 of io-snd, five times in a row. slm restarts the sound system each time, chimed reconnects by itself, and the system never reboots.
  3. A bug: the vehicle-state server is rebuilt with _NTO_CHF_FIXED_PRIORITY. The turn signal drifts off the beat, the detector reports CRIT PRIORITY_INVERSION and names the chain, and removing the flag puts every tick back on the beat with the storm still running.

How I built it

  • The driver (chime/src/driver/vsnd.c) implements the VirtIO 1.2 sound protocol over virtio-mmio behind the io-snd driver API: card_dll_init(), ado_pcm_create(), ado_attach_interrupt() and the hw_* callbacks. It finds the device by scanning the mmio slots and queues io-snd's ring fragments to the device as virtio periods with zero copy. It reports completions from the interrupt handler with dma_interrupt_n().
  • The service (chime/src/apps/chimed.c) uses resmgr_attach() for /dev/chime and renders chimes in small periods on a FIFO thread. When io-snd disappears it reopens the PCM in pcm_open_retry().
  • The cast is small QNX programs: the turn signal is a timer_create() pulse that MsgSend()s to the vehicle-state server (name_attach(), MsgReceive(), MsgReply()), plus a music synth and a CPU storm.
  • The image is built with mkqnximage. The sound stack and chimed live in the boot image (IFS), so sound comes up before any disk is mounted, and slm components start and restart io-snd and chimed.
  • The detector (blockwatch/) is portable C11 with a thin QNX layer: libintrospection collection, and a resource manager at /dev/blockwatch/* with deferred-reply alerts and MsgDeliverEvent() subscriptions. Its tests replay real captures from QNX 8.0.
  • The toolchain: QNX SDP 8.0 qcc (gcc_ntoaarch64le). The SDP's Linux host tools run in an x86_64 container under Rosetta on an Apple-silicon Mac, and the target is QEMU's AArch64 virt machine. The README has the build steps.

Where to look: the README's "Where QNX is used" table maps each QNX feature to its file and function. Video timestamps: driver 0:42, starve 0:53, crash 1:02, the bug 1:16, the inversion explained 1:25, the detector 1:40, the fix 1:54.

Challenges I ran into

The hardest part was the driver timing model, because QEMU reads a sound period the moment it is queued rather than when it plays. A driver that queued the whole io-snd ring at once would send audio that io-snd had not written yet. The driver therefore keeps only a few fragments queued ahead of playback and queues the next one from each completion interrupt. That one decision is the difference between clean chimes and a stream of stale noise.

io-snd could also hang when slm launched it, because slm runs at a high priority and io-snd inherited it. Clients that connected while io-snd was still initialising then blocked forever. The fix was an explicit priority in the slm component (<SLM:priority>10r), which is the kind of interaction that only shows up when the real QNX supervisor starts the stack at boot. Finding it meant reading io-snd's slog2 output under slm, not just testing from a shell.

Accomplishments that I'm proud of

QNX 8.0 on AArch64 QEMU now has sound, which no shipped driver offers (the only prebuilt 8.0 sound driver is Intel HDA for x86_64). The safety chime stayed on the beat under a CPU storm and came back after every crash of the sound system, without a reboot. The one failure was a real QNX design hazard, lost priority inheritance, and the detector explains it from live kernel data in terms a developer can act on.

What I learned

QNX's message passing carries priority with it, and that is what keeps a mixed-criticality system honest. A server that serves a priority-50 client runs at priority 50, so a priority-20 CPU storm cannot get in between. One channel flag, _NTO_CHF_FIXED_PRIORITY, quietly removes that guarantee. The turn signal in this demo went audibly off the beat from that single change, with no error anywhere. The lesson is that on QNX a timing guarantee belongs to the whole message chain, not to one thread's priority.

What's next for Chime

  • Fixed on 2 Dec, after submission: stress-testing the crash demo found that a killed io-snd could leave the virtual sound card writing into freed memory, which could crash the kernel under repeated kills. The driver now keeps that memory alive across restarts, and chimed has a watchdog that restarts io-snd if audio ever stops. Details are in the README.
  • Capture (the virtio-snd input stream), and a security policy (secpol) that lets only safety clients reach /dev/chime.
  • Running the same service on a Raspberry Pi 5 with a real audio codec.

Built With

Share this project:

Updates

Submission history