[pve-devel] [PATCH v3 manager 01/11] Broadcast supported CPU flags

Stefan Reiter s.reiter at proxmox.com
Thu Oct 3 16:56:16 CEST 2019


pvestatd will check if the KVM version has changed using
kvm_user_version (which automatically clears its cache if QEMU/KVM
updates), and if it has, query supported CPU flags and broadcast them as
key-value pairs to the cluster.

If detection fails, we clear the kv-store and set up a delay (120s), to not
try again too quickly.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

v2 -> v3:
* broadcast tcg and kvm flags if available
* clear kv-store on error, wait a bit until retry

v1 -> v2:
* broadcast directly in update_supported_cpuflags
* use kvm_user_version to determine when to re-query CPU flags
* don't broadcast flags when unchanged or empty


 PVE/Service/pvestatd.pm | 46 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index bad1b73d..f99036c4 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -78,6 +78,46 @@ sub hup {
     $restart_request = 1;
 }
 
+my $cached_kvm_version = '';
+my $next_flag_update_time;
+my $failed_flag_update_delay_sec = 120;
+
+sub update_supported_cpuflags {
+    my $kvm_version = PVE::QemuServer::kvm_user_version();
+
+    # only update when QEMU/KVM version has changed, as that is the only reason
+    # why flags could change without restarting pvestatd
+    return if $cached_kvm_version && $cached_kvm_version eq $kvm_version;
+
+    if ($next_flag_update_time && $next_flag_update_time > time()) {
+	return;
+    }
+    $next_flag_update_time = 0;
+
+    my $supported_cpuflags = eval { PVE::QemuServer::query_supported_cpu_flags() };
+    warn $@ if $@;
+
+    if (!$supported_cpuflags) {
+	# something went wrong, clear broadcast flags and set try-again delay
+	warn "CPU flag detection failed, will try again after delay\n";
+	$next_flag_update_time = time() + $failed_flag_update_delay_sec;
+
+	$supported_cpuflags = {};
+    } else {
+	# only set cached version if there's actually something to braodcast
+	$cached_kvm_version = $kvm_version if $supported_cpuflags;
+    }
+
+    for my $accel ("tcg", "kvm") {
+	if ($supported_cpuflags->{$accel}) {
+	    PVE::Cluster::broadcast_node_kv("cpuflags-$accel", join(' ', @{$supported_cpuflags->{$accel}}));
+	} else {
+	    # clear potentially invalid data
+	    PVE::Cluster::broadcast_node_kv("cpuflags-$accel", '');
+	}
+    }
+}
+
 my $generate_rrd_string = sub {
     my ($data) = @_;
 
@@ -97,7 +137,9 @@ sub update_node_status {
 
     my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
 
-    my $maxcpu = $cpuinfo->{cpus}; 
+    my $maxcpu = $cpuinfo->{cpus};
+
+    update_supported_cpuflags();
 
     my $subinfo = PVE::INotify::read_file('subscription');
     my $sublevel = $subinfo->{level} || '';
@@ -110,7 +152,7 @@ sub update_node_status {
 	$netin += $netdev->{$dev}->{receive};
 	$netout += $netdev->{$dev}->{transmit};
     }
- 
+
     my $meminfo = PVE::ProcFSTools::read_meminfo();
 
     my $dinfo = df('/', 1);     # output is bytes
-- 
2.20.1





More information about the pve-devel mailing list