Files
Reims-Go/internal/host/optimizations_test.go
T
Nwflower d42a4f85f0 feat(perf): default to NVMe, guard P-core pinning, add Win11 WHPX nested-virt patch
- Default newly created VMs to NVMe disk controller via reims-ctl set (supported by macOS Recovery, installer, and installed guests)
- Guard P-core affinity pinning with CanSafelyPinPCores (require P-core logical CPUs >= vmCPUs+1) to prevent XNU spinlock stalls on non-HT hybrid CPUs such as Intel Core Ultra 9 285H (6P/6T + 8E), and include logical thread counts in CPU pinning logs
- Add patches/qemu-whpx-nested-virt-nonfatal.patch (registered in patches/README.md & docs/portable-runtime-spec.md) to make WHvSetPartitionProperty(NestedVirtualization) hr=0x80370302 non-fatal so Win11 retains kernel-irqchip=on, and detect the patch in host optimizations and WHPX compat pre-apply
2026-11-28 08:22:01 -07:00

116 lines
4.2 KiB
Go

package host
import "testing"
func findOpt(t *testing.T, opts []Optimization, id string) Optimization {
t.Helper()
for _, o := range opts {
if o.ID == id {
return o
}
}
t.Fatalf("optimization %q not found", id)
return Optimization{}
}
func TestEvaluateOptimizationsWin10AndWin11(t *testing.T) {
// Win10 hybrid CPU without startup-ipis patch.
win10 := Report{
WHPX: WHPXReady,
HasHybridCores: true,
PCoreCount: 8,
ECoreCount: 4,
NeedsColdRebootWorkaround: true,
WHPXCaps: WHPXCapabilities{
APICEmulation: true,
KernelIrqchipAvailable: true,
},
RecommendedGPU: &GPUInfo{Name: "NVIDIA GeForce RTX 4070 Ti", Kind: GPUDiscrete, VulkanICD: "nv-vk64.json"},
}
opts := EvaluateOptimizations(win10, []string{"qemu-whpx-win10-compat.patch"})
if o := findOpt(t, opts, "pcore_pin"); o.Status != "recommended" || !o.Supported {
t.Fatalf("pcore_pin = %+v", o)
}
if o := findOpt(t, opts, "kernel_irqchip"); o.Status != "unavailable" || o.Detail != "win10-needs-patch" {
t.Fatalf("kernel_irqchip without patch = %+v", o)
}
if o := findOpt(t, opts, "cold_reboot"); o.Status != "auto" {
t.Fatalf("cold_reboot = %+v", o)
}
// Win10 with startup-ipis patch -> experimental.
optsPatched := EvaluateOptimizations(win10, []string{"qemu-whpx-win10-compat.patch", "qemu-whpx-win10-startup-ipis.patch"})
if o := findOpt(t, optsPatched, "kernel_irqchip"); o.Status != "experimental" || !o.Supported {
t.Fatalf("kernel_irqchip with patch = %+v", o)
}
// Win11 where NestedVirtualization probe fails with 0x80370302.
win11BrokenNested := Report{
WHPX: WHPXReady,
NeedsColdRebootWorkaround: false,
WHPXCaps: WHPXCapabilities{
ModernOS: true,
APICEmulation: true,
KernelIrqchipAvailable: true,
NestedVirtProperty: false,
NestedVirtProbeError: "0x80370302",
},
}
opts11 := EvaluateOptimizations(win11BrokenNested, nil)
if o := findOpt(t, opts11, "kernel_irqchip"); o.Status != "unavailable" || o.Detail != "0x80370302" {
t.Fatalf("win11 broken nested = %+v", o)
}
if o := findOpt(t, opts11, "cold_reboot"); o.Status != "unavailable" {
t.Fatalf("win11 cold_reboot = %+v", o)
}
// Win11 with nested-virt-nonfatal patch -> kernel_irqchip recommended even when probe returns 0x80370302.
opts11Patched := EvaluateOptimizations(win11BrokenNested, []string{"qemu-whpx-nested-virt-nonfatal.patch"})
if o := findOpt(t, opts11Patched, "kernel_irqchip"); o.Status != "recommended" || !o.Supported {
t.Fatalf("win11 with nested-virt-nonfatal patch = %+v", o)
}
// Win11 with full support.
win11BrokenNested.WHPXCaps.NestedVirtProperty = true
win11BrokenNested.WHPXCaps.NestedVirtProbeError = ""
opts11Ok := EvaluateOptimizations(win11BrokenNested, nil)
if o := findOpt(t, opts11Ok, "kernel_irqchip"); o.Status != "recommended" || !o.Supported {
t.Fatalf("win11 full support = %+v", o)
}
}
func TestCanSafelyPinPCores(t *testing.T) {
// Arrow Lake Core Ultra 9 285H: 6 P-cores with NO Hyper-Threading (6 logical CPUs).
arrowLake := Report{
HasHybridCores: true,
PCoreCount: 6,
ECoreCount: 10,
PCoreMask: 0x3C03,
PCoreLogicalCPUs: []int{0, 1, 10, 11, 12, 13},
}
if ok, threads := CanSafelyPinPCores(arrowLake, 8); ok || threads != 6 {
t.Fatalf("arrowLake 8 vCPU: got (%v, %d), want (false, 6)", ok, threads)
}
if ok, threads := CanSafelyPinPCores(arrowLake, 6); ok || threads != 6 {
t.Fatalf("arrowLake 6 vCPU: got (%v, %d), want (false, 6)", ok, threads)
}
if ok, threads := CanSafelyPinPCores(arrowLake, 4); !ok || threads != 6 {
t.Fatalf("arrowLake 4 vCPU: got (%v, %d), want (true, 6)", ok, threads)
}
// Raptor Lake 6P with Hyper-Threading (12 logical CPUs).
raptorLake := Report{
HasHybridCores: true,
PCoreCount: 6,
ECoreCount: 8,
PCoreMask: 0xFFF,
PCoreLogicalCPUs: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
}
if ok, threads := CanSafelyPinPCores(raptorLake, 8); !ok || threads != 12 {
t.Fatalf("raptorLake 8 vCPU: got (%v, %d), want (true, 12)", ok, threads)
}
if ok, threads := CanSafelyPinPCores(raptorLake, 12); ok || threads != 12 {
t.Fatalf("raptorLake 12 vCPU: got (%v, %d), want (false, 12)", ok, threads)
}
}