Telltale 如何讀取 QNX 8.0 畫面,偵測速度表顯示失真
A heartbeat can't tell you the speedometer is lying: reading the glass back on QNX 8.0
Telltale 是一個獨立的 QNX 8.0 程序,讀取 QNX Screen 合成的像素,核對車速、警示燈和生命訊號,並在渲染器失效時先顯示真實車速。測試注入 200 次故障,全部偵測到;但 STALE 故障的 p95 偵測時間為 271.2 ms,超出 200 ms 目標。該程序未獲認證,亦未聲稱符合 ISO 26262 或 ASIL。
A car brakes from 49 km/h to a stop. The instrument cluster keeps showing 48.
The renderer process is running. If you watch its liveness tick, it may still be ticking. If you ask it what it drew, it says the right number. Every check that lives inside or beside the renderer comes back green, and the driver is looking at a number that stopped being true seconds ago.
That is the gap I built Telltale to close: a watchdog proves the renderer is alive; only reading the glass back proves it tells the truth. Telltale is a separate QNX 8.0 process that reads back the pixels QNX Screen actually composed, decodes the speed digits, six warning lamps and a liveness tick, and compares them with the vehicle state. When the glass lies, it puts the true speed on screen first and deals with the renderer second.
Repo: github.com/edycutjong/telltale · Site: telltale.edycu.dev · Two-minute judge guide
Every timing in this post is QEMU (TCG) on an x86_64 QNX 8.0 guest, not hardware timing. Telltale is not certified and makes no ISO 26262 or ASIL claim.
The frozen 48
The drive is real: a stop from the comma2k19 dataset, 49.01 km/h to 0 in 4.848 s, replayed as CAN speed into a resource manager. A fault injector freezes the renderer mid-stop.
Both panes are real frames read back from QNX Screen on the guest, at 1x speed. On the left the monitor is disarmed: the glass keeps showing 48. On the right, in the recorded take, Telltale caught the stall 123.4 ms after the fault, its safe layer was on the glass at 181.3 ms, and the first verified true frame from a respawned renderer came at 580.7 ms.
The order matters. The truth goes up before anything is killed, and the display is handed back to the renderer only after its own window reads true and its tick has genuinely moved since the fault was caught.
Why a heartbeat and a self-report aren't enough
The bench makes this concrete rather than rhetorical. Two of the fault classes are designed to defeat the obvious checks:
- STALE: the renderer stays alive and keeps its tick moving, but draws an old value. A tick-only watchdog would not have caught any of the 50 STALE runs, by construction. All 50 were caught by Telltale's value check.
- BLANK and MISDRAW: the renderer intends the right number. In MISDRAW it draws a different one (48 drawn as 84). Computed offline from the renderer's own intent log, a self-report check would have passed all 50 BLANK and all 10 MISDRAW runs. The pixel read caught every one.
The check itself is deliberately boring: a deterministic glyph decode against a known atlas, no machine learning, so the same frame always gets the same verdict.
The honest bench
Here is what 200 injected faults (50 per class, one fresh process stack per injection, placed in the speed-changing windows of one real 31-minute drive) produced:
| class | misses | detect p50 / p95 (ms) | stretch < 100 ms (p95) | formula bound 197 ms (p95) |
|---|---|---|---|---|
| BLANK | 0 | 17.5 / 24.8 | met | met |
| FREEZE | 0 | 106.8 / 129.8 | missed | met |
| STARVE | 0 | 147.6 / 175.8 | missed | met |
| STALE | 0 | 168.2 / 271.2 | n/a: W + 100 = 200 ms target missed | n/a |
0 missed out of 200. But read the right-hand columns. The < 100 ms stretch target was met only for BLANK. STALE missed its 200 ms target by about 70 ms at p95. Those misses are published in the repo next to the wins, and the STALE miss was not decomposed or tuned afterwards. Detection time is dominated by the calibrated stall threshold (tick_stall_ms = 151), not by how fast the monitor runs: halving the check period from 20 ms to 10 ms moved FREEZE p95 only from 129.8 to 122.2 ms.
Two controls keep the headline honest:
- Monitor off. 40 runs with the monitor disarmed (it still reads, never acts): the glass was wrong or missing a speed for a median 29.9 s of a 30 s window, and still wrong at the end of all 40. That is a control, not a detection result, but it shows what the fault does when nobody is watching the glass.
- False positives. The first 30 minutes of the same real drive, no faults: 0 false positives in 91,029 checks. The whole check (three-region read-back plus decode) costs p50 / p95 5.7 / 6.3 ms.
The main bench was built at commit 7592e40. The monitor changed after code review, so the current build (f2b8002) was re-checked with a smaller regression run, 5 per class including crashes: 25/25 detected. The on-target test suite is 190 passed / 0 failed at f2b8002, and the repo keeps two earlier failing suite runs, each of which caught a real monitor defect that was then fixed.
The QNX primitives that kept it small
What surprised me most is how little glue this needed. QNX's primitives map almost one-to-one onto the problem.
A resource manager you can cat. The vehicle state lives in /dev/vehicle, served by an ordinary user-space process. Clients use devctl for typed reads and writes, and a human can just read it. This is a recorded session from the guest:
root@qnxqemu:/tmp/tt# cat /dev/vehicle
seq=377 t_ns=3693699975052 trace_s=5.945 speed_kmh=43.58 gear=D lamps=0x00 denied=0
The monitor exposes its own state the same way through /dev/telltale and /dev/telltale-events.
Pulses instead of polling. The monitor runs at SCHED_FIFO 60 and is woken by a periodic timer that delivers a pulse to a private channel:
int chid = ChannelCreate(_NTO_CHF_PRIVATE), coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
struct sigevent tev; SIGEV_PULSE_INIT(&tev, coid, 60, _PULSE_CODE_MINAVAIL, 0);
timer_t tid; CK(timer_create(CLOCK_MONOTONIC, &tev, &tid), "timer_create");
struct itimerspec its = period_its(cfg.period_ms);
CK(timer_settime(tid, 0, &its, NULL), "timer_settime");
/* ... */
for (;;) {
struct _pulse p;
if (MsgReceivePulse(chid, &p, sizeof p, NULL) == -1) { /* ... */ continue; }
Screen read-back. Each check reads three small regions of the composed display, which is what the driver sees, not what the renderer thinks it posted:
int e1 = screen_read_display(disp, bb, 1, rb, 0), e2 = screen_read_display(disp, bt, 1, rt, 0);
if (!e1 && !e2) e2 = screen_read_display(disp, bl, 1, rl, 0);
The safe layer is just another Screen window, posted on top with screen_post_window.
secpol, so the monitor can't be talked over. Every process gets its own security type, and only the feeder may write the truth:
allow feeder_t vehicle_t:vehicle write;
allow renderer_t vehicle_t:vehicle read;
allow monitor_t vehicle_t:vehicle read;
allow hog_t self:ability { priority:1-40 };
With the policy loaded, the on-target suite runs 22 secpol checks, 13 of them denials. Even untyped root gets DCMD_VEH_SET: Operation not permitted, and the CPU hog is refused priority 50. One caveat stated plainly: the policy is enforced in the on-target suite, not loaded during the timing bench.
Building for QNX 8.0 on an Apple-Silicon Mac
None of this ran on hardware. The whole loop ran on an M1 Mac, and the setup had its own lessons:
-
The compiler lives in a container. SDP 8.0's host tools are Linux-only, so
qccruns in alinux/amd64Docker image under emulation. The SDP itself stays on the Mac and is bind-mounted at the same absolute path. - QEMU with TCG, not KVM. The QNX Everywhere Quick Start image boots as an x86_64 guest with software emulation. It is slow, but it needs no root, no KVM and no extra drivers. The first boot converts the image's 47 GiB raw disk to qcow2. Because the guest is emulated and the Mac was under load, I label every number as QEMU timing and log host load per bench row.
-
The
ionotifypitfall. The renderer waits for new vehicle data withionotify()and a pulse. The step that is easy to miss: the event must be registered against the fd withMsgRegisterEvent()first. Leave it out andionotify()still succeeds, but the pulse never arrives. No error, just silence. The codelab records the broken variant (zero wake-ups after four seconds) next to the working one:
SIGEV_PULSE_INIT(&ev, coid, SIGEV_PULSE_PRIO_INHERIT, PULSE_CODE, 0);
if (MsgRegisterEvent(&ev, fd) == -1) { perror("MsgRegisterEvent"); return 1; }
/* ... */
int now = ionotify(fd, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT, &ev);
If you have never written a QNX resource manager, that codelab walks a /dev/counter from docker build to ionotify on the same Mac-plus-QEMU setup, with every command's recorded output.
Limits
- Not certified; no ISO 26262 or ASIL claim.
- All timings are QEMU (TCG) on a loaded Mac, not hardware.
- The monitor itself is not supervised: if
telltaledies, nothing restarts it. - Gear is drawn but not verified; speed digits, six lamps and the tick are.
- Whole-CPU starvation (Screen, monitor, renderer and hog on one CPU) delays the safe layer until the hog ends, so STARVE is reported as "renderer CPU only".
- The 200 injections are a declared population in one real drive, not general coverage.
Try it
The claims can be checked without a QNX licence: make test-host runs the host tests, scripts/replay_target_run.sh re-checks every recorded assertion of the cited on-target run, and scripts/bench_all.sh report regenerates the bench tables byte-identically. Running it on QNX needs SDP 8.0 and the QNX Everywhere QEMU image; the README has the steps.
- Repo: github.com/edycutjong/telltale
- Site: telltale.edycu.dev
- Codelab: telltale.edycu.dev/codelab
Telltale is entered in the QNX Global Hackathon; the project page is here.
AI disclosure: Claude Code was my engineering pair while building this; the product itself uses no AI at runtime.
來源:DEV Community · dev.to

