[pve-devel] [PATCH v4 manager 01/12] Broadcast supported CPU flags

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Oct 14 12:49:25 CEST 2019


On October 7, 2019 2:47 pm, Stefan Reiter wrote:
> 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() };

shouldn't this always return at least

{ tcg => undef, kvm => undef }

unless arch is aarch64 (which means it always fails anyway) or locking 
the fake VMID fails?

> +    warn $@ if $@;
> +
> +    if (!$supported_cpuflags) {

which makes this check kind of wrong?

> +	# 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 {

we enter the else branch

> +	# only set cached version if there's actually something to braodcast
> +	$cached_kvm_version = $kvm_version if $supported_cpuflags;

and set this, even though we don't have anything to broadcast. the 
post-fix if is redundant btw, since it's the negation of the outer if 
condition.

> +    }
> +
> +    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", '');

at least we end up here and clear both values ;)

> +	}
> +    }
> +}
> +
>  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
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 




More information about the pve-devel mailing list