Files
Reims-Go/internal/host/host.go
T
Nwflower 9e357ba38c fix(perf,sec): add 3-tier hybrid CPU affinity fallback and move QMP to AF_UNIX
- Detect 3-tier hybrid CPUs (P + E + LP-E, e.g. Intel Core Ultra 200 Arrow Lake) in host topology probe and select NonLPEMask (P+E, excluding slow LP-E cores) when VM vCPUs exceed P-core thread headroom
- Migrate Win10 cold-reboot secondary QMP socket from tcp:127.0.0.1:<port> to Windows AF_UNIX (reims-go-reboot.sock, with short tmp fallback) so guest code cannot reach unauthenticated QMP via SLIRP 10.0.2.2
- Automatically strip legacy tcp:127.0.0.1 QMP args on next start and update roadmap M3.2
2026-11-28 08:32:44 -07:00

113 lines
3.9 KiB
Go

package host
import "strings"
type GPUKind string
const (
GPUDiscrete GPUKind = "discrete"
GPUIntegrated GPUKind = "integrated"
GPUVirtual GPUKind = "virtual"
GPUUnknown GPUKind = "unknown"
)
type GPUInfo struct {
Name string `json:"name"`
VulkanICD string `json:"vulkan_icd"`
Kind GPUKind `json:"kind"`
}
type WHPXState string
const (
WHPXReady WHPXState = "ready"
WHPXNoHypervisor WHPXState = "no_hypervisor"
WHPXMissing WHPXState = "missing"
WHPXUnsupported WHPXState = "unsupported"
)
type WHPXCapabilities struct {
ModernOS bool `json:"modern_os"`
APICEmulation bool `json:"apic_emulation"`
KernelIrqchipAvailable bool `json:"kernel_irqchip_available"`
NestedVirtProperty bool `json:"nested_virt_property"`
NestedVirtProbeError string `json:"nested_virt_probe_error,omitempty"`
}
type Report struct {
OS string `json:"os"`
Arch string `json:"arch"`
LogicalCPUs int `json:"logical_cpus"`
PhysicalCores int `json:"physical_cores"`
HasHybridCores bool `json:"has_hybrid_cores"`
PCoreCount int `json:"p_core_count"`
ECoreCount int `json:"e_core_count"`
LPECoreCount int `json:"lpe_core_count,omitempty"`
PCoreMask uint64 `json:"p_core_mask"`
PCoreMaskHex string `json:"p_core_mask_hex"`
PCoreLogicalCPUs []int `json:"p_core_logical_cpus,omitempty"`
ECoreLogicalCPUs []int `json:"e_core_logical_cpus,omitempty"`
NonLPEMask uint64 `json:"non_lpe_mask,omitempty"`
NonLPEMaskHex string `json:"non_lpe_mask_hex,omitempty"`
NonLPELogicalCPUs []int `json:"non_lpe_logical_cpus,omitempty"`
TotalRAMGB float64 `json:"total_ram_gb"`
AvailRAMGB float64 `json:"avail_ram_gb"`
// Commit memory: QEMU commits all guest RAM at start (CreateFileMapping), so
// a VM needs its memory free in the commit charge, not just in physical RAM.
// Measured 2026-11-28: 14.7 GiB commit free with 17.3 GiB physical free, and a
// 16G guest failed ("Cannot set up guest memory"). portable-runtime-spec.md §5.1.
CommitAvailGB float64 `json:"commit_avail_gb"`
CommitLimitGB float64 `json:"commit_limit_gb"`
DataRoot string `json:"data_root"`
FreeDiskGB float64 `json:"free_disk_gb"`
WHPX WHPXState `json:"whpx"`
WHPXCaps WHPXCapabilities `json:"whpx_caps"`
NeedsColdRebootWorkaround bool `json:"needs_cold_reboot_workaround"`
GPUs []GPUInfo `json:"gpus"`
RecommendedGPU *GPUInfo `json:"recommended_gpu,omitempty"`
}
// ClassifyGPU distinguishes discrete, integrated, and virtual display adapters.
func ClassifyGPU(name string) GPUKind {
low := strings.ToLower(name)
for _, v := range []string{"todesk", "gameviewer", "parsec", "virtual", "idd", "microsoft basic", "spacedesk"} {
if strings.Contains(low, v) {
return GPUVirtual
}
}
for _, d := range []string{"nvidia", "geforce", "rtx", "gtx", "quadro", "radeon rx", "radeon pro", "intel(r) arc"} {
if strings.Contains(low, d) {
return GPUDiscrete
}
}
for _, i := range []string{"intel(r) uhd", "intel(r) hd", "intel(r) iris", "radeon(tm) graphics"} {
if strings.Contains(low, i) {
return GPUIntegrated
}
}
return GPUUnknown
}
// PickRecommendedGPU selects the best Vulkan GPU (preferring discrete over integrated, skipping virtual).
func PickRecommendedGPU(gpus []GPUInfo) *GPUInfo {
for i := range gpus {
if gpus[i].Kind == GPUDiscrete && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
for i := range gpus {
if gpus[i].Kind == GPUIntegrated && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
for i := range gpus {
if gpus[i].Kind != GPUVirtual && gpus[i].VulkanICD != "" {
cp := gpus[i]
return &cp
}
}
return nil
}