From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 1C95C1FF16F for ; Tue, 2 Sep 2025 13:23:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2698B11018; Tue, 2 Sep 2025 13:23:45 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Tue, 2 Sep 2025 13:21:59 +0200 Message-ID: <20250902112307.124706-4-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250902112307.124706-1-d.kral@proxmox.com> References: <20250902112307.124706-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1756812177017 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server v2 2/4] cpu config: factor out gathering common cpu properties X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" The same logic is already present in print_cpu_device(...), get_cpu_options(...), and get_cpu_bitness(...) and will also be used in a new helper the next patch, so factor it out in preparation. Signed-off-by: Daniel Kral --- src/PVE/QemuServer/CPUConfig.pm | 54 +++++++++++---------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm index 786a99d8..f57275dd 100644 --- a/src/PVE/QemuServer/CPUConfig.pm +++ b/src/PVE/QemuServer/CPUConfig.pm @@ -492,30 +492,15 @@ sub print_cpu_device { die "Hotplug of non x86_64 CPU not yet supported" if $arch ne 'x86_64'; my $kvm = $conf->{kvm} // is_native_arch($arch); - my $cpu = get_default_cpu_type('x86_64', $kvm); - if (my $cputype = $conf->{cpu}) { - my $cpuconf = PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $cputype) - or die "Cannot parse cpu description: $cputype\n"; - $cpu = $cpuconf->{cputype}; - - if (my $model = $builtin_models->{$cpu}) { - $cpu = $model->{'reported-model'}; - } elsif (is_custom_model($cputype)) { - my $custom_cpu = get_custom_model($cpu); - - $cpu = $custom_cpu->{'reported-model'} // $cpu_fmt->{'reported-model'}->{default}; - } - if (my $replacement_type = $depreacated_cpu_map->{$cpu}) { - $cpu = $replacement_type; - } - } + my ($cputype) = get_cpu_properties($conf->{cpu}, 'x86_64', $kvm); my $cores = $conf->{cores} || 1; my $current_core = ($id - 1) % $cores; my $current_socket = int(($id - 1 - $current_core) / $cores); - return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0"; + return + "$cputype-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0"; } # Resolves multiple arrays of hashes representing CPU flags with metadata to a @@ -597,9 +582,8 @@ sub parse_cpuflag_list { return $res; } -# Calculate QEMU's '-cpu' argument from a given VM configuration -sub get_cpu_options { - my ($conf, $arch, $kvm, $kvm_off, $machine_version, $winversion, $gpu_passthrough) = @_; +sub get_cpu_properties { + my ($cpu_prop_str, $arch, $kvm, $kvm_off) = @_; my $cputype = get_default_cpu_type($arch, $kvm); @@ -607,7 +591,7 @@ sub get_cpu_options { my $custom_cpu; my $builtin_cpu; my $hv_vendor_id; - if (my $cpu_prop_str = $conf->{cpu}) { + if ($cpu_prop_str) { $cpu = PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $cpu_prop_str) or die "Cannot parse cpu description: $cpu_prop_str\n"; @@ -632,6 +616,16 @@ sub get_cpu_options { $hv_vendor_id = $cpu->{'hv-vendor-id'} if defined($cpu->{'hv-vendor-id'}); } + return ($cputype, $cpu, $custom_cpu, $builtin_cpu, $kvm_off, $hv_vendor_id); +} + +# Calculate QEMU's '-cpu' argument from a given VM configuration +sub get_cpu_options { + my ($conf, $arch, $kvm, $kvm_off, $machine_version, $winversion, $gpu_passthrough) = @_; + + (my $cputype, my $cpu, my $custom_cpu, my $builtin_cpu, $kvm_off, my $hv_vendor_id) = + get_cpu_properties($conf->{cpu}, $arch, $kvm, $kvm_off); + my $pve_flags = get_pve_cpu_flags($conf, $kvm, $cputype, $arch, $machine_version); my $hv_flags = @@ -842,21 +836,7 @@ sub get_cpu_bitness { $arch //= get_host_arch(); - my $cputype = get_default_cpu_type($arch, 0); - - if ($cpu_prop_str) { - my $cpu = PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $cpu_prop_str) - or die "Cannot parse cpu description: $cpu_prop_str\n"; - - $cputype = $cpu->{cputype}; - - if (my $model = $builtin_models->{$cputype}) { - $cputype = $model->{'reported-model'}; - } elsif (is_custom_model($cputype)) { - my $custom_cpu = get_custom_model($cputype); - $cputype = $custom_cpu->{'reported-model'} // $cpu_fmt->{'reported-model'}->{default}; - } - } + my ($cputype) = get_cpu_properties($cpu_prop_str, $arch); return $cputypes_32bit->{$cputype} ? 32 : 64 if $arch eq 'x86_64'; return 64 if $arch eq 'aarch64'; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel