[pve-devel] [PATCH qemu-server 3/6] cpuconfig: add get_cpu_topology helper
Alexandre Derumier
aderumier at odiso.com
Thu Mar 9 09:52:14 CET 2023
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 16 +++-------------
PVE/QemuServer/CPUConfig.pm | 11 +++++++++++
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index deb7faf..b49b59b 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -50,7 +50,7 @@ use PVE::QemuConfig;
use PVE::QemuServer::Helpers qw(min_version config_aware_timeout windows_version);
use PVE::QemuServer::Cloudinit;
use PVE::QemuServer::CGroup;
-use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
+use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options get_cpu_topology);
use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory;
@@ -3818,13 +3818,7 @@ sub config_to_command {
add_tpm_device($vmid, $devices, $conf);
- my $sockets = 1;
- $sockets = $conf->{smp} if $conf->{smp}; # old style - no longer iused
- $sockets = $conf->{sockets} if $conf->{sockets};
-
- my $cores = $conf->{cores} || 1;
-
- my $maxcpus = $sockets * $cores;
+ my ($sockets, $cores, $maxcpus) = get_cpu_topology($conf);
my $vcpus = $conf->{vcpus} ? $conf->{vcpus} : $maxcpus;
@@ -4660,11 +4654,7 @@ sub qemu_cpu_hotplug {
my $machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
- my $sockets = 1;
- $sockets = $conf->{smp} if $conf->{smp}; # old style - no longer iused
- $sockets = $conf->{sockets} if $conf->{sockets};
- my $cores = $conf->{cores} || 1;
- my $maxcpus = $sockets * $cores;
+ my ($sockets, $cores, $maxcpus) = get_cpu_topology($conf);
$vcpus = $maxcpus if !$vcpus;
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
index fb0861b..826e472 100644
--- a/PVE/QemuServer/CPUConfig.pm
+++ b/PVE/QemuServer/CPUConfig.pm
@@ -12,6 +12,7 @@ use base qw(PVE::SectionConfig Exporter);
our @EXPORT_OK = qw(
print_cpu_device
get_cpu_options
+get_cpu_topology
);
# under certain race-conditions, this module might be loaded before pve-cluster
@@ -659,6 +660,16 @@ sub get_cpu_from_running_vm {
return $1;
}
+sub get_cpu_topology {
+ my ($conf) = @_;
+
+ my $sockets = $conf->{sockets} || 1;
+ my $cores = $conf->{cores} || 1;
+ my $maxcpus = $sockets * $cores;
+
+ return ($sockets, $cores, $maxcpus);
+}
+
__PACKAGE__->register();
__PACKAGE__->init();
--
2.30.2
More information about the pve-devel
mailing list