[pve-devel] [RFC common 1/6] Include CPU flags in read_cpuinfo

Stefan Reiter s.reiter at proxmox.com
Wed Jul 17 15:03:43 CEST 2019


Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 src/PVE/ProcFSTools.pm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index 1b98b1e..027aa3a 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -29,6 +29,7 @@ sub read_cpuinfo {
 	mhz => 0,
 	cpus => 1,
 	sockets => 1,
+	flags => '',
     };
 
     my $fh = IO::File->new ($fn, "r");
@@ -43,19 +44,22 @@ sub read_cpuinfo {
 	    $res->{model} = $1 if $res->{model} eq 'unknown';
 	} elsif ($line =~ m/^cpu\s+MHz\s*:\s*(\d+\.\d+)\s*$/i) {
 	    $res->{mhz} = $1 if !$res->{mhz};
-	} elsif ($line =~ m/^flags\s*:.*(vmx|svm)/) {
-	    $res->{hvm} = 1; # Hardware Virtual Machine (Intel VT / AMD-V)
+	} elsif ($line =~ m/^flags\s*:\s*(.*)$/) {
+	    $res->{flags} = $1 if !length $res->{flags};
 	} elsif ($line =~ m/^physical id\s*:\s*(\d+)\s*$/i) {
 	    $idhash->{$1} = 1;
 	}
     }
 
+    # Hardware Virtual Machine (Intel VT / AMD-V)
+    $res->{hvm} = $res->{flags} =~ m/\s(vmx|svm)\s/;
+
     $res->{sockets} = scalar(keys %$idhash) || 1;
 
     $res->{cpus} = $count;
 
     $fh->close;
-    
+
     $cpuinfo = $res;
 
     return $res;
-- 
2.20.1





More information about the pve-devel mailing list