[pve-devel] [PATCH manager 2/7] Broadcast supported CPU flags

Stefan Reiter s.reiter at proxmox.com
Mon Sep 2 16:27:54 CEST 2019


pvestatd will read supported CPU flags once on startup (since these
never change during runtime, and QEMU updates trigger a service
restart), then broadcasts them as a key-value pair to the cluster.

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

Changes from RFC:

* Cache joined value
* Add eval around QEMU query
* Detect value regression (e.g. "better" value available in cluster kv) and
  handle accordingly


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

diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index e138b2e8..84258daf 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -47,12 +47,15 @@ my $cmdline = [$0, @ARGV];
 my %daemon_options = (restart_on_error => 5, stop_wait_time => 5);
 my $daemon = __PACKAGE__->new('pvestatd', $cmdline, %daemon_options);
 
+my $supported_cpuflags;
+
 sub init {
     my ($self) = @_;
 
     $opt_debug = $self->{debug};
 
     PVE::Cluster::cfs_update();
+    update_supported_cpuflags();
 }
 
 sub shutdown {
@@ -72,6 +75,25 @@ sub hup {
     $restart_request = 1;
 }
 
+sub update_supported_cpuflags {
+    eval {
+	$supported_cpuflags = join(" ", @{PVE::QemuServer::query_supported_cpu_flags()});
+    };
+    warn $@ if $@;
+
+    # detect regression
+    if (!$supported_cpuflags || $supported_cpuflags eq '') {
+	my $prev_cpuflags = PVE::Cluster::get_node_kv('cpuflags', $nodename)->{$nodename};
+	if ($prev_cpuflags && $prev_cpuflags ne '') {
+	    $supported_cpuflags = $prev_cpuflags;
+	    warn "CPU flag detection failed, using old values\n";
+	} else {
+	    $supported_cpuflags = '';
+	    warn "CPU flag detection failed and no previous values found\n";
+	}
+    }
+}
+
 my $generate_rrd_string = sub {
     my ($data) = @_;
 
@@ -91,7 +113,9 @@ sub update_node_status {
 
     my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
 
-    my $maxcpu = $cpuinfo->{cpus}; 
+    my $maxcpu = $cpuinfo->{cpus};
+
+    PVE::Cluster::broadcast_node_kv('cpuflags', $supported_cpuflags);
 
     my $subinfo = PVE::INotify::read_file('subscription');
     my $sublevel = $subinfo->{level} || '';
@@ -104,7 +128,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