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

[libvirt] [RFC][PATCHv1 5/5] Add a qemu driver for virDomainPcpuStats()




Signed-off-by: KAMEZAWA Hiroyuki <kamezawa hiroyu jp fujitsu com>
---
 src/qemu/qemu_conf.c   |    1 +
 src/qemu/qemu_driver.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index bb5421b..89c5b4c 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -302,6 +302,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
     } else {
         driver->cgroupControllers =
             (1 << VIR_CGROUP_CONTROLLER_CPU) |
+            (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
             (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
             (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
             (1 << VIR_CGROUP_CONTROLLER_BLKIO);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0a78a70..6db4f8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5011,6 +5011,75 @@ cleanup:
 }
 
 static int
+qemuDomainPcpuStats (virDomainPtr dom,
+                      struct _virDomainPcpuStat *stats,
+                      unsigned int nr_stats)
+{
+    struct qemud_driver *driver = dom->conn->privateData;
+    virDomainObjPtr vm = NULL;
+    virCgroupPtr group = NULL;
+    int ret = -1;
+    unsigned long long *array = NULL;
+    int i;
+
+
+    qemuDriverLock(driver);
+    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPUACCT)) {
+        qemuDriverUnlock(driver);
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("cgroup CPUACCT controller is not mounted"));
+        goto cleanup;
+    }
+
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    qemuDriverUnlock(driver);
+
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        qemuReportError(VIR_ERR_NO_DOMAIN,
+                        _("no domain with matching uuid '%s'"), uuidstr);
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(array, nr_stats) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (!virDomainObjIsActive(vm)) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("domain is not running"));
+        goto cleanup;
+    }
+
+    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+        qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("cannot find cgroup for domain %s"), vm->def->name);
+        goto cleanup;
+    }
+
+    ret = virCgroupGetCpuacctUsagePercpu(group, nr_stats, array);
+    if (ret <= 0) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    for (i = 0; i < ret; i++)
+       stats[i].cpuTime = array[i];
+
+cleanup:
+    if (group)
+        virCgroupFree(&group);
+    VIR_FREE(array);
+    if (vm)
+        virDomainObjUnlock(vm);
+    return ret;
+}
+
+
+
+static int
 qemudDomainBlockPeek (virDomainPtr dom,
                       const char *path,
                       unsigned long long offset, size_t size,
@@ -6981,7 +7050,7 @@ static virDriver qemuDriver = {
     qemudDomainBlockStats, /* domainBlockStats */
     qemudDomainInterfaceStats, /* domainInterfaceStats */
     qemudDomainMemoryStats, /* domainMemoryStats */
-    NULL, /* domainPcpuStats */
+    qemuDomainPcpuStats, /* domainPcpuStats */
     qemudDomainBlockPeek, /* domainBlockPeek */
     qemudDomainMemoryPeek, /* domainMemoryPeek */
     qemuDomainGetBlockInfo, /* domainGetBlockInfo */
-- 
1.7.4.1



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