[pve-devel] [PATCH qemu-server 5/7] Support custom CPU types in get_cpu_options
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Sep 9 11:53:35 CEST 2019
On September 2, 2019 4:27 pm, Stefan Reiter wrote:
> Supports custom basemodels (model shown to QEMU, i.e. must be a default
nit: s/shown/known/ ?
high-level: if we allow basing custom models on other custom models,
wouldn't we need to compute an effective model first, and then use that?
e.g., if I define the following:
cpu-model: leaf
basemodel: intermediate
vendor: intel
flags: +aes,+pcid
host-phys-bits: 1
cpu-model: intermediate1
vendor: amd
basemodel: intermediate2
flags: -aes;-ssbd
phys-bits: 32
cpu-model: intermediate2
vendor: amd
basemodel: phenom
flags: +ssbd;+md-clear
phys-bits: 48
I'd expect the end result to be:
vendor: intel
flags: phenom +aes +pcid -ssbd +md-clear
phys-bits: host (overriding the one from intermediate)
(ignore that those flags don't make much sense ;))
this patch (series) only looks at the leaf and the last basemodel in the
chain, and ignores everything inbetween. vendor also can't be
'inherited' from basemodel, because it is always set.
we can either go full-blown 'inherit properties across multiple
basemodels', or we limit ourselves to 'basemodel must be a regular cpu
model'. the former is of course more flexible (allowing stuff like
re-using a custom model and just adding one flag, without duplication),
but the latter is a lot more simple (one additional level to check
instead of recursive walk, loop and conflict detection, no nested
versioning needed, etc.pp.). something inbetween like the current patch
does is probably confusing.
> model), vendors and (host-)phys-bits for VMs with large amounts of RAM
> (see bug #2318).
>
> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
> ---
> PVE/QemuServer.pm | 32 +++++++++++++++++++++++++++++++-
> 1 file changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 97fa955..417bea8 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -37,6 +37,7 @@ use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr);
> use PVE::QemuServer::Memory;
> use PVE::QemuServer::USB qw(parse_usb_device);
> use PVE::QemuServer::Cloudinit;
> +use PVE::QemuServer::CustomCPUConfig;
> use PVE::SysFSTools;
> use PVE::Systemd;
> use Time::HiRes qw(gettimeofday);
> @@ -3595,10 +3596,30 @@ sub get_cpu_options {
> $cpu = 'cortex-a57';
> }
> my $hv_vendor_id;
> + my $custom_cpu_config;
> if (my $cputype = $conf->{cpu}) {
> my $cpuconf = PVE::JSONSchema::parse_property_string($cpu_fmt, $cputype)
> or die "Cannot parse cpu description: $cputype\n";
> $cpu = $cpuconf->{cputype};
> +
> + if (!defined($cpu_vendor_list->{$cpu})) {
> + # not a default CPU model, read config and see if $cpu is name of
> + # a custom model
> + my $cpu_models = PVE::QemuServer::CustomCPUConfig::config_from_file();
> + if ($cpu_models && ($custom_cpu_config = $cpu_models->get_model_by_name($cpu))) {
> + $cpu = $custom_cpu_config->{basemodel};
> +
> + # 'basemodel' could be custom as well
> + while (!defined($cpu_vendor_list->{$cpu})) {
> + my $custom_base = $cpu_models->get_model_by_name($cpu);
> + die "unknown CPU basemodel: $cpu\n" if !$custom_base;
> + $cpu = $custom_base->{basemodel};
> + }
possible endless loop
> + } else {
> + die "unknown CPU model (neither default nor custom): $cpu\n";
> + }
> + }
> +
> $kvm_off = 1 if $cpuconf->{hidden};
> $hv_vendor_id = $cpuconf->{'hv-vendor-id'};
>
> @@ -3628,13 +3649,22 @@ sub get_cpu_options {
>
> push @$cpuFlags, 'kvm=off' if $kvm_off;
>
> - if (my $cpu_vendor = $cpu_vendor_list->{$cpu}) {
> + if (defined($custom_cpu_config) && (my $custom_vendor = $custom_cpu_config->{vendor})) {
> + push @$cpuFlags, "vendor=${custom_vendor}"
> + if $custom_vendor ne 'default';
> + } elsif (my $cpu_vendor = $cpu_vendor_list->{$cpu}) {
> push @$cpuFlags, "vendor=${cpu_vendor}"
> if $cpu_vendor ne 'default';
> } elsif ($arch ne 'aarch64') {
> die "internal error"; # should not happen
> }
>
> + $cpu .= ",host-phys-bits=true"
> + if defined($custom_cpu_config) && $custom_cpu_config->{'host-phys-bits'};
> + $cpu .= ",phys-bits=$custom_cpu_config->{'phys-bits'}"
> + if defined($custom_cpu_config) && $custom_cpu_config->{'phys-bits'}
> + && !$custom_cpu_config->{'host-phys-bits'};
> +
> $cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
>
> return ('-cpu', $cpu);
> --
> 2.20.1
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>
More information about the pve-devel
mailing list