Files
reims-vgpu/scripts/gpu-load-probe/gpu-load-probe.sh
T
Anees IqbalandClaude 23a6e3080f 📝 The load probe's WebGL dial collapses the guest rather than the device, and the layers dial is the one that drives the gather rail hardest
Pathway: x86 macOS / Linux Vulkan. Probe only; no device code.

Four driven macos-13 boots of one binary put numbers on the three dials, and
one of them does not do what the probe was written to make it do.

  dials                                     duty   draws/s  gather regions/s
  (sustained-animation probe, for scale)    0.83    26 800           427 000
  layers=24&boxes=6                         0.68    11 525           270 807
  layers=16&boxes=6&verts=30000&tex=512     0.14     1 390            34 976
  layers=8&boxes=6&verts=60000              0.11     1 017            26 592

**Any WebGL at all collapses the guest to ~1 000 draws a second at duty 0.11.**
The device is then idle seven eighths of the time and the boot measures
Safari's WebGL path rather than this device — the exact failure the probe
exists to avoid, one layer further out. The dial is kept and documented as not
usable for ranking, because the collapse is worth being able to reproduce in
one command; it is not quietly left looking like a working axis.

Two fixes went in first, so the reading above is not measuring the page:

  - the vertex array is built once and only re-uploaded. The first version
    rewrote all `verts * 2` floats per frame, which at verts=90000 gave 1 329
    draws/s at duty 0.12 — indistinguishable from the collapse above, and
    caused by the page rather than the guest. `bufferData` re-uploads the whole
    array regardless, so eight mutated entries per frame keep the device
    traffic and stop a browser eliding the call.
  - the 2D canvas draws two fills rather than twenty-five, for the same reason:
    the upload is `tex * tex` either way and the rest was guest paint time
    bought at the device's expense.

`layers` is the axis that works, and its value is the *shape* rather than the
size: at 24 layers it drives 23.5 gather regions per draw against the sustained
probe's 15.8, so it is the heavier arm for anything about the guest buffer
gather despite the lower absolute draw rate. Nothing here beats the
sustained-animation probe for total device load, and the doc now says so.

Verification performed:
  - the four driven macos-13 boots above, quiesced host, `bash -n` on the script
  - each boot's dials are recorded in its own `load-url.txt`

Not verified: `tex` has not been measured on its own, and no rail but macos-13
has run this probe.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 08:08:59 +03:00

