[pve-devel] [PATCH v3 qemu-server 6/7] cpuconfig: add find_hosts_common_flags
Alexandre Derumier
aderumier at odiso.com
Mon May 22 12:25:27 CEST 2023
find common flags && vendor between differents hosts
if vendor are different (amd/intel), return default vendor
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer/CPUConfig.pm | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
index 63e57d4..3f24b31 100644
--- a/PVE/QemuServer/CPUConfig.pm
+++ b/PVE/QemuServer/CPUConfig.pm
@@ -741,6 +741,38 @@ sub find_best_cpumodel {
}
}
+sub find_hosts_common_flags {
+ my ($hosts_cpuinfo) = @_;
+
+ my $common_vendor = undef;
+ my $common_flags = {};
+
+ my $hosts_flags = {};
+ my $last_vendor = undef;
+ foreach my $cpuinfo (@$hosts_cpuinfo) {
+ my $flags = get_host_cpu_flags($cpuinfo);
+ foreach my $flag (keys %$flags) {
+ $hosts_flags->{$flag}++;
+ }
+
+ if ($last_vendor && $cpuinfo->{vendor} ne $last_vendor) {
+ $common_vendor = 'default';
+ } else {
+ $last_vendor = $cpuinfo->{vendor};
+ $common_vendor = $last_vendor;
+ }
+ }
+
+ my $nb_hosts = @{$hosts_cpuinfo};
+ foreach my $flag (keys %$hosts_flags) {
+ if ($hosts_flags->{$flag} == $nb_hosts) {
+ $common_flags->{$flag} = 1;
+ }
+ }
+
+ return ($common_flags, $common_vendor);
+}
+
__PACKAGE__->register();
__PACKAGE__->init();
--
2.30.2
More information about the pve-devel
mailing list