Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ on:
- bootchart
- ledger
- exits
- io
- build
- check:firmware
- check:firmware-stages
- check:waits
Expand Down
2 changes: 1 addition & 1 deletion cmd/spin-machine-dev/lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func treeFlags(fs *pflag.FlagSet, s *lab.TreeSpec) {
fs.StringVar(&s.Append, "append", "", "added to the kernel command line of every boot")
fs.StringArrayVar(&s.Boot, "boot", nil, "a spin-machine boot flag for every boot of the tree, e.g. --boot --cpu=Skylake-Server-v4")
fs.StringVar(&s.CPU, "cpu", "", "baseline: the newest named CPU model the host making the tree can run, chosen there (machine.QEMU.CPUModels, internal/lab)")
fs.StringArrayVar(&s.Edits, "edit", nil, "an edit of every boot's overlay, by name: lane (the first login's lane as this checkout builds it), pressure (the pressure probe's guest sender as this checkout builds it into the image), floor (no systemd before sshd: a bound, with --append init=/usr/local/sbin/spin-floor), nolinger (spin not lingering, as this checkout builds the image), forwarder-early (login=spin's forwarder, spin's supervisor, without systemd's default dependencies), carry-masks, carry-generators and carry-coldplug (optimize-systemd.sh's boot-time changes and the coldplug filter taken back, after lane), carry-journal, carry-docker, carry-lane-logind and carry-keygen (four of the image's deviations, each as Ubuntu ships it, after lane; docs/image.md, \"Measured in this review\"), bootchart (systemd-bootchart as PID 1, which the bootchart probe draws), ledger (sshd at DEBUG1 and the ledger probe's scripts, with --append '"+lab.LedgerAppend+"': the scheduler traced from the kernel's start, which the ledger probe accounts for)")
fs.StringArrayVar(&s.Edits, "edit", nil, "an edit of every boot's overlay, by name: lane (the first login's lane as this checkout builds it), pressure (the pressure probe's guest sender as this checkout builds it into the image), floor (no systemd before sshd: a bound, with --append init=/usr/local/sbin/spin-floor), nolinger (spin not lingering, as this checkout builds the image), forwarder-early (login=spin's forwarder, spin's supervisor, without systemd's default dependencies), carry-masks, carry-generators and carry-coldplug (optimize-systemd.sh's boot-time changes and the coldplug filter taken back, after lane), carry-journal, carry-docker, carry-lane-logind and carry-keygen (four of the image's deviations, each as Ubuntu ships it, after lane; docs/image.md, \"Measured in this review\"), bootchart (systemd-bootchart as PID 1, which the bootchart probe draws), ledger (sshd at DEBUG1 and the ledger probe's scripts, with --append '"+lab.LedgerAppend+"': the scheduler traced from the kernel's start, which the ledger probe accounts for), fio (fio, built from the release versions.yaml pins, which the io probe runs)")
fs.StringVar(&s.Systemd, "systemd", "", "an image/systemd/experiments patch: systemd built with it here, in every overlay")
fs.BoolVar(&s.OpenSSH, "openssh", false, "OpenSSH as this checkout builds it (image/openssh), built here, in every overlay")
fs.StringArrayVar(&s.Options, "opt", nil, "a probe option NAME=VALUE for this tree's boots in place of the run's, e.g. --opt memory=2048 --opt plugged=0: two shapes as two trees of one run. Not login, nor one that changes the probe's rows")
Expand Down
17 changes: 17 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ laid out as one (`--from _output`). It replaces what its flags ask for:
- `--edit bootchart`: systemd-bootchart as PID 1, spin-stack's fork at the commit versions.yaml
pins, compiled here in a container, which samples the boot and execs systemd. The `bootchart` probe draws only a tree that carries
it (measuring.md, "Boot charts").
- `--edit fio`: fio, built here from the release versions.yaml pins, at /usr/local/bin/fio,
which the `io` probe runs.
- `--edit ledger`: sshd at LogLevel DEBUG1 and the `ledger` probe's two scripts. Its tree also
boots a kernel that can be traced and the scheduler's tracepoints from the kernel's start,
`--kernel traceable:TAG --append '<lab.LedgerAppend>'` (measuring.md, "The ledger").
Expand Down Expand Up @@ -414,6 +416,21 @@ burst's counts, with every restore's `running`.
each number in `crowds` (default `0 8 16 32`). The running workspaces are idle, or keep their vCPUs
busy with `load=cpu`, and settle for `settle` seconds (default 10) before the measured boot.

`io` is what a running workspace's disk I/O costs the host (#563). Each row is a fio job in
`jobs` (default all six: 4 KiB random read and write at 1 and at 32 in flight, 1 MiB sequential
read and write at 8), run for `runtime` seconds (default 10) with no ramp. The guest boots and is
logged into, then gets a raw disk of `size` MiB (default 1024) attached as spin attaches one,
and fio runs against its device with O_DIRECT and io_uring. It records IOPS, MiB/s, the
completion latency's p50 and p99, and the CPU each GiB moved took: QEMU's, every thread
(`/proc/PID/stat`), and the guest's busy time. The disk is on the host's tmpfs on every host, so
two hosts differ only in the path through the hypervisors, not in their scratch devices. The tree
needs `--edit fio`.

`build` is what a build a workspace runs costs the host (#563): `go build cmd/go` with an empty
cache and its `sync`, inside the guest, on an ext4 disk attached after the boot that holds the
host's Go toolchain, on the host's tmpfs as `io`'s is. It records the wall time on the guest's
clock, QEMU's CPU time and the guest's busy time over it.

`transport` says how much of each goal number QMP and vsock are. It boots and restores as
`restore-first` does, with QEMU traced (QMP and the run state, in host time). From the trace it
reads which commands each path waits on: `cont` for a cold boot, and `migrate-incoming` and what
Expand Down
6 changes: 5 additions & 1 deletion internal/lab/density.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (m *Measurement) bootLoggedIn(name string) (*Machine, uint32, time.Duration
return nil, 0, 0, err
}
cid := NewCID()
qmp := filepath.Join(m.Socks, name+".qmp")
qmp := m.qmpPath(name)
args := append([]string{"--vsock-cid", fmt.Sprint(cid), "--console", "file:" + m.Dir + "/" + name + ".console",
"--append", m.Tree.Cmdline(m.Key.Init())}, m.qmpToPlug(qmp)...)
t0 := time.Now()
Expand All @@ -161,3 +161,7 @@ func (m *Measurement) bootLoggedIn(name string) (*Machine, uint32, time.Duration
}
return mc, cid, login, plugged()
}

// qmpPath is the monitor bootLoggedIn opens for the machine it boots as name, when the options size
// the guest.
func (m *Measurement) qmpPath(name string) string { return filepath.Join(m.Socks, name+".qmp") }
2 changes: 1 addition & 1 deletion internal/lab/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ func TestAStatesDataIsReadAndASocketWaitedFor(t *testing.T) {
}

func TestTheProbesAreTheGoalsAndTheKernels(t *testing.T) {
if got := ProbeNames(); !slices.Equal(got, []string{"bootchart", "density", "exits", "initcalls", "ledger", "prestart", "restore-first", "restore-together", "run-delay", "ssh-first", "transport", "usage"}) {
if got := ProbeNames(); !slices.Equal(got, []string{"bootchart", "build", "density", "exits", "initcalls", "io", "ledger", "prestart", "restore-first", "restore-together", "run-delay", "ssh-first", "transport", "usage"}) {
t.Errorf("probes %v", got)
}
for _, name := range ProbeNames() {
Expand Down
30 changes: 30 additions & 0 deletions internal/lab/fio.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# internal/lab's fio edit: fio compiled from the release tarball versions.yaml pins, for a lab
# overlay and never for the base image. The context is the directory holding the tarball, which
# fioEdit fetched and checked; it is checked again here, on the bytes that are compiled.
#
# On the Ubuntu the guest runs, so the binary links the guest's own libc and nothing else: the
# io probe's jobs use io_uring, which fio reaches through its own system calls, not a library.
ARG UBUNTU_IMAGE
FROM ${UBUNTU_IMAGE} AS build

ARG FIO_VERSION
ARG FIO_SHA256
ENV DEBIAN_FRONTEND=noninteractive

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get install -y --no-install-recommends gcc libc6-dev make

COPY fio-${FIO_VERSION}.tar.gz /build/source.tar.gz
WORKDIR /build
RUN echo "${FIO_SHA256} source.tar.gz" | sha256sum -c - && \
mkdir src && tar -xzf source.tar.gz -C src --strip-components=1 && \
cd src && ./configure --disable-native && \
make -j"$(nproc)" && \
./fio --enghelp | grep -qx '[[:space:]]*io_uring' && \
test "$(./fio --version)" = "fio-${FIO_VERSION}" && \
install -D -m 0755 fio /out/fio

FROM scratch AS bin
COPY --from=build /out/ /
127 changes: 127 additions & 0 deletions internal/lab/gobuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: Apache-2.0

package lab

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

xssh "golang.org/x/crypto/ssh"
)

// goBuild is what nesting costs a build a workspace runs (#563): the Go toolchain building cmd/go
// from its own source with an empty build cache, on a workspace disk attached after the boot, as
// spin hands a workspace its filesystem. It is compile-bound with the reads and writes a build
// makes, and needs nothing the image lacks but the toolchain, which the disk carries.
//
// The toolchain is the host's own (`go env GOROOT`), which go.mod's toolchain line pins and the
// checksum database verified when it was downloaded, so the nested run and the metal run of one
// commit build with the same compiler. The disk is a raw ext4 image on the host's tmpfs, for the
// reason the io probe's is.
type goBuild struct{}

func (goBuild) Name() string { return "build" }
func (goBuild) About() string {
return "`go build cmd/go` inside the guest with an empty cache, on an ext4 disk on the host's tmpfs attached after the boot, `sync` included"
}

func (goBuild) Options() []Option { return shape }

func (goBuild) Rows(Options) []string { return []string{"cmd/go"} }
func (goBuild) Phases() int { return 1 }

func (goBuild) Needs(o Options) []Need {
return append(append(bootNeeds, Need{"boot", "vsock-cid"}, Need{"boot", "console"}, Need{"boot", "append"},
Need{"boot", "qmp"}, Need{"attach", "disk-serial"}), plugNeeds(o)...)
}

func (goBuild) Metrics() []Metric {
return []Metric{
{"wall", "ms", "the build and its sync, on the guest's clock"},
{"host_cpu", "ms", "QEMU's CPU time over the build, every thread"},
{"guest_cpu", "ms", "the guest's busy time over the build, all vCPUs"},
}
}

// goDisk makes the workspace disk a build starts from at path: a raw ext4 image holding the
// host's Go toolchain at /go. It returns the toolchain's version.
// mutate-lane: TestEveryProbeMeasuresATree
func goDisk(path string) (string, error) {
out, err := exec.Command("go", "env", "GOROOT", "GOVERSION").Output()
f := strings.Fields(string(out))
if err != nil || len(f) != 2 {
return "", fmt.Errorf("asking go for its GOROOT and version: %v %q", err, out)
}
tree := path + ".tree"
if err := os.Mkdir(tree, 0o755); err != nil {
return "", fmt.Errorf("making %s: %w", tree, err)
}
if err := run("cp", "-r", f[0], filepath.Join(tree, "go")); err != nil {
return "", err
}
if err := run("mkfs.ext4", "-q", "-F", "-E", "root_owner=0:0", "-d", tree, path, "4G"); err != nil {
return "", err
}
// The module cache's toolchain is read-only, and so is its copy.
return f[1], run("sh", "-c", `chmod -R u+w "$1" && rm -rf "$1"`, "-", tree)
}

// mutate-lane: TestEveryProbeMeasuresATree
func (goBuild) Measure(_ context.Context, m *Measurement) error {
dir, remove, err := tmpfsDir()
if err != nil {
return err
}
defer remove()
disk := filepath.Join(dir, "workspace.raw")
version, err := goDisk(disk)
if err != nil {
return err
}
mc, cid, _, err := m.bootLoggedIn("build.qcow2")
if mc != nil {
defer mc.Stop()
}
if err != nil {
return err
}
dev, err := m.attachRaw(cid, "build.qcow2", disk, "ws")
if err != nil {
return err
}
env := "export GOROOT=/mnt/ws/go PATH=/mnt/ws/go/bin:$PATH GOCACHE=/mnt/ws/cache GOTMPDIR=/mnt/ws/tmp GOPATH=/mnt/ws/gopath GOTOOLCHAIN=local CGO_ENABLED=0 GOFLAGS="
if _, _, err := m.Key.Run(cid, xssh.KeyExchangeMLKEM768X25519, "mkdir -p /mnt/ws && mount "+dev+" /mnt/ws && mkdir -p /mnt/ws/tmp && "+env+" && test \"$(go env GOVERSION)\" = "+version); err != nil {
return Miss("mounting the workspace disk and finding %s on it: %v", version, err)
}
script := env + "; head -1 /proc/stat; s=$(date +%s%N); go build -o /mnt/ws/out cmd/go >&2 && sync && e=$(date +%s%N) && echo $(( (e - s) / 1000 )); head -1 /proc/stat"
host0, err := qemuCPU(mc.PID())
if err != nil {
return err
}
_, out, err := m.Key.Run(cid, xssh.KeyExchangeMLKEM768X25519, script)
if err != nil {
return Miss("go build cmd/go: %v", err)
}
host1, err := qemuCPU(mc.PID())
if err != nil {
return err
}
guest, between, err := guestBusyAround(out)
if err != nil {
return Miss("go build cmd/go: %v", err)
}
us, err := strconv.ParseInt(strings.TrimSpace(between), 10, 64)
if err != nil {
return Miss("go build cmd/go said no time: %q", between)
}
m.Record("wall", float64(us)/1000)
m.Record("host_cpu", ms(host1-host0))
m.Record("guest_cpu", ms(guest))
m.Logf("go build cmd/go (%s): %d ms, host CPU %.0f ms, guest CPU %.0f ms", version, us/1000, ms(host1-host0), ms(guest))
return nil
}
Loading
Loading