pmb887x-emu-web/doc/lessons.md
Konstantin Pereiaslov a9b40fec51 doc: typing retest on the spaced key queue, models that cannot be typed on
Every model was retested with qemu spacing the key edges, the sweeps'
taps included: 19 phones type with the page's setting (6 of 6 runs each),
and the per-chip thresholds stand with more phones in them (S65, S66 on
PMB8875; S68, SL75 on PMB8876). The EL71 had been measured losing taps at
40+20; with the edges spaced by qemu it types 40+20 and 30+30 like the
E71, S68 and SL75, so the old harness had been shortening some taps.

The first slow-host runs had not been slow for the phone (it kept up with
real time); the lesson now gives the side-by-side run instead: at 0.4x
real time the KE970 typed 6 of 16 right with the old page code and 15 of
15 with the new. Also noted: why CF75, CL61, M72 and SK65 could not be
measured, and which C81/SL75 dumps do not boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xda8d7rfJjkFSmKVQtcBGh
2026-11-14 00:08:36 -06:00

40 KiB
Raw Permalink Blame History

Lessons learned

Platform facts and rules that the design and the measuring method rest on. Each one was paid for at least once. Figures carry the date they were measured; the investigations behind them are in this file's git history. Current methods and numbers are in performance.md.

Timing model

  • Siemens firmware needs virtual time decoupled from wall time. The L1↔DSP handshake and other firmware budgets are wall-clock budgets in guest terms. On a host slower than the phone, a clock locked to real time starves the guest of instructions per virtual second and the phone aborts with >>EXIT<< FILE: l1bbcsg. The page's vcpu-timers clock counts guest CPU cycles and is paced to wall time, so a slow host slows the clock instead. -icount shift=3,sleep=off has the same property unpaced, and is what lockstep and scripts/run-native.sh use.
  • Under icount, sleep=off is the indispensable half. With sleep=on the vCPU parks in real time during every idle window and the DSP handshake desyncs: shift=3 and shift=4 both die with the L1 abort, in the browser and natively.
  • A catch-up bank must be windowed in guest time. A guest that fell behind during the boot must be allowed to catch up, but the same credit later lets a stall be repaid by sprinting the phone's clock. vcpu-timers-bank is therefore limited to the guest's first 30 s. The window is in guest time because the boot costs the same virtual time on every host, while its wall time ranges from under 30 s to minutes.
  • LG firmware used to boot on the realtime clock. Since the DSP LLE its DSP boot-ROM poll loop runs on the vCPU thread and starves the ARM in real time, so every board runs the same clock.
  • Virtual time outrunning instructions kills the boot (BROM delay loops). Never fix pacing by pinning clock frequencies.
  • Any >>EXIT<< on serial means the phone crashed. Stop there; it does not recover.

Mid-TB MMIO and the io-recompile rewind

  • The rewind is clock semantics, not only cost. A device callback must see the clock of exactly the accessing instruction. Skipping cpu_io_recompile moved that clock, the boot ROM's GPTU poll read its timer as not yet expired, and the phone died with >>EXIT<< FILE: flash within seconds. Splitting TBs at known io PCs, crediting at the access and pacing per access all reproduced the abort.
  • What the port does instead: the rewind happens once per instruction. The PC becomes an io barrier and is retranslated as a single-instruction TB (wasm_add_io_barrier, A5 in wasm-fast-paths.md).
  • Whatever a prologue counts, an unwind has to hand back. The wasm64 prologue adds the TB's instructions to the page's counter and the lockstep fold; only icount_decr and the cycle counter were rewound. The fold then sampled early by the unrun instructions of every rewind, which read as a wasm-only divergence in internal SRAM for a week (w64_acct_unwind, 2026-11-10).
  • A 32-bit TCG value has no defined upper half in its host register. With TCG_TARGET_HAS_extr_i64_i32 0, extrl_i64_i32 is a move and the I32 temp may simply take over the i64 temp's register. A backend emitter that widens an I32 operand must extend it itself (w64_get_u32, 2026-11-10).
  • An op-suite case whose operands are constants tests the optimizer. Superblocks inline the shim into its caller, and the shift under test folds away; and while NF/ZF still hold copies of a result, later uses read those copies. The case that failed loads its operands from volatile memory and overwrites the flags before the use.
  • An op-suite shim that is one TB must not straddle a page. Adding code moved smc_slot onto a page boundary and the same-TB SMC canary "failed" on the native JIT (.balign 16).
  • A fallback that "has not been observed to run" has not been tested. Lowering W64_LIVE_MAX to 48 ran batch eviction within seconds and aborted in the DSP at 61M instructions. The fix of that day dropped the evicted DSP blocks when a slice starts, and a second case stayed: a batch that lands in the middle of a slice (the dispatcher closes the open batch when a staged block first runs) evicts a block the same slice then runs, and DSP blocks are not in TCG's TB tree, so the dispatcher cannot retire them (w64: evicted TB … is not known; a Firefox boot at a cap of 128 showed it, 2026-11-10). A boot uses ~450–900 of the 6144 batches, but Tower Bloxx adds two or three a second, so a long game gets there. Test eviction with a temporary cap of 256 under tools/lockstep-wasm.mjs --insns 1e9; below ~512 a scene cannot be walked, the guest thrashes and drops the keys.
  • A direct-mapped fix-once cache can thrash into a fix-never loop. The barrier set was once 64 slots indexed by pc >> 2: two hot MMIO instructions shared a slot and evicted each other on every pass (~800 rewinds/s, ~1 MIPS), and pc >> 2 aliased adjacent Thumb instructions. It is two-way and indexed by pc >> 1 for that reason.
  • one-insn-per-tb hides this whole class of bug, including a wrong recorded return address for the unwind. That is why the default lockstep is blind to it (performance.md, Lockstep).

