# qemu-tool settings for the scale-out ernic+rocjitsu fleet.
#
# An N-VM rocm-ernic mesh, one emulated RDMA NIC and one rocjitsu GPU per VM.
# Not copied to qemu/.env -- named explicitly, the way the rocjitsu lane does it
# (see ansible/playbooks/roles/rocjitsu_gpu_test/defaults/main.yml):
#
#   qemu-tool gen-compose --env-file qemu/env/scale-out
#   qemu-tool compose --env-file qemu/env/scale-out \
#     --stack vfio-user-ernic-rocjitsu-scale-out --profile metrics up -d
#
# Everything in qemu/env/example applies here too -- same syntax, same
# precedence, same consumers. This file adds the fleet keys and the list
# semantics below. Read env/example first; it explains the keys that are
# merely repeated here.
#
# ---- Layering --------------------------------------------------------------
#
# This file is the golden one: it is authoritative, it is what packaging ships,
# and it is what the committed stack under
# qemu/compose/vfio-user-ernic-rocjitsu-scale-out/ is generated from, so
# `gen-compose --check` in CI compares against this file and nothing else.
#
# A deployment that needs different values does NOT get a copy of it. --env-file
# is repeatable and later files win key by key, so a deployment is this file
# plus a short overlay carrying only the keys that differ:
#
#   qemu-tool gen-compose --env-file qemu/env/scale-out \
#     --env-file qemu/env/overlay-mi100 \
#     --output-dir /var/lib/qemu-tool/stacks/mi100-fleet
#   qemu-tool compose --stack-dir /var/lib/qemu-tool/stacks/mi100-fleet \
#     --env-file qemu/env/scale-out --env-file qemu/env/overlay-mi100 \
#     --profile metrics up -d
#
# Both directory flags are load-bearing. gen-compose defaults its output to the
# committed stack directory, so an overlay render without --output-dir writes a
# 2-VM or 32-VM fleet over the golden 8-VM one and the Gen Compose Check lane
# fails on the next push. And VM_COUNT and the VM names are baked into the
# generated YAML rather than interpolated from the env file, so a compose run
# without --stack-dir brings up the committed 8-VM stack no matter which layers
# it was handed.
#
# Two overlays are committed, and both are deltas only:
#
#   qemu/env/overlay-ci      the two-VM fleet in report-for-lmcache.yml
#   qemu/env/overlay-mi100   the 32-VM fleet on ctr-mi100-rack33a-9
#
# Restating a golden value in an overlay is the thing to avoid -- it is a copy
# that no longer tracks, which is exactly how the four hand-synced files this
# replaces drifted. For a machine that is only yours, qemu/env/local-* is
# git-ignored and layers the same way.
#
# ---- List semantics -------------------------------------------------------
#
# Per-VM values are comma-lists, not numbered keys: VM1_NAME/VM2_NAME does not
# survive 8 VMs, let alone the mesh's 64. For any key naming a scalar VMConfig
# field:
#
#   a bare value broadcasts to every VM        VM_VCPUS=4
#   a comma-list applies positionally          VM_VMEM=8192,8192,...,16384
#   any length other than VM_COUNT is an error, naming the key and both lengths
#
# The exception, and it matters: three VMConfig fields are ALREADY list[str] --
# pci_hostdev, vfio_userdev, extra_hostfwd (config.py:73,76,84) -- where the
# commas mean "several values for ONE VM". VM_EXTRA_HOSTFWD=a,b is two hostfwd
# rules for every guest, NOT one rule each for two guests. The generator tells
# the two cases apart from VMConfig's own type hints rather than a hand-kept
# list of names, so a scalar field added later becomes per-VM-overridable for
# free. Do not "fix" a list[str] key by padding it to VM_COUNT.
#
# The comma-list form is understood by the generator ONLY. run-vm and gen-vm
# coerce VM_VMEM and friends with int(), so pointing them straight at a file
# using it exits with "Error: VM_VMEM must be an integer, got '8192,...'".
# That is the intended split and not a bug to work around: the fleet's run-vm
# invocations get their values as CLI flags the generator has already resolved
# per VM, and never read this file. Keep the lists commented out while you are
# also using this file for one-off gen-vm/run-vm runs.

# ---------------------------------------------------------------------------
# Fleet shape
# ---------------------------------------------------------------------------

