]> git.proxmox.com Git - pve-container.git/commitdiff
use CGroup::get_cpu_stat
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 3 Apr 2020 14:37:28 +0000 (16:37 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 4 Apr 2020 17:39:02 +0000 (19:39 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/LXC.pm

index 1f7aea6b479af39751bbb62677ea4da474b691d2..30e7713f15c07dfd6270536582f18818248310fc 100644 (file)
@@ -280,30 +280,27 @@ sub vmstatus {
            $d->{diskwrite} = 0;
        }
 
-       if (-d '/sys/fs/cgroup/cpuacct') {
-           my $pstat = $parse_cpuacct_stat->($vmid, $unpriv);
-
-           my $used = $pstat->{utime} + $pstat->{stime};
+       if (defined(my $cpu = $cgroups->get_cpu_stat())) {
+           # Total time (in milliseconds) used up by the cpu.
+           my $used_ms = $cpu->{utime} + $cpu->{stime};
 
            my $old = $last_proc_vmid_stat->{$vmid};
            if (!$old) {
                $last_proc_vmid_stat->{$vmid} = {
                    time => $cdtime,
-                   used => $used,
+                   used => $used_ms,
                    cpu => 0,
                };
                next;
            }
 
-           my $dtime = ($cdtime -  $old->{time}) * $cpucount * $cpuinfo->{user_hz};
-
-           if ($dtime > 1000) {
-               my $dutime = $used -  $old->{used};
-
-               $d->{cpu} = (($dutime/$dtime)* $cpucount) / $d->{cpus};
+           my $delta_ms = ($cdtime - $old->{time}) * $cpucount * 1000.0;
+           if ($delta_ms > 1000.0) {
+               my $delta_used_ms = $used_ms - $old->{used};
+               $d->{cpu} = (($delta_used_ms / $delta_ms) * $cpucount) / $d->{cpus};
                $last_proc_vmid_stat->{$vmid} = {
                    time => $cdtime,
-                   used => $used,
+                   used => $used_ms,
                    cpu => $d->{cpu},
                };
            } else {