]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/ProcFSTools.pm
bugfix: cpushares : default value is 1024 for cgroup v1
[pve-common.git] / src / PVE / ProcFSTools.pm
index e413ccf1c50b1f90575f9cb9a764c45fcc73a962..7687c13c4e30b9d483ebb624c8d522ca8a74ca3d 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use POSIX;
 use Time::HiRes qw (gettimeofday);
 use IO::File;
+use List::Util qw(sum);
 use PVE::Tools;
 use Cwd qw();
 
@@ -35,6 +36,7 @@ sub read_cpuinfo {
     my $fh = IO::File->new ($fn, "r");
     return $res if !$fh;
 
+    my $cpuid = 0;
     my $idhash = {};
     my $count = 0;
     while (defined(my $line = <$fh>)) {
@@ -47,7 +49,10 @@ sub read_cpuinfo {
        } 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;
+           $cpuid = $1;
+           $idhash->{$1} = 1 if not defined($idhash->{$1});
+       } elsif ($line =~ m/^cpu cores\s*:\s*(\d+)\s*$/i) {
+           $idhash->{$cpuid} = $1 if defined($idhash->{$cpuid});
        }
     }
 
@@ -56,6 +61,8 @@ sub read_cpuinfo {
 
     $res->{sockets} = scalar(keys %$idhash) || 1;
 
+    $res->{cores} = sum(values %$idhash) || 1;
+
     $res->{cpus} = $count;
 
     $fh->close;
@@ -125,6 +132,24 @@ sub read_loadavg {
     return wantarray ? (0, 0, 0) : 0;
 }
 
+sub read_pressure {
+
+    my $res = {};
+    foreach my $type (qw(cpu memory io)) {
+       if (my $fh = IO::File->new ("/proc/pressure/$type", "r")) {
+           while (defined (my $line = <$fh>)) {
+               if ($line =~ /^(some|full)\s+avg10\=(\d+\.\d+)\s+avg60\=(\d+\.\d+)\s+avg300\=(\d+\.\d+)\s+total\=(\d+)/) {
+                   $res->{$type}->{$1}->{avg10} = $2;
+                   $res->{$type}->{$1}->{avg60} = $3;
+                   $res->{$type}->{$1}->{avg300} = $4;
+               }
+           }
+           $fh->close;
+       }
+    }
+    return $res;
+}
+
 my $last_proc_stat;
 
 sub read_proc_stat {