# Authoritative. Names no VMConfig field, so run-vm ignores it
# (envfile.overrides() iterates dataclass fields, envfile.py:98-99).
#
# Ceilings, nearest first -- and none of them is memory:
#
#   ~40 registered mesh nodes. Past that, workers die on "TCP: Registration
#   timeout" in a permanent restart loop and their guests die with them. The
#   mesh is a full mesh, so registering node N+1 costs N new connections
#   against a fixed timeout, through a single-threaded manager. Asking for 64
#   VMs settles at 40 of 64, on an idle host as much as a busy one. This is
#   the wall that actually binds; see AGENTS.md issue 17.
#
#   VM_VCPUS x VM_COUNT <= nproc, plus ~25%. The mesh manager's heartbeat
#   timeout is 20 s of wall clock and is not tunable, so an oversubscribed host
#   does not just run slowly -- the manager mistakes slow nodes for dead ones,
#   evicts them, and every guest attached to an evicted node dies with
#   "vfio-user: timed out waiting for reply". Measured on 128 cores at 4 vCPU:
#   40 VMs clean in 117 s, 44 lose 3, 48 lose 7, with 107G of 503G in use.
#
#   VM_SHM_SIZE x VM_COUNT <= /dev/shm -- at 8g, ~30 VMs on a 252G host.
#
#   64 mesh nodes (rdma_backend_tcp.c:2570), which is a cap on CONNECTION
#   EVENTS, not on VMs: a reconnect takes a new node id and never reclaims the
#   old one. See AGENTS.md issue 13. Listed last because it is not reachable:
#   the 64-VM fleet peaked at node id 30 before registration stopped working.
#
# None of them binds at 8.
VM_COUNT=8

# Identity. Leave VM_NAMES empty to derive <VM_NAME_PREFIX>-<n> for n in
# 1..VM_COUNT; each VM needs its own qcow2 overlay of that name, which
# gen-compose prints the gen-vm commands that create them. Set VM_NAMES to name
# them individually;
# if set, its length must equal VM_COUNT.
VM_NAME_PREFIX=stebates-fleet
#VM_NAMES=

# ---------------------------------------------------------------------------
# Images -- containers AND qcow2, one build stamp across all four
# ---------------------------------------------------------------------------

# batesste-ci-images tags are <date>.<ci-sha>-<component>, and the qcow2 is
# published to Docker Hub under the same scheme, so "is this set coherent?" is
# a string comparison. The generator asserts it: all four must share one
# <date>.<ci-sha>, and QEMU_IMAGE/ERNIC_IMAGE must share one vfu.* revision.
#
# Both checks guard the same failure. A guest driver and a host rocm-ernic
# server built from different SHAs do not fail cleanly across the vfio-user/DSR
# boundary -- they surface as the DSR -ETIMEDOUT and "Failed to register ibdev"
# symptoms in AGENTS.md, which look like a wedged device rather than a version
# problem. At 8 VMs that is an expensive afternoon.
#
# Pinned to 20260925.g12f12f8: the newest stamp at which the qcow2 and all three
# containers exist. The 2026-09-29 push rebuilt the containers but not the
# ernic-rocjitsu qcow2; pairing them would put a 7b6fa94 guest against a 1484557
# server. Move all four together when the matching qcow2 publishes.
# STOCK QEMU 11.1.1, which cannot do vfio-user P2P DMA. Left pinned here
# because the fork cannot help yet either -- see below -- but anything
# depending on one vfio-user device DMAing into another's BAR (LMCache P2P
# reading GPU memory over the ernic, for instance) will not work on this
# image, and will not say so: the BAR window is simply never advertised.
#
# The fix is one commit on sbates130272/qemu, branch
# dev/stephen/pci-mmio-bridge-submit:
#
#   31e3d06a "hw/vfio: assign region fd to RAMBlock for vfio-user P2P DMA"
#   (2026-09-26, hw/vfio/region.c, +17)
#
#   vfio_user_dma_map skips sending an fd in DMA_MAP when
#   memory_region_get_fd() returns -1. For vfio-user mmap regions the backing
#   fd arrives from GET_REGION_INFO into vbasedev->region_fds[] but is never
#   propagated to the RAMBlock, so the GPU BAR window is never advertised to
#   peer vfio-user servers.
#
# NO PUBLISHED IMAGE CONTAINS IT. Every tag of
# batesste-ci-images-ubuntu-qemu-libvfio-user-sbates-fork is built from
# qemu.d757fa6 (2026-09-22), which is one commit short of it -- the fork
# image needs a rebuild at 31e3d06a or later. The fork's other addition, the
# `pci-mmio-bridge` device, IS in those images (absent from stock), but it is
# a different mechanism and not the one P2P DMA needs.
#
# Once rebuilt, switch to the fork tag whose <date>.<ci-sha> stamp matches the
# other three images, so _check_image_coherence still passes:
#   sbates130272/batesste-ci-images-ubuntu-qemu-libvfio-user-sbates-fork:20261030.gadc94af-qemu.f91f120-vfu.3719c3a
QEMU_IMAGE=docker.io/sbates130272/batesste-ci-images-ubuntu-qemu-libvfio-user:20261030.gadc94af-qemu11.1.3-vfu.5b9c722
ERNIC_IMAGE=docker.io/sbates130272/batesste-ci-images-ubuntu-rocm-ernic:20261030.gadc94af-ernic.8f35f4a-vfu.5b9c722
ROCJITSU_IMAGE=docker.io/sbates130272/batesste-ci-images-ubuntu-rocm-rocjitsu:20261030.gadc94af-rocjitsu.73c3cf3

# The backing qcow2, as an OCI artifact -- artifactType
# application/vnd.batesste.vm-image.v1, one zstd layer named
# batesste-ci-vm.qcow2.zst. Not a runnable image: fetch it with `oras pull`,
# not `docker pull`. `qemu-tool gen-vm --backing-image "$VM_BACKING_IMAGE"`
# does the pull and the decompression.
# The bare (non -qcow2) tag is a conventional image carrying the same file,
# ~2 GiB larger, extractable with docker create + docker cp if oras is absent.
VM_BACKING_IMAGE=docker.io/sbates130272/batesste-ci-images-ubuntu-qcow2-gen-ernic-rocjitsu:20261030.gadc94af-vm.resolute-ernic-rocjitsu-qm.ae551b3-qcow2

# ---------------------------------------------------------------------------
# Per-VM resources  (scalar broadcasts; comma-list of length VM_COUNT overrides)
# ---------------------------------------------------------------------------

# Do not drop below 4 on an ernic stack: ionic_lif_size() derives its EQ count
# from num_online_cpus() and ionic_create_rdma_admin() rejects fewer than
# IONIC_EQ_COUNT_MIN, so ionic_rdma never probes. The only symptom is
# "Failed to register ibdev" in the guest log. Applies to every VM in the
# fleet, so a per-VM list that drops one below 4 breaks only that VM -- which
# is harder to spot than breaking all of them.
VM_VCPUS=4
VM_VMEM=8192

# Shared memory for the vfio-user memfd backend. Must be >= VM_VMEM MiB, per
# VM. VM_COUNT of these have to fit in /dev/shm simultaneously.
VM_SHM_SIZE=8g

# A heterogeneous fleet looks like this -- VMs 7 and 8 get 16G, the rest 8G:
#VM_VMEM=8192,8192,8192,8192,8192,8192,16384,16384

# rocjitsu GPU config, a filename under /usr/local/share/rocjitsu/configs/
# inside the rocjitsu image. Available: gfx1250_mi455x.json gfx950_mi355x.json
# gfx942_cdna3.json gfx1100_w7900.json. Per-VM lists work here too.
ROCJITSU_CONFIG=gfx1250_mi455x.json

# ---------------------------------------------------------------------------
# Fleet-wide -- never per-VM
# ---------------------------------------------------------------------------

# Not /var/lib/qemu-tool/images: this checkout keeps its qcow2s in-tree.
# ${HOME} rather than a literal path: the same checkout is used from accounts
# whose home differs (/home/AMD/stebates and /home/batesste, so far), and a
# hardcoded one silently starts every guest against a missing qcow2 --
# `Could not open ...: No such file or directory`, with compose reporting the
# container as Started. Compose interpolates this from the environment when it
# reads the env file.
VM_IMAGES_DIR=${HOME}/Projects/qemu-minimal/images

# Required, not optional, at VM_COUNT > 1. All VMs open one backing file, which
# needs backing.file.locking=off (run_vm.py:267-269). images/ is also NFS
# here, where qcow2 locking is unreliable regardless of sharing.
VM_BACKING_SHARED=true

# The guest's login account. gen-compose puts this in the generated fleet
# inventory, so ansible and the env file cannot disagree about it -- but on the
# fleet path gen-vm never APPLIES it: both --backing-image and --backing-file
# return before cloud-init (gen_vm.py:79-90), so this has to match the account
# that is already in the qcow2.
#
# A fleet backing image is baked with ansible/playbooks/vm-ernic-fleet.yml,
# whose ernic_fleet_guest role creates "ubuntu" (ernic_fleet_user, uid 1001)
# with a password and NOPASSWD sudo -- so "ubuntu" is what a fleet guest has,
# and one account under one name is what this repo expects everywhere.
#
# An image that does not carry it cannot be reached at all, and the symptom is
# misleading: gen-vm reports "VM did not accept SSH in time", which reads as a
# boot failure and is a login failure. --username overrides this for a single
# invocation, which is the way into an image baked before this was true.
VM_USERNAME=ubuntu
VM_PASSWORD=ubuntu

