From e7ace4651a1ae502b757ac3628b6069a544db19e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 1 Oct 2026 20:48:23 -0300 Subject: [PATCH] boot: cmp.Or where orElse was, and the baseline written where it starts orElse was cmp.Or with its arguments the other way round, and the package already used cmp.Or. cmdlineVariants held one row since the hash-table row was measured and dropped. Co-Authored-By: Claude Opus 5.5 (1M context) --- boot/firmware_test.go | 16 ++++------------ boot/fwstages_test.go | 2 +- boot/initcalls_test.go | 14 +++++--------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/boot/firmware_test.go b/boot/firmware_test.go index 6e43458..9a95b5d 100644 --- a/boot/firmware_test.go +++ b/boot/firmware_test.go @@ -3,6 +3,7 @@ package boot_test import ( + "cmp" "encoding/json" "fmt" "net" @@ -115,13 +116,13 @@ func (p *probe) start(t *testing.T, variant string, gen bool, incoming, kernel, args := []string{ "-L", p.firmware, "-machine", "q35,sata=off,smbus=off", - "-accel", "kvm", "-cpu", orElse("host", cpu), + "-accel", "kvm", "-cpu", cmp.Or(cpu, "host"), "-m", "2048", "-smp", "2", "-nodefaults", "-display", "none", "-serial", "stdio", "-monitor", "none", "-qmp", "unix:" + qmp + ",server=on,wait=off", "-bios", p.bios[variant], - "-kernel", orElse(p.kernel, kernel), - "-initrd", orElse(p.initrd, initrd), + "-kernel", cmp.Or(kernel, p.kernel), + "-initrd", cmp.Or(initrd, p.initrd), "-append", "console=ttyS0 quiet loglevel=3 pci=lastbus=0 no_timer_check " + "tsc=reliable rcupdate.rcu_expedited=1 TERM=dumb rdinit=/init", } @@ -397,12 +398,3 @@ func pct(v []float64, p int) float64 { x, _ := boot.Percentile(v, float64(p)/100) return x } - -// orElse is the override or the default, and exists so that a probe varying one argument -// of the machine line does not need a second copy of the whole line. -func orElse(dflt, override string) string { - if override != "" { - return override - } - return dflt -} diff --git a/boot/fwstages_test.go b/boot/fwstages_test.go index 63cc208..e69c22d 100644 --- a/boot/fwstages_test.go +++ b/boot/fwstages_test.go @@ -45,7 +45,7 @@ func TestFirmwareStages(t *testing.T) { reps := envInt(t, "REPS", 10) initrd := probeInitrd(t) - flags := strings.Fields(orElse("--cpus 1 --memory 512 --max-cpus 16 --max-memory 8192 --hotplug-disks 1", os.Getenv("FLAGS"))) + flags := strings.Fields(cmp.Or(os.Getenv("FLAGS"), "--cpus 1 --memory 512 --max-cpus 16 --max-memory 8192 --hotplug-disks 1")) flags = append([]string{"--disk", "-", "--initrd", initrd, "--console", "file:/dev/stdout"}, flags...) cli := filepath.Join(out, "bin", "spin-machine") type variant struct { diff --git a/boot/initcalls_test.go b/boot/initcalls_test.go index 81b1b11..ffbdf66 100644 --- a/boot/initcalls_test.go +++ b/boot/initcalls_test.go @@ -3,12 +3,12 @@ package boot_test import ( + "cmp" "fmt" "os" "os/exec" "path/filepath" "regexp" - "slices" "sort" "strconv" "strings" @@ -111,7 +111,7 @@ WantedBy=multi-user.target checkName = name } dump = strings.Replace(dump, "FORMATCHECK ", check+" ", 1) - cvs := slices.Clone(cmdlineVariants) + cvs := []cmdlineVariant{{label: "baseline"}} if k := kernelB(t); k != "" { cvs = append(cvs, cmdlineVariant{label: "kernel B", kernel: k}) } @@ -128,8 +128,8 @@ WantedBy=multi-user.target } base := variant{ - cpus: orElse("2", os.Getenv("CPUS")), - memory: orElse("2048", os.Getenv("MEMORY_MIB")), + cpus: cmp.Or(os.Getenv("CPUS"), "2"), + memory: cmp.Or(os.Getenv("MEMORY_MIB"), "2048"), flags: strings.Fields(os.Getenv("FLAGS")), files: map[string]string{ "/etc/systemd/system/spin-dmesg.service": dump, @@ -282,7 +282,7 @@ func clip(s string) string { } // The command lines to compare: the baseline, which the per-initcall table below is taken -// from, and a kernel B or C when one is named. +// from, and a kernel B or C, or a command line B, when one is named. // // Smaller TCP and UDP hash tables (thash_entries=2048 uhash_entries=2048), for inet_init's // 8 ms on a machine that will never hold 32768 connections, moved nothing: 85.8 ms against @@ -290,10 +290,6 @@ func clip(s string) string { // 30 boots, 2026-09-30). type cmdlineVariant struct{ label, extra, kernel string } -var cmdlineVariants = []cmdlineVariant{ - {label: "baseline"}, -} - // initcallsOfInterest are printed side by side for every variant, because a variant that // moved the total is only interesting once it is clear which initcall moved. var initcallsOfInterest = []string{