146 lines
7.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Drive the guest with a load whose weight is a dial, served from the host.
# Fourth probe alongside `maps.sh`, `hammer.sh` and `sustained-animation-probe`;
# same (outdir, seconds) interface, so it drops into `ab.sh` as `AB_PROBE`.
#
# gpu-load-probe.sh <outdir> <seconds>
#
# Why it exists. The sustained-animation probe has **saturated** on macos-13:
# the guest produces ~26 800 draws and ~76 presented frames a second whatever
# the device does, the drain worker sits at duty 0.83, and a measured
# 3.9 us/chain CPU saving moved `draws_s` by less than 0.1 % because the worker
# spent what it saved waiting for guest work. A probe the device cannot fall
# behind cannot rank a device change, in either direction — it reports "no
# effect" for a real win and for a real regression alike.
#
# So this probe makes each guest frame heavier instead of asking for more
# frames, which is also the only thing a page *can* do: the guest's frame rate
# is its own display cadence and no content raises it.
#
# The load is three independent dials, set through `GPU_LOAD_ARGS`, because they
# land on three different rails:
#
# layers=N composited surfaces -> the writeback / store rail
# verts=K per-frame WebGL buffer upload -> the **guest buffer gather** rail
# tex=W per-frame 2D canvas repaint -> the sampled-image rail
#
# GPU_LOAD_ARGS='layers=16&boxes=8&verts=90000&tex=1024' \
# kb/harness/ab.sh /tmp/out on macos-13 25
#
# Name the dials in any result. Two boots at different `GPU_LOAD_ARGS` are two
# workloads, not two readings, exactly as two rails are two guest drivers.
#
# # Turning a dial up can make the measurement worse, and the reading that says
# # so is `drain_duty`
#
# The failure this probe exists to fix has a mirror image: a load heavy enough
# to starve the *guest* measures Safari's JavaScript engine instead of the
# device, and looks like a very slow device while doing it. The first run of
# this probe at `layers=16&boxes=8&verts=90000&tex=1024` reported a worst second
# of 11.3 Hz — and produced **1 329 draws a second at drain duty 0.12**, against
# 26 800 at 0.83 on the far lighter CSS-only probe. The device was idle seven
# eighths of the time.
#
# So read `drain_duty`'s `duty` and `draws` before believing any frame rate off
# this probe, and choose dials that push `duty` toward 1.0 with `draws` at or
# above what the sustained-animation probe produces.
#
# # What each dial is worth, measured — and the one that does not work
#
# Four driven macos-13 boots, one binary, quiesced host. `verts` builds its
# array once and only re-uploads it, so none of this is the JavaScript fill:
#
# dials duty draws/s gather regions/s
# (sustained-animation probe, for scale) 0.83 26 800 427 000
# layers=24&boxes=6 0.68 11 525 270 807
# layers=16&boxes=6&verts=30000&tex=512 0.14 1 390 34 976
# layers=8&boxes=6&verts=60000 0.11 1 017 26 592
#
# **The `verts` axis does not work on this rail.** Any WebGL at all collapses
# the guest to ~1 000 draws a second at duty 0.11 — the device is then idle
# seven eighths of the time and the boot measures Safari's WebGL path, not this
# device. That is a property of the guest, not of the dial: the array is static
# and the shader is two lines. Do not use `verts` to rank a device change until
# something explains the collapse; the dial stays because the collapse is itself
# worth reproducing in one command.
#
# `layers` is the axis that works, and it is worth using for what it does to the
# *shape* rather than the size of the load: at 24 layers it drives **23.5 gather
# regions per draw against the sustained probe's 15.8**, so it is the heavier arm
# for anything about the guest buffer gather even though its absolute draw rate
# is lower. `tex` has not been measured alone.
#
# Nothing here beats the sustained-animation probe for total device load. That
# probe reaches duty 0.83 and this one does not, so it remains the arm for
# ranking a change; this one is for loading a *particular rail* harder than a
# compositing page does.
#
# The page is served by the host over QEMU's user-net gateway (10.0.2.2), not
# fetched from the internet: a probe whose workload can change under it cannot
# be A/B'd, and the rails have no reason to have working DNS.
set -u
OUT="${1:?outdir}"; SECS="${2:-40}"
REPO=/home/aneesiqbal/Projects/steelbrain/reims-vgpu
export QMP_SOCK="${QMP_SOCK:-$REPO/vm/disks/run/qmp.sock}"
Q="$REPO/scripts/qmp/qmp.py"
FAILLOG=/tmp/reims-vgpu-fail.log
# Fixed port: the guest is told the URL once and a random port would have to be
# plumbed through `open`. A different default from the sustained probe's 8123,
# so a stray server left behind by one cannot serve the other's page.
PORT="${GPU_LOAD_PORT:-8124}"
GATEWAY=10.0.2.2
ARGS="${GPU_LOAD_ARGS:-layers=8&boxes=6}"
mkdir -p "$OUT"
# Serve from the page's own directory so nothing else in the repo is exposed.
python3 -m http.server "$PORT" --directory "$REPO/scripts/gpu-load-probe" \
>"$OUT/httpd.log" 2>&1 &
HTTPD=$!
trap 'kill $HTTPD 2>/dev/null' EXIT
sleep 1
kill -0 $HTTPD 2>/dev/null || { echo "http server failed to start:"; cat "$OUT/httpd.log"; exit 2; }
URL="http://$GATEWAY:$PORT/load.html?$ARGS"
echo "serving $URL (pid $HTTPD) secs=$SECS"
# The dials are the workload, so they go in the output directory rather than
# only into this script's stdout — a result read later has to be able to say
# which load produced it.
printf '%s\n' "$URL" >"$OUT/load-url.txt"
# `open -a` at setup and never at drive time, so a rail with flaky ssh still
# produces a measurable window. Safari because it is on every rail from macos-11
# up and its compositor path is the one the window server actually serves.
timeout 60 ssh -o BatchMode=yes macos-vm "open -a Safari '$URL'" 2>/dev/null \
|| { echo "could not open Safari on the guest"; exit 3; }
# Safari has to fetch, lay out, compile the WebGL program and get a first frame
# composited before the measurement means anything. Longer than the sustained
# probe's 12 s because a shader compile is on this page's warm-up path.
sleep 16
read -r W H < <("$Q" size) || { echo "no display size"; exit 2; }
echo "display ${W}x${H}"
# Full-screen it, so the load drives the whole scanout rather than a window
# inset in a static desktop. ctrl+cmd+f is Safari's binding and needs no chrome
# geometry to be guessed — `meta_l` is Command in QEMU's qcode names, which is
# not free choice. Then park the pointer in a corner: a cursor resting over a
# moving layer adds hover work that is not the workload under test.
"$Q" key ctrl+meta_l+f >/dev/null 2>&1
sleep 3
"$Q" move 4 4 >/dev/null 2>&1
sleep 2
# Mark the log so only the driven window is measured.
OFFSET=$(stat -c %s "$FAILLOG")
# Nothing to drive: the page animates itself. That is the point — no host input
# lands during the window, so nothing in the measurement is the probe's own cost.
sleep "$SECS"
tail -c "+$(( OFFSET + 1 ))" "$FAILLOG" >"$OUT/window.log"
# Reading a captured window is not specific to this probe, so the analysis is
# not carried here. `ANIM_ANALYZE` names it — the same variable the sustained
# probe uses, because the window format is the device's and not the probe's.
ANALYZE="${ANIM_ANALYZE:-}"
[ -n "$ANALYZE" ] && [ -f "$ANALYZE" ] && python3 "$ANALYZE" "$OUT/window.log"
exit 0