# /16 the fleet's containers are addressed out of. Every service gets a fixed
# address -- <prefix>.<family>.<n>, family 0 infra / 1 ernic / 2 rocjitsu /
# 3 qemu -- and nothing resolves a service name at run time.
#
# That is a scaling fix, not tidiness. Docker runs one embedded DNS resolver
# per network, and a fleet start burst saturates it: at VM_COUNT=48 (144
# containers) workers died with "Temporary failure in name resolution", and
# because the mesh hands out a NEW node id on every reconnect and never
# reclaims the old one, the restart churn walked a 48-VM fleet to node id 61
# against a 64-node protocol ceiling. Change this only to dodge a subnet
# collision with something else on the host.
FLEET_NET_PREFIX=172.31

# TCP port the ernic mesh manager listens on; every worker connects to it.
# One port for the whole fleet -- the services are on the compose network, so
# there is no host-side collision to avoid.
ERNIC_TCP_PORT=6320

# ---------------------------------------------------------------------------
# Derived per-VM identity
# ---------------------------------------------------------------------------
#
# All four are computed from VM_COUNT and the bases below. The override lists
# exist for the awkward cases -- an image whose netplan pins a MAC, or a host
# where some port is already taken -- and should normally stay empty.
#
#   ssh port   VM_SSH_PORT_BASE + n - 1
#   RDMA MAC   <ERNIC_MAC_PREFIX>:<n >> 8>:<n & 0xff>
#   guest IP   <ERNIC_GUEST_SUBNET>.<10 + n>
#
# The ernic and rocjitsu socket paths (/run/vfu/{ernic,rocjitsu}-<n>.sock) are
# derived only, with no override: they are internal wiring between services the
# generator emits together, so an override could only desynchronise them.

VM_SSH_PORT_BASE=2222

# "rocm" in ASCII. 0x72 has the locally-administered bit set and the multicast
# bit clear, so the whole space is ours to hand out. Two derived octets, so the
# scheme is good to 65534 VMs; the mesh gives out at 64 first.
ERNIC_MAC_PREFIX=72:6f:63:6d

# Guests get .11 upward. Avoid .1: the mesh manager claims it as its DHCP
# server_ip and intercepts ARP for it, so a VM that takes .1 is unreachable in
# a way that looks like a driver fault (AGENTS.md known issue 1).
ERNIC_GUEST_SUBNET=192.168.100

#VM_SSH_PORTS=
#ERNIC_MACS=
#ERNIC_GUEST_IPS=


# ---------------------------------------------------------------------------
# Emulated NVMe -- LMCache's L2 tier
# ---------------------------------------------------------------------------
#
# One NVMe device per guest. run-vm creates the backing qcow2 itself
# (<vm-name>-nvme1 under VM_IMAGES_DIR), so there is no gen-vm step to pair
# with this the way there is for the root disk.
#
# This is where L2 belongs, and the alternative is worse than it looks: an L2
# fs adapter pointed at a path on a tmpfs writes KV chunks into RAM until the
# filesystem fills, which on a 16G /tmp takes one bench run.
#
# A bare count is the common case. The field also accepts a negative count
# (null_blk) or a literal QEMU argument string, and all three pass through to
# run-vm unchanged.
VM_NVME=1

# Put each vfio-user device behind its own pcie-root-port.
#
# q35 IS a PCIe machine, but a device with no bus= lands on pcie.0 as a
# CONVENTIONAL PCI endpoint -- no Express capability, so no link speed and no
# link width. The guest's ionic then reports
#   0.000 Gb/s available PCIe bandwidth (Unknown x255 link)
# and `lspci -vv` shows zero Express capabilities on the device.
#
# That is cosmetic for the Ethernet path but not for DMA between two
# vfio-user devices, which needs real PCIe semantics -- the same territory as
# the fd-backed-region patch noted against QEMU_IMAGE above.
#
# And it is not cosmetic at all for a GPU. A conventional endpoint gets a
# 32-bit prefetchable BAR: 16M measured on the emulated rocjitsu, against
# 256M 64-bit behind a port. 16M cannot be a VRAM aperture, so amdgpu's probe
# fails with -22, no KFD node appears, and HIP reports "no ROCm-capable
# device is detected" -- three layers from the cause.
#
# This is now the DEFAULT, so the line below only states intent. Turning it
# off makes gen-compose warn, because the combination has produced a wrong
# diagnosis before.
VM_VFIO_USER_ROOT_PORT=true

