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 A7A571FF15C for ; Fri, 5 Sep 2025 12:33:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 78FB611D6F; Fri, 5 Sep 2025 12:33:20 +0200 (CEST) Message-ID: <8042d6f3-90c4-4ea3-8f9d-56371e16ec4a@proxmox.com> Date: Fri, 5 Sep 2025 12:32:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Proxmox VE development discussion , Daniel Kral References: <20250902112307.124706-1-d.kral@proxmox.com> <20250902112307.124706-4-d.kral@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: <20250902112307.124706-4-d.kral@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1757068348526 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.024 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [cpuconfig.pm] Subject: Re: [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" Am 02.09.25 um 1:23 PM schrieb Daniel Kral: > 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 Reviewed-by: Fiona Ebner with two comments below > --- > 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); Nit: even if it's the only possible value right now, I'd still use $arch instead of hardcoding 'x86_64'. > > 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) = @_; Alternatively, we could not pass $kvm_off and have the single caller override its own $kvm_off only when the returned value is defined. Not sure if that's cleaner, both seem slightly awkward. > > 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'; _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel