From 2b1b6f0a4d5cd950b3df76454f8cc0da1a6ef316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A7=E7=80=AC=E7=B4=85=E8=8E=89=E6=A0=96?= Date: Mon, 25 Oct 2021 16:48:46 +0800 Subject: [PATCH] Implement CPU pinning While this can be done by [3rd party script](https://github.com/ayufan/pve-helpers/), running on non SMP system requires this to be set before KVM was even started, otherwise you get error [qemu kvm_arm_vcpu_init failed: Invalid argument"](https://forum.armbian.com/topic/16830-virtualization-support/). This is a [known limitation](https://www.mail-archive.com/qemu-devel@nongnu.org/msg755010.html) of QEMU. --- PVE/QemuServer.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 975cca3..f17bf06 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -686,6 +686,15 @@ EODESCR description => "Configure a VirtIO-based Random Number Generator.", optional => 1, }, + cpu_taskset => { + optional => 1, + type => 'string', + description => "CPU pinning config.", + verbose_description => "When specified VM will be launched with `cpuset -c {cpu_taskset} kvm ...`\n" + ."No argument test is performed so please make sure the value matches VM cpu total thread count.\n" + ."This is required when VM is sensitive to host context switching (e.g. gaming)," + ." or when host is not SMP so VM thread could be switched to a different CPU architecture (e.g. big.LITTLE for ARM).", + }, }; my $cicustom_fmt = { @@ -3219,6 +3228,10 @@ sub config_to_command { my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits} : $defaults->{cpuunits}; + if (defined($conf->{cpu_taskset})) { + push @$cmd, 'taskset', '-c', $conf->{cpu_taskset}; + } + push @$cmd, $kvm_binary; push @$cmd, '-id', $vmid;