# A host directory shared into every guest over 9p, mounted in the guest with
#   mount -t 9p -o trans=virtio,version=9p2000.L hostfs /mnt/hostfs
#
# This is how the fleet gets the LMCache image in: `docker save` once on the
# host, `docker load` from the share in each guest. The alternative is copying
# a ~2.8 GB tar per VM over SLIRP -- 22 GB at VM_COUNT=8, 112 GB at 40 -- for
# a file that is identical everywhere.
#
# Bind-mounted read-only into each qemu container at the same path, because
# run-vm passes it straight to -virtfs.
VM_FILESYSTEM=/var/lib/qemu-tool/share

# ---------------------------------------------------------------------------
# Metrics
# ---------------------------------------------------------------------------

# An existing run-vm key (config.py:84), not a fleet-specific one. The guests
# are behind QEMU SLIRP inside their qemu containers and have no Docker network
# address of their own -- Prometheus scrapes the CONTAINER, qemu-<n>:9100, and
# this rule forwards that to the guest. Each container has its own netns, so
# one rule serves the whole fleet with no per-VM port arithmetic and nothing
# published to the host.
#
# The exporter is NOT in the published ernic-rocjitsu qcow2, whatever
# vm-basic.yml does for images this repo bakes itself -- checked on a running
# guest: no binary, no unit, package not installed, nothing on :9100. So this
# forward pointed at nothing and every fleet-node target scraped down. The
# lmcache_guest role now installs prometheus-node-exporter
# (lmcache_guest_node_exporter_enable).
#
# This is a list[str] field -- see the note at the top. Adding a second rule
# here gives BOTH rules to EVERY VM.
#
# Two rules, both of which every guest gets: node-exporter on 9100, and the
# LMCache MP server's HTTP API on LMCACHE_SERVER_HTTP_PORT, which is where
# its /metrics lives. Drop the second if LMCACHE_ENABLE is false -- it costs
# nothing, but a forward to a port nothing listens on is one more thing to
# rule out when a scrape is down.
#
# Only this one port needs forwarding. The server's ZMQ and P2P ports are
# dialled by the other GUESTS, over the ernic L2 segment they share, so they
# never traverse SLIRP.
VM_EXTRA_HOSTFWD=tcp::9100-:9100,tcp::9500-:9500

# The other scrape source, and the interesting one: each rocm-ernic writes a
# stats dump every ~1s under -S (pvrdma_stats.c:85-186) -- per-QP bytes,
# doorbells, CQEs, WQEs by opcode, MMIO and interrupt counts. A sidecar parses
# those into Prometheus text on this port. Costs the guests nothing, which is
# why the in-guest GPU exporters are deliberately NOT scraped here:
# amd-metrics-exporter (:5000) and hsa-snoop-prometheus (:9488) poll the
# emulated device, and rocjitsu serves single-threaded, so every scrape is
# taken out of the same thread as whatever workload is running
# (rocjitsu_gpu_test/defaults/main.yml:14-24).
#
# 9840 is rocm-ernic's own exporter port (prometheus/ernic-exporter). Matching
# it is what lets grafana/ernic-dashboard.json work here unmodified.
ERNIC_STATS_PORT=9840

# File-descriptor limit for every ernic service. Docker's default soft limit
# is 1024, and the mesh manager leaks an fd for every node it evicts -- the
# evicted worker reconnects on a new socket and the old one is never closed.
# At fleet scale that reaches 1024 inside a normal run, after which the
# manager spins in an accept()/EMFILE loop and its guest dies. Raising this
# does not fix the leak, it buys the run enough headroom to finish.
# Give the guest working Ethernet by attaching each ernic to a TAP that a
# short-lived privileged sidecar bridges onto a shared L2 network. The TCP
# mesh carries RDMA payload only, so without this ARP goes unanswered and
# inter-node ib_send_bw cannot do its out-of-band exchange at all. Costs one
# extra container per VM at start, which exits immediately.
ERNIC_TAP=true

ERNIC_NOFILE=65536

