From 83870398192b0916da632c3fdbe14a133ed5e6ac Mon Sep 17 00:00:00 2001 From: Daniel Bowder Date: Thu, 30 Jun 2022 17:09:45 -0700 Subject: [PATCH] fix #3593: add affinity to qemu Reuse the PVE::CpuSet to validate cpuset formatting. Add new qemu property called 'affinity' to store the cpuset. Push taskset command in front of kvm if 'affinity' is set. Signed-off-by: Daniel Bowder --- PVE/QemuServer.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 9b9f0b0e..11029566 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -28,6 +28,7 @@ use UUID; use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file); use PVE::CGroup; +use PVE::CpuSet; use PVE::DataCenterConfig; use PVE::Exception qw(raise raise_param_exc); use PVE::Format qw(render_duration render_bytes); @@ -707,6 +708,11 @@ EODESCR description => "Some (read-only) meta-information about this guest.", optional => 1, }, + affinity => { + type => 'string', format => 'pve-cpuset', + description => "List of host cores used to execute guest processes.", + optional => 1, + }, }; my $cicustom_fmt = { @@ -1026,6 +1032,20 @@ foreach my $key (keys %$confdesc_cloudinit) { $confdesc->{$key} = $confdesc_cloudinit->{$key}; } +PVE::JSONSchema::register_format('pve-cpuset', \&pve_verify_cpuset); +sub pve_verify_cpuset { + my ($set_text, $noerr) = @_; + + my ($count, $members) = eval { PVE::CpuSet::parse_cpuset($set_text) }; + + if ($@) { + return if $noerr; + die "unable to parse cpuset option\n"; + } + + return PVE::CpuSet->new($members)->short_string(); +} + PVE::JSONSchema::register_format('pve-volume-id-or-qm-path', \&verify_volume_id_or_qm_path); sub verify_volume_id_or_qm_path { my ($volid, $noerr) = @_; @@ -3532,6 +3552,13 @@ sub config_to_command { my $use_old_bios_files = undef; ($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type); + if ($conf->{affinity}) { + push @$cmd, "taskset"; + push @$cmd, "--cpu-list"; + push @$cmd, "--all-tasks"; + push @$cmd, $conf->{affinity}; + } + push @$cmd, $kvm_binary; push @$cmd, '-id', $vmid;