Skip to content
Merged
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
5 changes: 3 additions & 2 deletions docs/spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,8 @@ bench-2, in page order. (Q) marks the Quick list. bench-1 is the same but for Om
- **The work ran where it says** (review). A row counts only when the run shows it: the GPU drew the browser pages (a software renderer is an error) at the same effective 60 Hz on both boots, as MotionMark scales its work to the frame rate; clpeak ran on the physical GPU (from bench-2, the Mac's own GPU among the devices it measured, its best vector width of those that ran); Core ML placed the model on the Neural engine; MLX ran on the GPU, synchronised before timing (on Omarchy, `omarchy-mlx`'s packaged Honeykrisp driver on the Mac's own GPU, through its own interpreter with no user's module or Vulkan override); llama.cpp offloaded every layer; FFmpeg decoded each codec in hardware, timing the same frames on both: every frame the set pins for the clip (600 and 1797), on Omarchy through the V4L2 request VA driver on the Apple GPU's render node, each frame a VA surface, and the clip's first 30 frames, read back from VA-API before timing, those FFmpeg's own decoder makes; on both systems a decode that spends over half its wall time on the CPU fell back (bench-2). A row that fell back reads "fell back", with no value.
- **API differs.** A row whose two systems reach the hardware through different APIs (video decode, llama.cpp on the GPU, MLX, the Neural engine) is compared and marked "API differs", naming both, wherever it shows (owner, 2026-11-21). clpeak's OpenCL C 1.2 kernels run the same on Rusticl and Apple's OpenCL; it is marked only where a kernel uses a feature one of them lacks.
- **Omarchy only** is boot time alone (owner, 2026-11-22). glmark2, vkmark, vkpeak, the kernel compile and suspend and resume are in no set, and so leave the `bench` builtins and Compare.
- **What the Stack lacks.** MLX on Omarchy runs only when the boot carries `omarchy-mlx`; the Neural engine only with an ANE driver and a MobileNet v1 program for libane, which neither bench-1 nor bench-2 has. Otherwise the row reads "no build" or "no driver": listed as a gap, kept out of every mean.
- **What the Stack lacks.** MLX on Omarchy runs only when the boot carries `omarchy-mlx`; the Neural engine only with an ANE driver and a MobileNet v1 program for libane, which no set has: on 2026-11-27 Omarchy's ANE compiler (`mil-hwx-compiler` 0.1.0) compiled only convolutions inside the shapes it has proven against macOS, as small as a 64-to-64 1×1 at 8×8, and none of MobileNet v1's on M1 (H13) or M2 (H14), and `omarchy-ane` runs no job on the M3 family. Splitting the model into many small programs would time the splitting, not the Neural engine, so the row stays "no build" until Omarchy's compiler takes the model. Otherwise the row reads "no build" or "no driver": listed as a gap, kept out of every mean.
- **Packages the lab adds** (owner, 2026-11-27: "The lab should be able to install packages to make everything work", in any Mac added to the lab; from bench-3). A metric whose Omarchy side names `adds` (packages, by name, such as `omarchy-mlx` for MLX and `opencl-aurora` for clpeak) is measured on a Candidate boot of the Release's set with them added, never on the Mac's own system. The first Lab-owned Mac that needs the set resolves it: lab-agent has pacman download, against copies of the Mac's pacman database and keyring in a folder of its own, with the Mac's repositories and no other cache, every package file the packages need beyond what the Mac has installed (pacman checks each package's signature), and sends each file to the job in parts of exactly 64 MiB but the last; labd takes at most 64 files, 2 GiB a file and 6 GiB in all, joins them into the artifact store, checks each part's size and each file's sha256 (a blob of that sha256 already there is checked too), removes the parts however it ends, and keeps the Package set `release-<version>-adds-<12 hex digits of the sha256 of the packages' names>`, frozen: the Release's items and the added files. A file the Release's set holds at another version, or no file of a package asked for, makes no set. A resolve that fails (a package Omarchy does not ship yet) opens no attempt of the metrics, and labd waits 24 hours before a Lab-owned Mac tries again. The set is resolved against the resolving Mac's installed packages, as Release manifests name only the stack: a Mac that lacks a package the set leaves out fails its offline stage, saying so (a known limit). Every Mac after boots that set, a Volunteer's Mac only once a Lab-owned Mac has resolved it (call: a Volunteer's Mac never chooses what the lab keeps). A Performance run, which only labd makes (generic job submission refuses one), takes only the metrics its attempt was asked for, and runs on lab-agent 0.12.0 or later; it stages its set offline: pacman installs the set's files with the candidate's own options and no repository, so staging fails on a package they need that the set lacks, rather than fetching it. The values are kept under the Release with the packages (`7.3+omarchy-mlx`), apart from the Release's own: a metric is measured one way or the other, never both. In public they carry the packages and are in none of the Release's figures, means, trends or Qualification; a Configuration's page shows them apart, under "With packages the lab added", with the same Macs' macOS values and ratios. A Release's sets stay in the artifact store, the added ones too. `lab perf rerun` reruns the Release's own metrics. Compare and `lab run` run a metric that adds packages on their boot as it is: it reads "no build" there.
- **Geekbench** is in no set (review): its licence has to cover the lab's Macs, handing it to them, and publishing its scores. A set that adds it passes `--no-upload` on both systems and keeps its scores out of the CC0 data unless the licence allows them there.

### Measuring
Expand All @@ -1433,7 +1434,7 @@ bench-2, in page order. (Q) marks the Quick list. bench-1 is the same but for Om

### Performance run

- **What it is.** A job of the Mac (`spec.performance`) that measures one Release on one Mac with one Benchmark set: one Release per run (owner, 2026-11-22). Its Package set is the Release's frozen manifest, resolved by the manifest's digest (`release-<version>`, call). Every file must be in the artifact store, and the Release must support the Mac's board; otherwise staging is refused, with the reason. The run boots the set as a Candidate boot, so the Mac's own system is never changed, and measures only once the running kernel is the Release's. It records, by exact package name, the versions actually booted of the kernel, Mesa, m1n1, U-Boot, the firmware, the ANE driver and libane's compiler, MLX, llama.cpp, the AVD firmware, FFmpeg, libva and OpenCL (section 21's list); a column whose Macs differ in any of them says so (review).
- **What it is.** A job of the Mac (`spec.performance`) that measures one Release on one Mac with one Benchmark set: one Release per run (owner, 2026-11-22). Its Package set is the Release's frozen manifest, resolved by the manifest's digest (`release-<version>`, call). Every file must be in the artifact store, and the Release must support the Mac's board; otherwise staging is refused, with the reason. The run boots the set as a Candidate boot, staged offline (from 2026-11-27: no repository, so nothing outside the set is installed), so the Mac's own system is never changed, and measures only once the running kernel is the Release's. It records, by exact package name, the versions actually booted of the kernel, Mesa, m1n1, U-Boot, the firmware, the ANE driver and libane's compiler, MLX, llama.cpp, the AVD firmware, FFmpeg, libva and OpenCL (section 21's list); a column whose Macs differ in any of them says so (review).
- **When** (review). Scheduled lab work, as a first Reference run is: on Lab-owned Macs, and on a Volunteer's Mac whose Volunteer turned performance runs on at the Mac (`sudo lab-agent performance on`), inside the Mac's Availability window, with no Lease and no job, at Full access, on AC, not Paused, and not leaving. labd claims the Mac at once and keeps it until cleanup ends. labd works out what is missing per Mac, set, metric and Release whenever a Release is frozen, a Mac enrolls or turns performance runs on, a set or its files change, or a verdict is recorded, and queues it newest Release first: the Quick list while a Release has no verdict, and the rest of the Full list once it is qualified. A Release whose m1n1 or U-Boot differs from the Mac's is not run on a Mac with no Sighting, as for every Candidate boot.
- **Never repeated.** One value per Mac, set, metric and Release (owner, 2026-11-22); every attempt is kept, and an upload is taken once per attempt and metric. A benchmark that failed or was skipped for a passing reason is run once more, alone, at the Mac's next slot; after that it is "not run", with its reason. `lab perf rerun <mac> <release>` (a Maintainer, or the Mac's Lease holder) runs it again under the caller's Lease, taken for them when they hold none, as a Compare's; its values replace the last only when it succeeds, and the old ones stay in the Mac's history. Values and attempts belong to the Mac's enrollment: a Mac enrolled under a name used before starts with none.
- **Kept** in labd.db (`perf_runs`, `perf_results`), with each run's set, Release, booted versions, boot time and conditions (call: a migration, unlike section 21's file). Published values go to `reports.db` (below).
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var errAccessLevel = errors.New("refused")
// own session), and a Lab boot for a job that runs one.
func needsFull(c api.Command) bool {
switch c.Kind {
case api.CmdExec, api.CmdMesaStage, api.CmdCandidateStage, api.CmdBootMacOS:
case api.CmdExec, api.CmdMesaStage, api.CmdCandidateStage, api.CmdBootMacOS, api.CmdAddsResolve:
return true
case api.CmdRunTest:
var t api.TestSpec
Expand Down
251 changes: 251 additions & 0 deletions internal/agent/adds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
package agent

// Packages the lab adds (spec section 22, "Packages the lab adds"): on a
// Lab-owned Mac's known-good system, lab-agent has pacman download every
// package file some packages need beyond what the Mac has installed, against
// copies of its pacman database, and sends each file to labd in parts; labd
// freezes them with the Release's set. Every Mac after installs that set
// offline: staging gives pacman no repository to fetch from.

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
"time"

"github.com/omacom/omarchy-maclab/internal/api"
)

// addsSystem is a System that can resolve the packages the lab adds: the
// files, in a folder of their own the caller removes.
type addsSystem interface {
ResolveAdds(ctx context.Context, a api.AddsResolveArgs) (dir string, files []api.AddsFile, err error)
}

// pacmanDB, pacmanConf and pacmanGPG are the known-good system's pacman
// database, configuration and keyring.
var (
pacmanDB = "/var/lib/pacman"
pacmanConf = "/etc/pacman.conf"
pacmanGPG = "/etc/pacman.d/gnupg"
)

// ResolveAdds downloads, with pacman, every package file the packages need
// beyond what this Mac has installed, into a folder of its own, against
// copies of its pacman database and keyring, with its repositories and no
// other cache: the Mac's own database, keyring, cache and system stay as
// they are. pacman checks each package's signature as it downloads it.
func (l *Linux) ResolveAdds(ctx context.Context, a api.AddsResolveArgs) (string, []api.AddsFile, error) {
if err := checkAdds(a.Packages); err != nil {
return "", nil, err
}
tmp, err := os.MkdirTemp("/var/tmp", "lab-adds-")
if err != nil {
return "", nil, err
}
fail := func(err error) (string, []api.AddsFile, error) {
os.RemoveAll(tmp)
return "", nil, err
}
// pacman downloads as its own user (DownloadUser), who must reach the
// folders below.
if err := os.Chmod(tmp, 0o755); err != nil {
return fail(err)
}
db, cache := filepath.Join(tmp, "db"), filepath.Join(tmp, "files")
for _, d := range []string{filepath.Join(db, "sync"), cache} {
if err := os.MkdirAll(d, 0o755); err != nil {
return fail(err)
}
}
gpg, conf := filepath.Join(tmp, "gnupg"), filepath.Join(tmp, "pacman.conf")
for _, c := range [][2]string{{filepath.Join(pacmanDB, "local"), db}, {pacmanGPG, gpg}} {
if out, err := combinedGroup(exec.CommandContext(ctx, "cp", "-a", c[0], c[1])); err != nil {
return fail(fmt.Errorf("copying %s: %v: %s", c[0], err, lastLines(string(out), 3)))
}
}
if err := writeResolveConf(pacmanConf, conf); err != nil {
return fail(err)
}
pacman := func(args ...string) error {
ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)
defer cancel()
base := []string{"--config", conf, "--dbpath", db, "--cachedir", cache, "--gpgdir", gpg, "--logfile", "/dev/null", "--noconfirm"}
out, err := combinedGroup(exec.CommandContext(ctx, "pacman", append(base, args...)...))
if err != nil {
return fmt.Errorf("pacman %s: %v: %s", strings.Join(args, " "), err, lastLines(string(out), 5))
}
return nil
}
if err := pacman("-Sy"); err != nil {
return fail(err)
}
if err := pacman(append([]string{"-Sw"}, a.Packages...)...); err != nil {
return fail(err)
}
files, err := addsFiles(cache)
if err != nil {
return fail(err)
}
return cache, files, nil
}

// writeResolveConf writes to the pacman configuration a resolve runs with:
// the Mac's own, its repositories included, without the options that name
// where its database, cache, keyring, log and hooks are.
func writeResolveConf(from, to string) error {
b, err := os.ReadFile(from)
if err != nil {
return err
}
var keep []string
for _, line := range strings.Split(string(b), "\n") {
k, _, _ := strings.Cut(strings.TrimSpace(line), "=")
switch strings.TrimSpace(k) {
case "CacheDir", "DBPath", "GPGDir", "LogFile", "HookDir", "RootDir":
continue
}
keep = append(keep, line)
}
return os.WriteFile(to, []byte(strings.Join(keep, "\n")), 0o644)
}

// checkAdds is why the package names will not do.
func checkAdds(pkgs []string) error {
if len(pkgs) == 0 {
return errors.New("no package to add")
}
for _, p := range pkgs {
if !reCandidatePkg.MatchString(p) || strings.HasPrefix(p, "-") {
return fmt.Errorf("bad package %q", p)
}
}
return nil
}

// addsFiles are the package files in dir, by name, with their sha256s.
func addsFiles(dir string) ([]api.AddsFile, error) {
ents, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
var out []api.AddsFile
for _, e := range ents {
name, version, ok := pkgFile(e.Name())
if !ok || !e.Type().IsRegular() {
continue
}
p := filepath.Join(dir, e.Name())
st, err := os.Stat(p)
if err != nil {
return nil, err
}
sum, err := fileSHA256(p)
if err != nil {
return nil, err
}
out = append(out, api.AddsFile{Name: name, Version: version, File: e.Name(), SHA256: sum, Size: st.Size(),
Parts: int((st.Size() + api.AddsPart - 1) / api.AddsPart)})
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
if len(out) == 0 {
return nil, errors.New("pacman downloaded no package: the packages are installed already, with all they need")
}
return out, nil
}

// resolveAdds is CmdAddsResolve: the files, each sent to the job as
// adds/<file>.<n> in parts of at most api.AddsPart bytes.
func (a *Agent) resolveAdds(ctx context.Context, c api.Command) (any, error) {
as, ok := a.sys.(addsSystem)
if !ok {
return nil, errors.New("agent system cannot add packages")
}
var args api.AddsResolveArgs
if err := json.Unmarshal(c.Args, &args); err != nil {
return nil, err
}
dir, files, err := as.ResolveAdds(ctx, args)
if err != nil {
return nil, err
}
defer os.RemoveAll(filepath.Dir(dir))
for _, f := range files {
if err := a.uploadParts(ctx, c.JobID, filepath.Join(dir, f.File), f); err != nil {
return nil, fmt.Errorf("sending %s to labd: %w", f.File, err)
}
}
return api.AddsResolved{Files: files}, nil
}

// uploadParts sends the file to the job in f.Parts parts.
func (a *Agent) uploadParts(ctx context.Context, job, path string, f api.AddsFile) error {
src, err := os.Open(path)
if err != nil {
return err
}
defer src.Close()
for n := 0; n < f.Parts; n++ {
part := fmt.Sprintf("%s.%d", path, n)
if err := copyPart(src, part); err != nil {
return err
}
err := a.upload(ctx, job, fmt.Sprintf("adds/%s.%d", f.File, n), part)
os.Remove(part)
if err != nil {
return err
}
}
return nil
}

func copyPart(src io.Reader, part string) error {
dst, err := os.OpenFile(part, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600)
if err != nil {
return err
}
_, err = io.CopyN(dst, src, api.AddsPart)
if errors.Is(err, io.EOF) {
err = nil
}
if cerr := dst.Close(); err == nil {
err = cerr
}
return err
}

// offlineConf is the pacman configuration an offline stage installs with,
// inside the candidate: the candidate's own [options] and no repository, so
// pacman installs the set's files and fetches nothing besides.
const offlineConf = "etc/pacman-lab-offline.conf"

// writeOfflineConf writes offlineConf into the candidate from its
// pacman.conf's options.
func writeOfflineConf(cand string) error {
b, err := os.ReadFile(filepath.Join(cand, "etc/pacman.conf"))
if err != nil {
return err
}
var keep []string
in := false
for _, line := range strings.Split(string(b), "\n") {
s := strings.TrimSpace(line)
if strings.HasPrefix(s, "[") {
in = s == "[options]"
}
if in && !strings.HasPrefix(s, "Include") {
keep = append(keep, line)
}
}
if len(keep) == 0 {
keep = []string{"[options]"}
}
return os.WriteFile(filepath.Join(cand, offlineConf), []byte(strings.Join(keep, "\n")+"\n"), 0o644)
}
Loading
Loading