# Where Prometheus keeps its TSDB, bind-mounted into the container, and where
# Grafana keeps its sqlite. Both on the host filesystem so a fleet run's
# record outlives the containers.
#
# ABSOLUTE, and that matters. A relative path resolves against the STACK
# directory, and the stack directory is wherever qemu-tool found it -- for a
# pipx or .deb install that is inside site-packages or /usr/share. A relative
# default put a live TSDB under
# ~/.local/share/pipx/venvs/qemu-tool/.../share/compose/<stack>/prom-data,
# root-owned, where a reinstall deletes it and Prometheus crash-looped on
# "mkdir data/: permission denied" anyway.
#
# Bind mounts rather than named volumes on purpose: the TSDB is the record of
# a fleet run, and a named volume buries it under /var/lib/docker/volumes as
# root, invisible to whoever ran the fleet and silently reused by the next run
# of a different size. Point these at a per-run directory to keep runs apart
# and to archive one next to its dashboards.
#
# Create both before `up` with the right owner. Docker creates a missing
# bind-mount source as root, and each image runs unprivileged -- prometheus as
# nobody (65534), grafana as 472:
#
#   sudo mkdir -p /var/lib/qemu-tool/prom-data /var/lib/qemu-tool/grafana-data
#   sudo chown 65534:65534 /var/lib/qemu-tool/prom-data
#   sudo chown 472:472     /var/lib/qemu-tool/grafana-data
PROM_DATA_DIR=/var/lib/qemu-tool/prom-data
GRAFANA_DATA_DIR=/var/lib/qemu-tool/grafana-data

PROM_PORT=9090

# Host interface the published ports bind to -- Prometheus, Grafana and the
# LMCache coordinator. 0.0.0.0 makes Grafana reachable from other machines,
# which is the point of running the fleet on a lab box and looking at it from
# a workstation. Grafana has anonymous admin enabled, so this is the only
# thing deciding who can reach it: set it to 127.0.0.1 on a shared host.
PUBLISH_BIND_ADDR=0.0.0.0
PROM_SCRAPE_INTERVAL=15s
PROM_RETENTION=7d

# Grafana, in the `metrics` profile beside Prometheus. Its datasource and its
# dashboard are provisioned from files under the stack directory rather than
# clicked in, so a dashboard survives `down`. Anonymous admin access is on --
# this is a lab stack behind a host port, so do not publish GRAFANA_PORT
# anywhere shared.
# ---------------------------------------------------------------------------
# Logs
# ---------------------------------------------------------------------------
#
# Loki plus an Alloy on the host, both in the `metrics` profile. The guests
# get their own Alloy from the lmcache_guest role, because a VM's journal is
# behind QEMU and not reachable on the host's Docker socket.
#
# Create the data directory before `up`; Docker creates a missing bind-mount
# source as root and Loki runs as uid 10001:
#   sudo mkdir -p /var/lib/qemu-tool/loki-data
#   sudo chown 10001:10001 /var/lib/qemu-tool/loki-data
LOGS_ENABLE=true
LOKI_IMAGE=docker.io/grafana/loki:3.3.2
LOKI_PORT=3100
LOKI_DATA_DIR=/var/lib/qemu-tool/loki-data
ALLOY_IMAGE=docker.io/grafana/alloy:v1.5.1

GRAFANA_ENABLE=true
GRAFANA_PORT=3000
GRAFANA_ADMIN_PASSWORD=admin

# ---------------------------------------------------------------------------
# LMCache
# ---------------------------------------------------------------------------
#
# MP mode. An MP coordinator container beside the vfio-user device servers,
# and one `lmcache server` container INSIDE each guest registering with it.
#
# MP mode, not the legacy in-process mode, and the distinction decides
# everything else here. `lmcache server` is a standalone process that needs no
# vLLM, is configured by CLI flags rather than a YAML engine config, and
# registers with `lmcache coordinator`. The in-process mode's controller
# (`lmcache_controller`) listens for LMCacheWorker registrations an MP server
# never sends, so pairing the two leaves every guest registered with nothing.
#
# The split across the VM boundary is forced, not stylistic: compose has no
# reach into a VM, so the per-VM servers cannot be services here. They are
# started by a systemd unit that `ansible/playbooks/roles/lmcache_guest`
# installs, gated on an ExecStartPre that probes amdgpu and the RDMA NIC and
# reassigns the ernic address -- because only module loading survives a guest
# reboot (AGENTS.md issue 12), and with P2P a guest that comes back without
# its ernic address advertises an endpoint no peer can reach.
#
# This key decides whether the coordinator service and the two LMCache scrape
# jobs are GENERATED. `--profile lmcache` decides whether the coordinator
# RUNS. Both exist because prometheus.yml has no notion of a profile: jobs
# emitted for a profile nobody selected are just permanently-down targets.
LMCACHE_ENABLE=true

# Built by qemu/docker/lmcache/Dockerfile -- LMCache v0.5.5 compiled for
# gfx1250 on ROCm 10.1. There is no published LMCache wheel for gfx1250, so
# this image does not exist until you build it:
#
#   docker build -t qemu-tool/lmcache-rocm:0.5.6-gfx1250 qemu/docker/lmcache
#
# Deliberately NOT carrying a batesste-ci-images build stamp: it is not part
# of that build, and _check_image_coherence excludes unstamped refs rather
# than failing on them (it warns, which is correct here).
#
# This value reaches the guests through fleet-inventory.yml as
# lmcache_guest_image, so it OVERRIDES the role default -- the role's default
# is the fallback for a guest configured outside this stack, not what a fleet
# gets. Change it here.
#
# -srq, and ONE TAG ACROSS THE WHOLE FLEET. Kept deliberately, and the reason
# has narrowed rather than gone away.
#
# `nixl`'s meta package probes variants in a fixed order -- nixl_cu13,
# nixl_cu12, nixl_rocm -- by PRESENCE, not by platform, so any image that
# pulled a prebuilt CUDA variant resolves `from nixl._api import ...` to
# nixl_cu13 even on a ROCm guest with no CUDA. The -srq image builds nixl with
# -Dwheel_variant=rocm and installs the meta package --no-deps, so only
# nixl_rocm exists and the probe falls through to it. That half is unchanged
# and is why the tag matters on a single guest, never mind a fleet.
#
# What HAS changed is the failure mode of mixing tags. Through v0.5.5 the
# transfer channel pickled descriptor lists, pickle records the defining
# module, and a peer raised ModuleNotFoundError: No module named 'nixl_cu13'
# inside its serve loop -- sending no reply, so the initiator blocked to its
# ZMQ deadline and logged only "Failed to add P2P adapter for peer". v0.5.6
# removed pickle from lmcache/v1/distributed entirely (CVE-2026-105192); the
# handshake is msgspec msgpack over agent.deserialize_descs() on raw bytes.
#
# So the specific unpickling failure is gone. The rule stays anyway: a mixed
# fleet has never been measured working, the variant probe that put the wrong
# module there in the first place is untouched, and one tag costs nothing.
# Do not relax this on the strength of the CVE fix alone -- measure it.
#
# The plain tag additionally lacks SRQ in rdma-core, which UCX needs for
# rc_verbs (ibv_create_srq: Operation not supported).
LMCACHE_IMAGE=qemu-tool/lmcache-rocm:0.5.6-gfx1250-srq

# The MP coordinator's HTTP port (`lmcache coordinator`). Published on the
# host, because this is the port an operator curls:
#
#   curl -s localhost:9300/instances
#
# is how you find out whether the fleet's servers actually registered, which
# a unit being active does not tell you. The guests reach it at its FLEET
# address, not through this publication -- QEMU's SLIRP NATs guest egress out
# through the qemu container's stack, and that container is on the fleet
# network.
LMCACHE_COORD_PORT=9300

# Seconds without a heartbeat before the coordinator evicts an instance, and
# the sweep interval. Upstream's defaults, restated because a fleet boot burst
# can outrun a 30 s timeout the same way it outruns the ernic mesh manager's
# untunable 20 s one -- and the symptom is the same shape, live nodes declared
# dead. Raise it if a large fleet loses members during start.
LMCACHE_INSTANCE_TIMEOUT=30
LMCACHE_HEALTH_CHECK_INTERVAL=10

# Must be identical here and on every guest's server. The coordinator resolves
# pin token_ids to keys with both, so a mismatch is not an error -- it just
# silently stops matching. blake3 is self-contained; the other algorithms need
# vLLM importable in the coordinator, which this image does not carry.
LMCACHE_CHUNK_SIZE=256
LMCACHE_HASH_ALGORITHM=blake3

# In-guest ports, forwarded by the VM_EXTRA_HOSTFWD rules above where they
# need to be reachable from outside the guest.
#
# The HTTP API port is where /metrics lives, and it is the one Prometheus
# scrapes. `lmcache server` also has a --prometheus-port, which is a decoy:
# it only binds when the HTTP server is disabled, and `lmcache server` always
# runs it. Scraping that port gets connection refused.
LMCACHE_SERVER_HTTP_PORT=9500
# The ZMQ request server. Recorded by the coordinator as mq_port and dialled
# by peers, so it is reachable over the ernic L2 segment and needs no hostfwd.
LMCACHE_SERVER_ZMQ_PORT=5555
# The P2P transfer-channel endpoint each guest advertises to its peers. Also
# ernic-side only.
LMCACHE_P2P_PORT=9400

# nixl or mooncake_te. nixl is not a preference: mooncake's wheel is a CUDA
# build and dies on a ROCm image with "libcudart.so.12: cannot open shared
# object file". nixl is also upstream's default, ships as the lmcache[nixl]
# extra, and its UCX backend does instantiate on this image -- despite
# upstream's own Dockerfile.rocm still claiming NIXL is unavailable on ROCm.
LMCACHE_P2P_TRANSFER_ENGINE=nixl

# L1 host memory per guest, in GB. Must fit inside VM_VMEM (8192 MiB here)
# with room for the guest itself. This is what P2P peers RDMA-read out of, so
# it is the fleet's shared cache tier.
LMCACHE_L1_SIZE_GB=2
LMCACHE_EVICTION_POLICY=LRU

# A third source, off until the two above are proven: QEMU's own QMP counters
# (balloon, blockstats, per-vcpu time), which need no guest cooperation at all.
#VM_QMP_SOCKET=

# ---------------------------------------------------------------------------
# Compose-only
# ---------------------------------------------------------------------------

# Path to the repo root, resolved relative to the compose stack directory.
QEMU_TOOL_SRC=../../..

# Run the containers as somebody OTHER than you.
#
# You do not need to set this. Every service in the generated stack carries
# `user: ${CONTAINER_USER:?...}`, and `qemu-tool compose` fills it in from
# your own uid:gid -- and CONTAINER_KVM_GID from the gid that owns /dev/kvm --
# whenever neither the environment nor any env layer has. Unset means "run the
# fleet as me", which is what you almost always want. Set it only to pin a
# DIFFERENT identity: a shared service account, or 0:0 to deliberately go back
# to root.
#
# It was opt-in until 2026-10-24 and that meant root in practice. The value
# cannot be committed -- it differs per host, and `gen-compose --check`
# compares the rendered stack byte for byte in CI -- so "put it in an overlay"
# was the only on-ramp and the committed stacks shipped as uid 0. Making the
# reference unconditional and resolving the value in the tool fixes both
# halves: the render stays machine-independent because it is a reference, and
# the default stops being root because something now answers it.
#
# A plain `docker compose up` against the committed stack has no caller to
# ask, so it fails with "required variable CONTAINER_USER is missing a value"
# and tells you what to set. That refusal is deliberate. The cheap
# alternative, `${CONTAINER_USER:-}`, interpolates to empty, `user: ":"` is
# not an error to Docker, and the fleet runs as root with one warning line as
# the only evidence -- measured on compose v5.3.1.
#
#   CONTAINER_USER=$(id -u):$(id -g) \
#   CONTAINER_KVM_GID=$(stat -c %g /dev/kvm) docker compose up -d
#
# Numeric <uid>:<gid> only, here and there. A user name does not resolve --
# the images carry no passwd entry for your uid -- and ${UID}:${GID} is worse
# than wrong: bash exports neither, compose substitutes empty for both, and
# you are back to root. gen-compose refuses all three rather than letting them
# reach run time.
#
# CONTAINER_KVM_GID is required whenever CONTAINER_USER is: a container given
# a uid holds no supplementary groups, and /dev/kvm is crw-rw---- root:kvm, so
# QEMU cannot use accel=kvm without it. You must also be in that group on the
# host. Compose refuses to start if it is missing rather than letting the
# fleet boot under TCG and run ~20x slower, which presents as "the guests are
# hanging" rather than as a missing group.
#
# Does NOT apply to three services, each for its own reason:
#   tapsetup-N   cannot. Docker sets no ambient capabilities, so a non-root
#                uid holds no effective NET_ADMIN and bridge creation fails
#                with RTNETLINK "Operation not permitted". The sidecar is
#                short-lived, holds NET_ADMIN and nothing else (cap_drop ALL
#                first, then that one back), and runs on a read-only rootfs.
#   dockerapi    speaks to the host Docker socket, which is root's. It is an
#                haproxy that answers GET on /containers and refuses POST --
#                see the alloy service, which used to hold that socket itself
#                and now reaches the daemon only through this.
#   *-stats-exporter  stay 65534. They create nothing on the host, so there
#                is no ownership to fix and nobody is the stronger position.
#
# Migrating a fleet that ran as root: `qemu-tool compose up` names the files
# that will bite and creates the data directories as you. The one it cannot
# fix for you is a <vm>-nvmeN.qcow2 left behind by a root run -- 0644
# root-owned, and QEMU opens a drive read-write, so the guest will not boot at
# all rather than merely owning the wrong file. Delete those; they are
# scratch.
#CONTAINER_USER=
#CONTAINER_KVM_GID=
