[PATCH 2/2] qemu: Implement qemuDomainGetStatsCpu fallback for qemu:///session

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For domains started under session URI, we don't set up CGroups
(well, how could we since we're not running as root anyways).
Nevertheless, fetching CPU statistics exits early because of
lacking cpuacct controller. But with recent extension to
virProcessGetStatInfo() we can get the values we need from the
proc filesystem. Implement the fallback for the session URI as
some of virt tools rely on cpu.* stats to be reported (virt-top,
virt-manager).

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/353
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1693707
Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d7283a6e47..c7cca64001 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17765,6 +17765,30 @@ qemuDomainGetStatsCpuCgroup(virDomainObj *dom,
     return 0;
 }
 
+
+static int
+qemuDomainGetStatsCpuProc(virDomainObj *vm,
+                          virTypedParamList *params)
+{
+    unsigned long long cpuTime = 0;
+    unsigned long long sysTime = 0;
+    unsigned long long userTime = 0;
+
+    if (virProcessGetStatInfo(&cpuTime, &sysTime, &userTime,
+                              NULL, NULL, vm->pid, 0) < 0) {
+        /* ignore error */
+        return 0;
+    }
+
+    if (virTypedParamListAddULLong(params, cpuTime, "cpu.time") < 0 ||
+        virTypedParamListAddULLong(params, userTime, "cpu.user") < 0 ||
+        virTypedParamListAddULLong(params, sysTime, "cpu.system") < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 qemuDomainGetStatsCpuHaltPollTimeFromStats(virDomainObj *dom,
                                            unsigned int privflags,
@@ -17860,8 +17884,15 @@ qemuDomainGetStatsCpu(virQEMUDriver *driver,
                       virTypedParamList *params,
                       unsigned int privflags)
 {
-    if (qemuDomainGetStatsCpuCgroup(dom, params) < 0)
-        return -1;
+    qemuDomainObjPrivate *priv = dom->privateData;
+
+    if (priv->cgroup) {
+        if (qemuDomainGetStatsCpuCgroup(dom, params) < 0)
+            return -1;
+    } else {
+        if (qemuDomainGetStatsCpuProc(dom, params) < 0)
+            return -1;
+    }
 
     if (qemuDomainGetStatsCpuCache(driver, dom, params) < 0)
         return -1;
-- 
2.35.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux