[pve-devel] applied: [PATCH v6 manager 12/12] Broadcast supported CPU flags

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jan 14 12:05:53 CET 2020


On 11/21/19 3:53 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>
> ---
> 
> Depends on updated qemu-server.
> 

did not tracked that yet, as it's catched by eval anyway and I did not wanted to bump
qemu-server already.

> 
>  PVE/Service/pvestatd.pm | 43 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
> index 92d94809..924b7366 100755
> --- a/PVE/Service/pvestatd.pm
> +++ b/PVE/Service/pvestatd.pm
> @@ -74,6 +74,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}}));


maybe we want to prefix the "cpuflags-$accel" broadcast key with "qm-" ?

> +	} else {
> +	    # clear potentially invalid data
> +	    PVE::Cluster::broadcast_node_kv("cpuflags-$accel", '');
> +	}
> +    }
> +}
> +
>  my $generate_rrd_string = sub {
>      my ($data) = @_;
>  
> @@ -90,6 +131,8 @@ sub update_node_status {
>      my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
>      my $maxcpu = $cpuinfo->{cpus};
>  
> +    update_supported_cpuflags();
> +
>      my $subinfo = PVE::INotify::read_file('subscription');
>      my $sublevel = $subinfo->{level} || '';
>  
> 





More information about the pve-devel mailing list