137 lines
3.6 KiB
Go
137 lines
3.6 KiB
Go
package host
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Optimization summarizes the probed host availability and recommendation for
|
|
// one hardware/runtime optimization toggle.
|
|
type Optimization struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"` // recommended | available | experimental | auto | unavailable
|
|
Supported bool `json:"supported"`
|
|
Recommended bool `json:"recommended"`
|
|
Detail string `json:"detail,omitempty"`
|
|
}
|
|
|
|
// EvaluateOptimizations combines host capability probes with the active
|
|
// runtime's patch list so the UI can show accurate, self-explanatory guidance
|
|
// for every optimization toggle without guessing.
|
|
func EvaluateOptimizations(rep Report, runtimePatches []string) []Optimization {
|
|
hasPatch := func(substr string) bool {
|
|
for _, p := range runtimePatches {
|
|
if strings.Contains(strings.ToLower(p), strings.ToLower(substr)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
var out []Optimization
|
|
|
|
// 1. P-Core affinity pinning (hybrid Intel CPUs)
|
|
if rep.HasHybridCores {
|
|
out = append(out, Optimization{
|
|
ID: "pcore_pin",
|
|
Status: "recommended",
|
|
Supported: true,
|
|
Recommended: true,
|
|
Detail: fmt.Sprintf("%dP+%dE", rep.PCoreCount, rep.ECoreCount),
|
|
})
|
|
} else {
|
|
out = append(out, Optimization{
|
|
ID: "pcore_pin",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
})
|
|
}
|
|
|
|
// 2. WHPX kernel-irqchip (APIC emulation in Hyper-V)
|
|
switch {
|
|
case rep.WHPX != WHPXReady || !rep.WHPXCaps.KernelIrqchipAvailable:
|
|
out = append(out, Optimization{
|
|
ID: "kernel_irqchip",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
})
|
|
case !rep.NeedsColdRebootWorkaround:
|
|
// Windows 11 / Server 2022+: QEMU enables kernel-irqchip by default,
|
|
// unless NestedVirtualization property probe fails (e.g. hr=0x80370302).
|
|
if rep.WHPXCaps.NestedVirtProperty {
|
|
out = append(out, Optimization{
|
|
ID: "kernel_irqchip",
|
|
Status: "recommended",
|
|
Supported: true,
|
|
Recommended: true,
|
|
})
|
|
} else {
|
|
out = append(out, Optimization{
|
|
ID: "kernel_irqchip",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
Detail: rep.WHPXCaps.NestedVirtProbeError,
|
|
})
|
|
}
|
|
default:
|
|
// Windows 10: requires startup-ipis patch in runtime for multi-core boot.
|
|
if hasPatch("startup-ipis") {
|
|
out = append(out, Optimization{
|
|
ID: "kernel_irqchip",
|
|
Status: "experimental",
|
|
Supported: true,
|
|
Detail: "win10-startup-ipis",
|
|
})
|
|
} else {
|
|
out = append(out, Optimization{
|
|
ID: "kernel_irqchip",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
Detail: "win10-needs-patch",
|
|
})
|
|
}
|
|
}
|
|
|
|
// 3. Win10 cold-reboot compensation
|
|
if rep.NeedsColdRebootWorkaround {
|
|
out = append(out, Optimization{
|
|
ID: "cold_reboot",
|
|
Status: "auto",
|
|
Supported: true,
|
|
Recommended: true,
|
|
})
|
|
} else {
|
|
out = append(out, Optimization{
|
|
ID: "cold_reboot",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
})
|
|
}
|
|
|
|
// 4. Discrete Vulkan GPU acceleration
|
|
if rep.RecommendedGPU != nil && rep.RecommendedGPU.Kind == GPUDiscrete {
|
|
out = append(out, Optimization{
|
|
ID: "discrete_gpu",
|
|
Status: "recommended",
|
|
Supported: true,
|
|
Recommended: true,
|
|
Detail: rep.RecommendedGPU.Name,
|
|
})
|
|
} else if rep.RecommendedGPU != nil {
|
|
out = append(out, Optimization{
|
|
ID: "discrete_gpu",
|
|
Status: "available",
|
|
Supported: true,
|
|
Detail: rep.RecommendedGPU.Name,
|
|
})
|
|
} else {
|
|
out = append(out, Optimization{
|
|
ID: "discrete_gpu",
|
|
Status: "unavailable",
|
|
Supported: false,
|
|
})
|
|
}
|
|
|
|
return out
|
|
}
|