Skip to content

Commit f4a3b21

Browse files
committed
Fix #471: Improve x86_64 emulation on arm64 platform
This change will use qemu64 cpu for better emulation and add some extra parameters like tcg accel and force multi threading where multiple host threads will be used for vcpus according to qemu documentation. Added few more extra parameters which are used by UTM for better emulation of x86_64 Signed-off-by: Gayan Perera <[email protected]>
1 parent f290fa5 commit f4a3b21

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/qemu/qemu.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ func appendArgsIfNoConflict(args []string, k, v string) []string {
134134
return append(args, k)
135135
}
136136

137-
if origV, ok := argValue(args, k); ok {
138-
logrus.Warnf("Not adding QEMU argument %q %q, as it conflicts with %q %q", k, v, k, origV)
139-
return args
137+
if k != "-global" {
138+
if origV, ok := argValue(args, k); ok {
139+
logrus.Warnf("Not adding QEMU argument %q %q, as it conflicts with %q %q", k, v, k, origV)
140+
return args
141+
}
140142
}
141143
return append(args, k, v)
142144
}
@@ -208,12 +210,24 @@ func Cmdline(cfg Config) (string, []string, error) {
208210
}
209211
switch *y.Arch {
210212
case limayaml.X8664:
211-
cpu := "Haswell-v4"
213+
cpu := "qemu64"
212214
if isNativeArch(*y.Arch) {
213215
cpu = "host"
214216
}
215217
args = appendArgsIfNoConflict(args, "-cpu", cpu)
216-
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel)
218+
if isNativeArch(*y.Arch) {
219+
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel)
220+
} else {
221+
// use q35 machine with vmware io port disabled.
222+
args = appendArgsIfNoConflict(args, "-machine", "q35,vmport=off")
223+
// use tcg accelerator with multi threading with 512MB translation block size
224+
// https://qemu-project.gitlab.io/qemu/devel/multi-thread-tcg.html?highlight=tcg
225+
// https://qemu-project.gitlab.io/qemu/system/invocation.html?highlight=tcg%20opts
226+
// this will make sure each vCPU will be backed by 1 host user thread.
227+
args = appendArgsIfNoConflict(args, "-accel", "tcg,thread=multi,tb-size=512")
228+
// This will disable CPU S3 state.
229+
args = appendArgsIfNoConflict(args, "-global", "ICH9-LPC.disable_s3=1")
230+
}
217231
case limayaml.AARCH64:
218232
cpu := "cortex-a72"
219233
if isNativeArch(*y.Arch) {

0 commit comments

Comments
 (0)