Emscripten runtime

  • Asyncify breaks cross-worker pthread_cond wake-ups. Signals from another worker are never delivered and waiters return only by timeout. QemuCond and QemuEvent are futex-based on emscripten (emscripten_futex_wait/wake is Asyncify-safe). An untimed wait must pass an infinite timeout: 0 ms returns at once and spins.
  • poll()/ppoll() never sleep on the proxied main thread, so the main loop sleeps in emscripten_futex_wait on a sequence word (ml_futex_seq, util/main-loop.c). Condvar timed waits round to whole milliseconds; emscripten_futex_wait has ns precision and is the right sleep primitive.
  • A wake must be published after the work it advertises, and the sequence word is an atomic counter. A non-atomic increment lets one waker erase another's wake. A wake issued before qatomic_set(&ctx->notified, true) in aio_notify() is spent on an empty look. Either loses an edge, and where the main loop runs the virtual timers (?icount=none) a lost edge is a dead guest: KE800 froze on its splash screen on Android. A race like this cannot be A/B'd on a clock. Build a knob that widens the window until the failure is certain.
  • Who runs the timers decides whether a wake is waste. Under vcpu-timers and icount the vCPU thread runs virtual timers, and waking the main loop for them is pure loss. qemu_timer_notify_cb tests qemu_virtual_timers_on_vcpu.
  • A cross-thread wake costs the BQL round trip behind it, on the other thread: the woken thread takes the lock, finds nothing and parks. Deleting 38k useless wakes/s was worth +37 % MIPS on the S75 (September), which no self-time profile predicted. Size such a fix by the wake count.
  • Work under the BQL costs the vCPU what it takes on the slowest core. The vCPU thread takes the BQL thousands of times a second, so it meets every hold of another thread and waits it out. A phone's scheduler puts a thread that is nearly idle, the main loop, on a little core, where a display refresh takes several times longer: 0.85 % of the vCPU on the desktop, 1.5 % on a Motorola One 5G Ace, 3.3 % on a Pixel 8 Pro, for the same 61 refreshes a second. The cure was not a shorter hold but no second thread: the refresh became a timer of the vCPU thread (91ad8b0c21). The sign was not in any profile: the vCPU worker was 92.8 % busy with the guest at half of real time (tools/perf/phonethreads.sh).
  • On a phone that throttles, heat is a lever. A Pixel 8 Pro caps its big core from 2.9 to 1.9 GHz after two minutes of a game and to 1.2 later, so whatever the page spends anywhere, on any core or in the GPU process, comes back as vCPU frequency. Polling the LCD in guest time halved the display pipeline's work for a guest at half speed, and the build held x0.56 where the one before sank to x0.46; the 3 % of lock waiting it removed explains a fraction of that.
  • Proxied syscalls take ~1 ms, and realtime clock reads are JS imports (~1.5–3 µs). Neither belongs on a per-timer or per-budget path.
  • Asyncify instrumentation is an allowlist (configs/meson/asyncify-only.txt), and it is not free: a state test at entry and around every call, plus spilled locals. Seven hot cputlb functions on the list turned a +4.1 % patch into −2.5 %. A vCPU thread is never on a coroutine switch stack (qemu_coroutine_forbid_current_thread; qemu_coroutine_switch aborts there), so nothing reachable only from the vCPU belongs on the list, and no block-layer coroutine may run on the vCPU thread (the CFI flash writeback starts from a bottom half). ?env=QEMU_COSTACK=1 logs every distinct stack at a switch and tools/asyncify-audit.mjs reports MISSING and UNUSED entries. UNUSED is only a candidate: most unobserved entries serve paths the run did not take. The log holds wasm function indices, so resolve it against the dist it came from.
  • wasm-EH longjmp composes with Asyncify only while no instrumented function calls setjmp. Keep setjmp callers off the onlylist. The build is -sSUPPORT_LONGJMP=wasm with the standard exnref instructions (-sWASM_LEGACY_EXCEPTIONS=0 -mllvm -wasm-use-legacy-eh=0): Firefox logs a deprecation warning for the legacy try, which the Firefox gate counts as an error, and emcc 4.0.10 passes LLVM the switch only for C++ exceptions. Check with wasm-dis --all-features x.wasm | grep -c '(try_table'. exnref needs Chrome 137, Firefox 131, Safari 18.4.
  • Firefox caps live wasm modules (~16k) and does not count code memory as GC pressure; a periodic throwaway allocation keeps its worker collecting dropped modules. Every translated TB must be staged in an open batch (w64_batch_begin_tb): a TB run from a module of its own works in Chrome and eats Firefox's budget. Only the Firefox gate sees it.
  • V8's arm64 code is not its x64 code, and only an ARM host shows it. For the same hot TB functions TurboFan emits 1.36x the instructions on arm64 (2026-11-10, Node 22's V8 12.4, bounds checks on). Measured on a phone (Snapdragon 750G, Chrome 156), towerblox:
    • A constant address costs by its size. A load or store at a constant address below 16380 (4-byte access; 32760 for 8 bytes, 8190 for 2, 4095 for one byte) takes it as an immediate offset (ldr w2, [x1, #4356]); below 64 KiB it is one movz first; above, movz + movk. With the CPU state in the heap those pairs were 19–22 % of all TB instructions. x64 folds any constant into the access. This is why the state sits at the bottom of memory (qemu/w64-low.h, wasm-fast-paths.md A11).
    • Explicit bounds checks cost 19 % there (--no-wasm-bounds-checks: x0.285 → x0.338), against ~8 % on x64. Each is a cmp + b.hs per access with a dynamic index (TLB entry, guest RAM), often with a sub of its own for the limit.
    • An index is constant for V8 only if the wasm says i32.const. The check is dropped while the graph is built (BoundsCheckMem, no machine-level folding yet), so i32.wrap_i64 (local.get $r) keeps its check even when $r was set from an i64.const two instructions earlier; the address is folded afterwards and the check stays, as cmp x13, #264; b.ls. The backend tracks registers a movi loaded for this (w64_const_base; towerblox +4.7 %, bobby +7.3 % on the phone).
    • Tiering is the same as on the desktop: a 10x lower --wasm-tiering-budget gives +4 %. The optimizing tier is not behind: 53 lazy baseline compiles a second on the vCPU thread at 156 us each (0.8 % of it), 10 TurboFan compiles a second in the background at 6.9 ms each (tools/perf/wasmtrace.mjs).
    • The thread is where it should be: the vCPU worker runs on a big core at its top frequency, 98.5 % busy; 72.6 % of it is TB code and 28.8 % the main module (x64: ~65 / 34).
    • Reading arm64 code without a phone: an arm64 Node under qemu-user prints TurboFan's code for a grabbed TB module in seconds (tools/perf/a64code.sh <module.wasm>, the modules from tools/perf/wasmgrab.mjs; scripts/setup-android-emu.sh linux-install installs qemu-user and the arm64 libraries). Take the Node whose V8 is the phone's Chrome's: Node 22 (V8 12.4) spills a TB's three parameters at entry and calls the pc-cache probe, V8 15.6 does neither. Weight the listing by the functions' self time (hot.json next to the grabbed modules) before reading it: the tail of a function is cold code and trap stubs, a bl per bounds check.
    • V8 flags on a phone that is not rooted: adb shell am set-debug-app --persistent com.android.chrome, then echo 'chrome --js-flags=...' > /data/local/tmp/chrome-command-line and am force-stop com.android.chrome; chrome://version shows the command line. Undo with am clear-debug-app and removing the file.
    • A dist the phone has not run yet reads ~3 % slow. A guest that is behind real time is in free-run by itself, so no bench build is needed: alternate the two dists, one run each, ~5 minutes a run. But Chrome keeps the main module's optimized code per URL, and the first run of a new dist has none (x0.318, then x0.331, then x0.334–0.341). A candidate just built against a baseline measured for hours loses 3 % before it starts: the first phone A/Bs understated their levers, and one candidate "lost" 4 % in its first pair and led by 0.7 % over the next four. Warm runs vary by ±1 %; three in a row within 0.5 % (x0.283, x0.284, x0.287) was luck taken for the method's resolution.
    • A listing does not price a lever there, even within one kind of instruction. Nine bounds checks out of a DSP block transition (27 instructions of ~160, ~11M transitions a guest second) were worth 4.7 % of towerblox and 7.3 % of bobby. Five plain instructions out of every chained transition, ARM and DSP (~28M a second; the typed chain table below), half as many instructions executed, were worth +0.7 % (inside the noise) and +2.6 %. Two more checks out of the DSP transition, priced from the first nine at ~1.5 % of bobby, read −4.1 % in one build and +0.5 % in the next build that contained them (performance.md, Closed ideas, DSP execution). Under ~2 % the phone tells builds apart, not mechanisms: measure every candidate build warm, over three rounds or more, and ship nothing from a count.
    • Stopwatch is the noisy scene on a phone: single runs of one build spread from x0.41 to x0.45 (ten runs each of two builds, 2026-11-11), towerblox and bobby within ±1 %. Two pairs there say nothing; ten said +0.3 %.
    • An indirect call through a funcref table is 21 instructions (V8 15.6, return_call_indirect): the table and its length from the instance, the bounds check, the entry's signature against a literal, the entry's code-pointer handle and instance, the frame teardown, the code pointer out of the code pointer table and br. Through a table of (ref $sig), non-null references to the call's own type, there is no signature compare and no null test: 16. A nullable (ref null $sig) still loads the signature word for the null test; a table with min = max makes the length a constant (15). JS cannot create such a table: a module has to define and export it, with an initializer expression; the element segments take the expression form (flags 5 and 6, ref.func; V8 fills them through the same lazy placeholders as function indices), and Table.grow/set need a function where they took null (cc1c25a551).
  • SpiderMonkey never patches a table slot when a function tiers up (Firefox 155 source, 2026-11-10). A slot written by an active element segment or Table.set keeps the code pointer of that moment, the baseline entry, and every later call through it runs the baseline prologue and hops through a jump table to the Ion code. Chained TBs enter each other only through the chain table, so that was every TB transition: towerblox ran at x0.96 where Ion-only (a pref) gave x1.31, and tiering up sooner (the wasm_lazy_tiering_level pref, even synchronous) gave nothing. table.init from a passive segment binds a slot to the best tier of that moment and can be repeated, so each Firefox batch carries a rebinder (w64_rebind_live). Import bindings and exported JSFunctions cache the pointer the same way and a page cannot refresh those. More facts:
    • Lazy tiering is always on; a page cannot ask for Ion-only compilation.
    • A function asks for Ion after ~20000 entries and loop headers at the default level: the baseline code counts down by size / 20 (1–127) at each of them from (30000 + 4000 × size) / 4, a third of that in a module whose code section is under 150 kB. One Ion compile runs at a time, so a scene takes about a minute to settle (towerblox: x1.15 over the first 20 s, x1.30 over 80 s, x1.35 with tier-up at the first call).
    • The Gecko profiler works headless from the environment: MOZ_PROFILER_STARTUP=1 MOZ_PROFILER_SHUTDOWN=<file> MOZ_PROFILER_STARTUP_FEATURES=js,leaf,cpu MOZ_PROFILER_STARTUP_FILTERS="DOM Worker,GeckoMain". On towerblox 98.8 % of the vCPU thread was JIT code, so nothing but the tier is Firefox's own cost.
  • A build flag in --extra-cflags is not on a compile line. meson gets two cross files, and the checked-in configs/meson/emscripten.txt replaces the generated one's c_args, so the C files compile at meson's -O2. Flags that must not go missing belong in configure's CPU_CFLAGS (the compiler's own argv), where -sMEMORY64 and -sSUPPORT_LONGJMP are. Grep build.ninja for a flag you passed. The -O3 on the link line does matter: without it emcc links at -O0 with assertions and no Binaryen pass.
  • An index narrows, a pointer does not. -sMEMORY64=2 lowers the memory and the table to 32 bits and leaves pointers as i64, so wasmTable.get(BigInt(i)) is a TypeError. When a mode switch changes a type, audit hand-written JS handles (table reads, Memory/Table construction) as well as the emitted wasm.
  • An EM_JS body goes through the C preprocessor. ??= is a trigraph for # and ??( for [, which only warns. Write if (x === undefined). #ifdef cannot switch code inside the body.
  • NULL does not trap in wasm. A NULL-pointer bug surfaces as an out-of-bounds access at NULL->field_far_away, frames away from the mistake, after small-offset accesses succeeded silently. Resolve the frames through the .symbols sidecar and disassemble the faulting offset with build/deps/emsdk/upstream/bin/llvm-objdump -d --start-address=. A hard trap is never host pressure, and a bisect that "fits" can fit because the bug predates both revisions.

wasm and V8

  • wasm has no relaxed atomics. A relaxed atomic store is a seq_cst store, which is a locked exchange on x64; a relaxed load is a plain load. A single-writer publish of an aligned word that readers tolerate stale can be a plain store.
  • A store to a cache line another thread reads costs ~24x: 2.2 ns alone, 52 ns with one reader spinning on the line (emscripten microbenchmark, September). The signature is a small function whose self time per call far exceeds its instruction count. Pad the line.
  • An uncontended mutex still costs a locked compare-exchange and a locked exchange in musl. At millions of acquisitions a second the fix is to stop taking it (A7's deferred BQL release). A deferred release is safe only with a structural bound on how long it can be held.
  • Emitted TB code starts in Liftoff; C in the main module runs in TurboFan. Liftoff zeroes every declared local at entry and is ~2x slower on TB-shaped code. A call from a TB module into the main module is ~2–3 ns (5–7 ns in situ), so moving work into a C helper is cheap at the call. Inside a real TB the same call cost ~14.5 ns, because the engine spills every live local and TCG treats all globals as written. An inline lookup of a dozen loads and six branches lost to the helper it replaced; the same cache comparing two or three words wins.
  • Read TurboFan's machine code before deciding what code costs. V8's wasm calling convention has no callee-saved registers, so a call on a cold arm spills every live value where it is defined, on the hot path, unless the arm is hinted cold. One metadata.code.branch_hint entry per inline TLB probe made video 20 % faster (September). A hypothesis can be tested offline by rewriting a captured module (tools/perf/wasm-bhint.mjs; capture with tools/perf/wasmgrab.mjs).
  • Locality only pays on a dependent load. A load from an address that the emitter wrote as a constant issues early and hides its latency. Removing a load whose address came out of another load won 5–11 %; packing the remaining constant-address slots densely was a wash.
  • A chained TB transfer is predictable per site. With per-site predictable targets every dispatch mechanism (indirect tail call, driver loop, merged br_table) measured the same 16–17 ns in tests/wasm/dispatchbench.mjs. Only an unpredictable target sequence separates them, and that is not what tb_add_jump produces.
  • An interpreter compiles to wasm at native speed (tools/interp-probe.c: 7.3 ns per op both ways). Before assuming a native cost ratio carries over, ask which tier each side lands in.
  • V8 caches compiled modules by their bytes. A microbenchmark that compiles the same module repeatedly measures the cache. Distinct bytes cost 2–3.8x more. Vary the input of anything that may memoise.

TCG backend design

  • A wasm JIT pays only if TB-to-TB control flow never leaves wasm. The first attempt (one module and instance per TB, a C dispatch loop between instances, registers as wasm globals) reached 1.3–2.3x over TCI and was discarded. The backend that shipped chains by tail calls through a funcref table, keeps registers in locals and batches TBs into modules.
  • Value-level correctness needs its own harness. That first attempt died of a data divergence with an identical PC stream for 470k TBs. The op-suite (tests/tcg-isa) and the lockstep digests exist for that class and were built before the backend.
  • Code that translates ahead of execution must probe without faulting. A lookup of a not-yet-executed target went through the faulting get_page_addr_code and the guest took a prefetch abort at a PC it had not reached.
  • A key the translator can stamp statically should not be compared at run time. hflags cannot change without ending the TB. A generation counter suits rare events only: hflags change 88k times a second, jump-cache flushes ~1.4k times per boot.
  • A counter that a fast path must keep exact is a constraint on that path. An exact per-entry TB counter, read only by a MIPS display, once switched off both TB-lengthening mechanisms. Make such a counter refundable, as icount is.
  • Backend constraints: immediates go through tcg_target_const_match and the out_rri/out_ri/out_i hooks. A bare const constraint letter with no register class trips get_constraint_priority's assert at boot.

Devices

  • A QEMU timer per hardware tick is a denial of service in wasm. A timer callback costs ~10 µs of JS clock reads, ~200x native. A device's deadline must be the next event somebody can observe, not the next tick (gptu.c, tpu.c, the lazy dif_v2 bus timer). A device that re-arms a timer on a register-write path is the same storm: the TPU once made 1.45M timer_mod calls a second on an idle screen.
  • When a stalled guest is really a starved one, profile every thread. That GPTU storm looked like a firmware wait: the vCPU was 94 % in futex_wait while the main loop ran one device's timer at 100 kHz under the BQL.
  • Replacing a deferral with a synchronous path needs its resume points. Every access that can drop the condition the loop stopped on must call back in. Keep the deferral as a backstop, armed only where progress is not otherwise guaranteed.
  • Before memoising a device callback, check re-entrancy. A skip-if- unchanged cache on a DMA request line blanked the display: driving the line re-entered the function through the DMAC, and the outer call then finished from stale inputs with the fresh key already stored.
  • Mechanisms are board-specific. LG boards, the SGOLD CX70 (dif_v1) and the EL71 (hot registers in regions smaller than a page, flash writes during boot) each hid a problem that no S75 profile contained. Work that is redone on every register write usually costs more than the per-word chain behind it.

Measuring

The binding method is in performance.md. These are the traps behind it.

  • A build that boots faster is measured earlier in the phone's life. scenebench walks into a scene as soon as the idle screen is up. The merge of smh/master 23d7df3200 brought SL65's boot from 53 s to 23 s, and its two scenes read −10.7 % and −4.7 % in the free-run A/B, 6 of 6 pairs each with a spread under 1 % on midi: as clean as a real loss. The firmware was 30 s deeper in its network search after boot. Signs: tIdle differs between the legs; delaying the faster leg by the difference removes the gap; the paced scene costs the same CPU on both. The SL65 scenes now start at a fixed guest time (startAt).

  • A counter on the slow path is not a hit rate. Work that TCG emits into the TB is invisible to every C-side counter, so a cache's successes are absent events. Size a cache by switching it off and watching the counter downstream. The pc cache was nearly deleted twice on a "0.28 % hit rate" while it answered seven eighths of the exits.

  • Count one step earlier before believing a zero. "The thing is rare" and "my probe never ran" look the same. A fast path guarded by a macro that no build defines compiles, links and A/Bs as "no change".

  • A path is not priced until something has been switched off. A sum of the events that counters name is a lower bound. The display path was closed at ~1 % by arithmetic and measured 15 % of wall when switched off. A call count prices a call site only if the work per call is constant.

  • Price times rate, both measured, and name the workload. A rate is a property of a workload, not of a function. A share is a ratio whose denominator moves: a rejected 0.1 % lever was 1.3 % after the rest of the wall halved. Re-price old rejections before trusting them.

  • Know what a probe can see.

    • Deleting work gives the whole prize, cost included, but only if the guest still runs. A lock cannot be probed by deletion.
    • Simulating a mechanism gives its hit rate and is silent on what the real thing adds to the path that still misses.
    • Duplicating existing code prices its deletion, never the insertion of a cheaper check in front of it.
    • Extra work must survive the optimiser (xor distributes over rotate; LICM hoists a duplicated call) and must not serialise through one shared sink. Turn the multiplier up until the guest visibly crawls, to prove that the knob arrived.
  • An A/B knob must restore the untouched path. If the "off" leg keeps part of the mechanism, the comparison flatters the change. An instrumentation knob that changes codegen can switch off the mechanism under test.

  • A comment explaining why something need not be measured is the thing to measure. "V8 serves this memory with trap handlers, so bounds checks cost nothing" stood for 34 rounds; the one-flag test read −26 %.

  • Fits and ratios.

    • A slope fitted across configurations is the price of everything the knob changed together, not a marginal cost. If the sweep extends past its optimum and changes sign, it was never marginal.
    • A high R² says that a line fits the points, not that the x-axis is the quantity it was named. Read a counter's definition, not its name.
    • Do not divide by a difference that does not clear the spread of the same quantity within one arm.
    • Two intervals from differently shaped experiments cannot be subtracted.
    • A counter incremented at translation time weights by compilation, never by execution.
    • Normalising per instruction does not make a host-paced or frame-paced counter guest-relative: an arm that runs 19 % faster shows −16 % on every per-second event. Parts must sum to their whole before any share is quoted.
  • Check that every leg ran the same workload. A mean over phases that behave differently reports the idle one. A fixed guest-time window does not fix what the guest did in it: 23 % of one J2ME game's legs were on its title screen, with rates inside the played legs' range. Compare guest-paced counters between legs before reading the clock.

  • Host noise.

    • A control that moves more than its known noise is a rejection signal. Locate the burst and drop those legs; do not model it as drift.
    • Rotating the arm order is a Latin square. Position was worth ~0.9 % per slot, enough to invent or destroy a 2 % effect.
    • Record host pressure with every run (tools/perf/hostmon.sh). The load comes from other tenants and is invisible in this container's process table.
  • Build both sides of an A/B the same way. An incremental build over a directory left mid-state ran ~5 % slow and faked a win across four invocations in both orders. Swapping the order cancels position, not a bad baseline.

  • When removing "measurement scaffolding", list what else the call did. A removed prologue import was also what opened the batch, and 20 % of TBs then ran from throwaway modules. Make invariants explicit calls.

  • A change can be right and unmeasurable. Report it as flat with the mechanism evidence (a profile share, a counter), never as the sample mean.

  • Profiles. DevTools resolves every wasm-function[N] through the main module's symbol map, so a frame from a TB module (wasm://wasm/…) wears a borrowed name. Bucket by URL; inside the TB bucket only the sum is meaningful. The vCPU worker's index moves between runs; identify it by content. Never pipe a profiler through tail.

  • A listing shows density, a census shows rate. Towerblox's hottest ARM TBs do one guest access per instruction, which read as "the probes are the scene". Counted, they were ~30M a second and a few percent of the vCPU: removing a quarter of them (one probe per LDM/STM) gained ~2 %. Count events per second before sizing a lever from a hot function's code.

Gates

  • Boot one fullflash per class. S75 was the only browser boot anyone watched for weeks while two board-specific breakages stayed green natively. EL71 is the only one that writes its flash file system while booting (the rewind and io barrier on a ROM device). KE800 and KE970 are LG firmware with an EFA sidecar. CX70 is SGOLD (dif_v1). The native suite is blind to every emscripten-gated change.
  • tools/bootcheck.mjs judges progress in executed instructions, not framebuffer updates: EL71 ends at a "set time and date?" wizard that never redraws. KE800 must also reach 1.5e9 instructions and KE970 1.2e9, because a guest parked at the LG logo still executes ~10k instructions/s and once passed at 590M.
  • Boards run as consecutive pages of one browser in the close tier. The second page loads the wasm from the cache and starts at full optimised speed, so a race can show in the s75→el71 order that never shows with el71 alone.
  • Every browser the page supports is a gate. The Firefox boot existed but was not in the ladder, and nine commits shipped with Firefox dying at the logo.
  • A stale boards.tar looks like a qemu regression (board settings silently revert). Every deploy path repacks it.

Shell and container traps

  • Never edit a shell script that is running. Bash reads it by byte offset as it goes. Copy it and edit the copy.
  • grep -c prints 0 and exits 1 on no match, so n=$(grep -c PAT f || echo 0) yields two lines. Use ${n:-0}.
  • Wait on an artifact, not on the process table. A pgrep -f waiter matches any command line that carries the pattern, its own included, and falls back to comm for zombies. kill -0 succeeds on a zombie forever, because PID 1 here reaps nothing.
  • ps %CPU is a lifetime average. Use top -bn2 for what is running now. A killed driver leaves its headless Chromium emulating a phone; count browsers before trusting a number.
  • The HUD checks need DejaVu Sans Mono as monospace. The strip's budget is the box width over the width of a monospace "0", so a narrower font keeps more tokens and ui-acceptance's v4.3 fails at 360 and 320 px. playwright install-deps brings fonts-wqy-zenhei, which fontconfig then picks for monospace; with fonts-dejavu-core missing it was that or IPAGothic (2026-11-13). Check fc-match monospace after installing packages. The container also lost libc6-dev, glib and the other native build headers that day; scripts/build-native.sh names what is missing.

pmb887x facts

  • The RTC CNT register is a linear Unix-seconds counter to Siemens firmware and a packed calendar to LG firmware. The board config's [rtc] format selects the layout; the wrong one gave a 2091 date and a clock jumping 16 minutes per minute.
  • The S75 panel is 132×176; EL71 and KE800 are 240×320, 3.3x the pixels through the same display chain.
  • A slow J2ME stopwatch is throughput, not pacing: the guest never halts there.
  • Driving an LG phone from a tool: the KE800 and KE970 swallow the first key that comes after ~10–15 s (guest) without one, whatever the key, while they wake up (KE800: a key after 10 s idle typed, after 15 s it was lost). A tool that presses one key per screenshot loses every press and the phone looks dead; send a key that does nothing there first (vol_up). The Siemens phones do not do this. A digit opens the dialler, whose Options ▸ New message ▸ Text message is the way into an editor. The KE970's editor starts in T9 (# four times reaches Abc). The EL71 test image is Russian and asks to set the date and time about a minute in; its idle left soft key is "Нов.SMS" only once it is on the GSM cell. (2026-11-13, the multi-tap work.)
  • A board config without the RF transceiver its firmware drives makes Layer 1 give up at random. The CX70 panicked in l1bbcsg (EXIT: 000A:017C / 000B:017C, x65-style dump) in 7-11 of 12 browser boots of 240 s, at 30-150 guest s, more often the busier the host, and never natively or under icount. A bisect over the qemu range found a DSP translator commit (455f756d82) that made it common, but reverting that on the newer pin changed nothing. The cause was the board: bsp 191612c gave the CX70 its pmb6270 on TPU:RFSSC0, and with qemu's model of it 0 runs of 24 exit, while the same build with that one [peripheral.RF] block taken out of boards.tar exits in 8 of 12 (2026-11-13). A firmware timing panic that only some hosts see can be a missing device, not a timing bug; bootcheck now catches the x65 dump (it only knew >>EXIT<<, and passed these runs).
  • Multi-tap tables are read off the firmware: a Siemens editor shows the tapped key's whole cycle in a bar along the bottom; an LG one shows none, so tap the key 1, 2, 3… times with a tap of another key between the groups and read the text.
  • Tap speed is per phone, and the thresholds are sharp. Typing the same two strings ("szvo lif yr", all different keys; "cab ba ll", same-key letters) over and over through _wasm_send_key, erasing between runs and comparing a hash of the LCD's text area with a slow reference, gives all-pass or all-fail per setting (2–3 runs each, 2026-11-13). It goes by the chip, not the generation: of 18 phones, every PMB8875 board (C65, C72, C75, CX65, CX70, CX75, M75, ME75, S65, S66, SL65 — the C75/CX75/M75 are x75s) still types at 15+15 with a multi-tap timeout of 0.7–0.8 s from the release, while the PMB8876 ones lose taps that come less than 60–70 ms apart (S75, C81, M81: 60+10 and 40+30 type, 40+20 does not; E71, EL71, S68, SL75: 30+30 types, 20+20 does not) and time out after 0.9–1.0 s. The EL71 had first come out with the S75 group: that run's taps were timed on the page (next lesson), which shortened some, and the retest with qemu spacing them typed 40+20 and 30+30. The erase key follows it too: "<C" is the left soft key on every PMB8875 editor, the right one on every PMB8876. Both LGs type at 15+15; timeouts KE800 0.9–1.0 s, KE970 0.6–0.7 s. The S75's had been put at ~0.8 s by eye, which was wrong. A key that takes the pending letter at once would beat the timeout, but joystick right is not one: at the end of the text the S75 and the LGs add a space with it, and in the middle of the text the EL71 and C81 take the letter and step over the next one. The harness is plain: hash only the rows below the title bar (counters and case indicators change after a run), erase by count after a passing run, and keep the phone busy, as a Siemens editor left alone for ~3 minutes falls back to idle.
  • Taps have to be spaced in the guest's time, by qemu. The page timed each edge itself, polling _wasm_vclock() and sending the edge when its guest time had come, but the guest sees the edge only when the main loop's bottom half runs, while the vCPU keeps running. On a throttled host (phone at 0.47× real time) the KE970 lost one tap in 16 page-typed runs at 30+30 (2026-11-13): a late hand-over had shortened a hold or a gap. Now the page queues a character's edges at once with their spacing (wasm_send_key_after) and a QEMU_CLOCK_VIRTUAL timer hands each one to the guest. Side by side on equally throttled cores (tools/slowhost.sh, 8 spinners per core, phone at 0.4× real time) the KE970 typed 6 of 16 right with the old page code and 15 of 15 with the new; S75, SL65 and KE970 typed 16 of 16 each with the host stalled 60 ms in every 310. A slow host only shows when it is slow for the phone: alone on 4 cores at 25 % each the phone kept up with real time and nothing failed either way. Test tools that tap with timing (the survey's sweeps) need the same queue, or they measure their own lateness: the old harness had the EL71 losing taps at 40+20, which it types.
  • Not every model in fullflashes-untracked could be typed on (2026-11-14). CF75: the board leaves the clamshell's lid hall sensor (USART1_CTS) floating, so the firmware boots "closed" and never starts the main display, and qemu has no model of either 128×160 main panel the firmware picks by strap pins (S6B33-style or Epson-style); a bsp patch for the sensor alone makes it draw to the bus, not the screen. CL61 and M72: the page's recalc rejects their dumps ("Not a recognizable Siemens fullflash layout") although tools/recalc-check.mjs reads their keys; run as is, the M72 ends in crypt_bfx (0x0404) and the CL61 shows "Wrong Software". SK65: the page stopped answering right after boot, and its keypad does not work here anyway. The two benqt C81 dumps carry no intact keys (fullflashes/rrC81 .bin is the one that boots), and the fwcenter SL75 "Hydra" dump ends in modeman_sm before idle (the benqt SW52 one boots).
  • The EL71 and C81 end in a firmware EXIT in modeman_sm (code 0x0009) when the red key is pressed at idle. The CX70 ends in camera_asic (0007:D166) whenever its camera starts: joystick left at idle is the camera shortcut there (on the S75 it is a new SMS), and Menu ▸ Камера ends the same way, while left moves the menu cursor left as it should — the board has no model of the camera chip, not a wrong key. Neither is the typing's doing; tools should not press those keys at idle.
  • The KE970's # goes abc → ABC → T9 Abc → T9 abc → T9 ABC → 123 → Abc → abc, unlike the KE800's, and right after a capital one more press than that is needed to get back to abc (7, typed through the page). Every phone opens a new message in sentence case (Abc), and the KE970 goes back to it after "! "; the page's case tracking takes the phone to be in lower case, so a capital typed there comes out wrong (Siemens x75: # lands in 123 and the letters become digits).