From 7bbc507416170c1754730318d5576f4104e0c755 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Tue, 10 Mar 2020 16:14:50 +0100 Subject: [PATCH] pmb.qemu: use -cpu host for KVM, make configurable with --cpu (!1886) For KVM the code is run pretty much natively on the host CPU, so all CPU extensions available on the host CPU can be also used inside the VM. To expose that information to the VM we should pass "-cpu host", so the VM is aware of which CPU is in use. For CPU emulation, QEMU uses a rather minimal CPU on x86_64 by default. It does not have support for SSE3/4 etc, which may be required for some applications to work properly (e.g. Android in Anbox). Add a --cpu flag to make the emulated CPU configurable. Useful values are for example --cpu max to emulate all implemented CPU features. --- pmb/parse/arguments.py | 6 ++++++ pmb/qemu/run.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 041aeb5a..044450fa 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -126,6 +126,12 @@ def arguments_qemu(subparser): ret.add_argument("--no-kvm", dest="qemu_kvm", default=True, action='store_false', help="Avoid using hardware-assisted virtualization with KVM " "even when available (SLOW!)") + ret.add_argument("--cpu", dest="qemu_cpu", + help="Override emulated QEMU CPU. By default, the host CPU " + "will be emulated when using KVM and the QEMU default otherwise " + "(usually a CPU with minimal features). " + "A useful value is 'max' (emulate all features that are available), " + "use --cpu help to get a list of possible values from QEMU.") ret.add_argument("--tablet", dest="qemu_tablet", action='store_true', default=False, help="Use 'tablet' instead of 'mouse' input " diff --git a/pmb/qemu/run.py b/pmb/qemu/run.py index 54bbdfc8..777fe7a4 100644 --- a/pmb/qemu/run.py +++ b/pmb/qemu/run.py @@ -146,9 +146,13 @@ def command_qemu(args, arch, img_path): native = args.arch_native == args.deviceinfo["arch"] if args.qemu_kvm and native and os.path.exists("/dev/kvm"): command += ["-enable-kvm"] + command += ["-cpu", "host"] else: logging.info("WARNING: QEMU is not using KVM and will run slower!") + if args.qemu_cpu: + command += ["-cpu", args.qemu_cpu] + display = args.qemu_display if display != "none": display += ",gl=" + ("on" if args.qemu_gl else "off")