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.rei...@proxmox.com> --- v4 -> v5: * fix error detection ($supported_cpuflags can contain { kvm => undef, tcg => undef} but is still invalid) 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 | 47 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm index bad1b73d..18c3f6df 100755 --- a/PVE/Service/pvestatd.pm +++ b/PVE/Service/pvestatd.pm @@ -78,6 +78,47 @@ 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 || + (!$supported_cpuflags->{tcg} && !$supported_cpuflags->{kvm})) { + # 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; + } + + 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 +138,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 +153,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 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel