all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Daniel Kral <d.kral@proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server v2 2/4] cpu config: factor out gathering common cpu properties
Date: Fri, 5 Sep 2025 12:32:46 +0200	[thread overview]
Message-ID: <8042d6f3-90c4-4ea3-8f9d-56371e16ec4a@proxmox.com> (raw)
In-Reply-To: <20250902112307.124706-4-d.kral@proxmox.com>

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 <d.kral@proxmox.com>

Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>

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


  reply	other threads:[~2025-09-05 10:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 11:21 [pve-devel] [PATCH common/qemu-server v2 0/5] fix issues with viommu+vfio passthrough in #6608, #6378 Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH common v2 1/1] procfs: cpuinfo: expose x86_phys_bits and x86_virt_bits values Daniel Kral
2025-09-05  9:10   ` Fiona Ebner
2025-09-05 11:47     ` Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH qemu-server v2 1/4] fix #6608: expose viommu driver aw-bits option Daniel Kral
2025-09-05 10:07   ` Fiona Ebner
2025-09-05 11:45     ` Daniel Kral
2025-09-05 12:00       ` Fiona Ebner
2025-09-05 14:18   ` Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH qemu-server v2 2/4] cpu config: factor out gathering common cpu properties Daniel Kral
2025-09-05 10:32   ` Fiona Ebner [this message]
2025-09-02 11:22 ` [pve-devel] [RFC qemu-server v2 3/4] fix #6378 (continued): warn intel-iommu users about iommu and host aw bits mismatch Daniel Kral
2025-09-02 11:26   ` Daniel Kral
2025-09-05 10:50   ` Fiona Ebner
2025-09-05 11:38     ` Daniel Kral
2025-09-05 12:52       ` Fiona Ebner
2025-09-02 11:22 ` [pve-devel] [RFC qemu-server v2 4/4] machine: warn intel-iommu users about too large address width Daniel Kral
2025-09-05 10:55   ` Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8042d6f3-90c4-4ea3-8f9d-56371e16ec4a@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=d.kral@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal