Skip to content

Commit e63ed72

Browse files
committed
config(qemu): default x86_64 CPU to highest supported by host
We cannot use "-cpu max" because it causes BSOD issues (see #2368). QEMU documentation suggests choosing a CPU model that matches the generation of the host. Luckily for us, XNU already did the difficult work of mapping the CPUID to the generation. Note that Rosetta returns Westmere but AMD based Hackintoshes will still be unsupported and will default to the old CPU model. This change is needed to both improve performance of virtualized CPUs on Intel Macs as well as enable Windows 11 24H2 to be booted as it now requires SSE4.2 support. Fixes #6325 Fixes #6772
1 parent 91a10dc commit e63ed72

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Configuration/UTMQemuConfiguration+Arguments.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ import Virtualization // for getting network interfaces
294294
if system.cpu.rawValue == system.architecture.cpuType.default.rawValue {
295295
// if default and not hypervisor, we don't pass any -cpu argument for x86 and use host for ARM
296296
if isHypervisorUsed {
297-
#if !arch(x86_64)
297+
#if arch(x86_64)
298+
if let cpu = highestIntelCPUConfigurationForHost() {
299+
f("-cpu")
300+
f(cpu)
301+
}
302+
#else
298303
f("-cpu")
299304
f("host")
300305
#endif
@@ -306,6 +311,9 @@ import Virtualization // for getting network interfaces
306311
// ARM64 QEMU does not support "-cpu default" so we hard code a sensible default
307312
f("-cpu")
308313
f("cortex-a15")
314+
} else if system.architecture == .x86_64, let cpu = highestIntelCPUConfigurationForHost() {
315+
f("-cpu")
316+
f(cpu)
309317
}
310318
} else {
311319
f("-cpu")
@@ -1064,6 +1072,32 @@ import Virtualization // for getting network interfaces
10641072
}
10651073
}
10661074

1075+
@MainActor
1076+
private extension UTMQemuConfiguration {
1077+
#if arch(x86_64)
1078+
func highestIntelCPUConfigurationForHost() -> String? {
1079+
let cpufamily = Self.sysctlIntRead("hw.cpufamily")
1080+
// source: https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/machine.h
1081+
switch cpufamily {
1082+
case 0x78ea4fbc: return "Penryn"
1083+
case 0x6b5a4cd2: return "Nehalem"
1084+
case 0x573b5eec: return "Westmere"
1085+
case 0x5490b78c: return "SandyBridge"
1086+
case 0x1f65e835: return "IvyBridge"
1087+
case 0x10b282dc: return "Haswell"
1088+
case 0x582ed09c: return "Broadwell"
1089+
case 0x37fc219f /* Skylake */, 0x0f817246 /* Kabylake */, 0x1cf8a03e /* Cometlake */: return "Skylake-Client"
1090+
case 0x38435547 /* Icelake */: return "Icelake-Server" // client doesn't exist
1091+
default: return nil
1092+
}
1093+
}
1094+
#else
1095+
func highestIntelCPUConfigurationForHost() -> String? {
1096+
return "Skylake-Client"
1097+
}
1098+
#endif
1099+
}
1100+
10671101
private extension String {
10681102
func appendingDefaultPropertyName(_ name: String, value: String) -> String {
10691103
if !self.contains(name + "=") {

0 commit comments

Comments
 (0)