[pve-devel] [PATCH qemu-server 07/13] move cpu option creation into separate sub

Dominik Csapak d.csapak at proxmox.com
Thu Oct 25 16:19:27 CEST 2018


On 10/24/18 10:56 AM, Wolfgang Bumiller wrote:
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
>   PVE/QemuServer.pm | 95 ++++++++++++++++++++++++++++++-------------------------
>   1 file changed, 52 insertions(+), 43 deletions(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index ab0f662..53d3c1b 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -3208,6 +3208,57 @@ sub get_command_for_arch($) {
>       return $cmd;
>   }
>   
> +sub get_cpu_options {
> +    my ($conf, $arch, $machine, $kvm, $machine_type, $kvm_off, $kvmver, $winversion, $gpu_passthrough) = @_;
> +
> +    my $cpuFlags = [];
> +    my $ostype = $conf->{ostype};
> +
> +    my $cpu = $kvm ? "kvm64" : "qemu64";
> +    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};
> +	$kvm_off = 1 if $cpuconf->{hidden};
> +
> +	if (defined(my $flags = $cpuconf->{flags})) {
> +	    push @$cpuFlags, split(";", $flags);
> +	}
> +    }
> +
> +    push @$cpuFlags , '+lahf_lm' if $cpu eq 'kvm64';
> +
> +    push @$cpuFlags , '-x2apic'
> +	if $conf->{ostype} && $conf->{ostype} eq 'solaris';
> +
> +    push @$cpuFlags, '+sep' if $cpu eq 'kvm64' || $cpu eq 'kvm32';
> +
> +    push @$cpuFlags, '-rdtscp' if $cpu =~ m/^Opteron/;
> +
> +    if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
> +
> +	push @$cpuFlags , '+kvm_pv_unhalt' if $kvm;
> +	push @$cpuFlags , '+kvm_pv_eoi' if $kvm;
> +    }
> +
> +    add_hyperv_enlightenments($cpuFlags, $winversion, $machine_type, $kvmver, $conf->{bios}, $gpu_passthrough) if $kvm;
> +
> +    push @$cpuFlags, 'enforce' if $cpu ne 'host' && $kvm;
> +
> +    push @$cpuFlags, 'kvm=off' if $kvm_off;
> +
> +    if (my $cpu_vendor = $cpu_vendor_list->{$cpu}) {
> +	push @$cpuFlags, "vendor=${cpu_vendor}"
> +	    if $cpu_vendor ne 'default';
> +    } elsif ($arch ne 'arm64') {
> +	die "internal error"; # should not happen
> +    }

does arm not support/have cpu vendors ? maybe we could make it 
configurable instead of ignoring it on arm?

> +
> +    $cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
> +
> +    return ('-cpu', $cpu);
> +}
> +
>   sub config_to_command {
>       my ($storecfg, $vmid, $conf, $defaults, $forcemachine) = @_;
>   
> @@ -3215,7 +3266,6 @@ sub config_to_command {
>       my $globalFlags = [];
>       my $machineFlags = [];
>       my $rtcFlags = [];
> -    my $cpuFlags = [];
>       my $devices = [];
>       my $pciaddr = '';
>       my $bridges = {};
> @@ -3516,48 +3566,7 @@ sub config_to_command {
>   	push @$rtcFlags, 'base=localtime';
>       }
>   
> -    my $cpu = $kvm ? "kvm64" : "qemu64";
> -    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};
> -	$kvm_off = 1 if $cpuconf->{hidden};
> -
> -	if (defined(my $flags = $cpuconf->{flags})) {
> -	    push @$cpuFlags, split(";", $flags);
> -	}
> -    }
> -
> -    push @$cpuFlags , '+lahf_lm' if $cpu eq 'kvm64';
> -
> -    push @$cpuFlags , '-x2apic'
> -	if $conf->{ostype} && $conf->{ostype} eq 'solaris';
> -
> -    push @$cpuFlags, '+sep' if $cpu eq 'kvm64' || $cpu eq 'kvm32';
> -
> -    push @$cpuFlags, '-rdtscp' if $cpu =~ m/^Opteron/;
> -
> -    if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
> -
> -	push @$cpuFlags , '+kvm_pv_unhalt' if $kvm;
> -	push @$cpuFlags , '+kvm_pv_eoi' if $kvm;
> -    }
> -
> -    add_hyperv_enlightenments($cpuFlags, $winversion, $machine_type, $kvmver, $conf->{bios}, $gpu_passthrough) if $kvm;
> -
> -    push @$cpuFlags, 'enforce' if $cpu ne 'host' && $kvm;
> -
> -    push @$cpuFlags, 'kvm=off' if $kvm_off;
> -
> -    my $cpu_vendor = $cpu_vendor_list->{$cpu} ||
> -	die "internal error"; # should not happen
> -
> -    push @$cpuFlags, "vendor=${cpu_vendor}"
> -	if $cpu_vendor ne 'default';
> -
> -    $cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
> -
> -    push @$cmd, '-cpu', $cpu;
> +    push @$cmd, get_cpu_options($conf, $arch, $base_machine, $kvm, $machine_type, $kvm_off, $kvmver, $winversion, $gpu_passthrough);
>   
>       PVE::QemuServer::Memory::config($conf, $vmid, $sockets, $cores, $defaults, $hotplug_features, $cmd);
>       
> 





More information about the pve-devel mailing list