]> xenbits.xensource.com Git - libvirt.git/commitdiff
Make qemuGetDomainTotalCPUStats a virCgroup function.
authorThorsten Behrens <tbehrens@suse.com>
Fri, 14 Feb 2014 17:49:01 +0000 (18:49 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Feb 2014 15:20:09 +0000 (16:20 +0100)
To reuse this from other drivers, like lxc.

src/libvirt_private.syms
src/qemu/qemu_driver.c
src/util/vircgroup.c
src/util/vircgroup.h

index db8bdfc7527d6742486698e3f6993468e98abbbc..c404cee6211a3eeff0a26d6a8a134b489d4ca71c 100644 (file)
@@ -1025,6 +1025,7 @@ virCgroupGetCpuCfsQuota;
 virCgroupGetCpusetCpus;
 virCgroupGetCpusetMems;
 virCgroupGetCpuShares;
+virCgroupGetDomainTotalCpuStats;
 virCgroupGetFreezerState;
 virCgroupGetMemoryHardLimit;
 virCgroupGetMemorySoftLimit;
index 6ea837ef0409f4864a8fb0fa58803d8710f8e36e..a291c205d1aa8a50a98f005a3080e2ec7fb34cb8 100644 (file)
 
 #define QEMU_NB_NUMA_PARAM 2
 
-#define QEMU_NB_TOTAL_CPU_STAT_PARAM 3
 #define QEMU_NB_PER_CPU_STAT_PARAM 2
 
 #define QEMU_SCHED_MIN_PERIOD              1000LL
@@ -15903,56 +15902,6 @@ cleanup:
     return ret;
 }
 
-/* qemuDomainGetCPUStats() with start_cpu == -1 */
-static int
-qemuDomainGetTotalcpuStats(virDomainObjPtr vm,
-                           virTypedParameterPtr params,
-                           int nparams)
-{
-    unsigned long long cpu_time;
-    int ret;
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-
-    if (nparams == 0) /* return supported number of params */
-        return QEMU_NB_TOTAL_CPU_STAT_PARAM;
-    /* entry 0 is cputime */
-    ret = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
-    if (ret < 0) {
-        virReportSystemError(-ret, "%s", _("unable to get cpu account"));
-        return -1;
-    }
-
-    if (virTypedParameterAssign(&params[0], VIR_DOMAIN_CPU_STATS_CPUTIME,
-                                VIR_TYPED_PARAM_ULLONG, cpu_time) < 0)
-        return -1;
-
-    if (nparams > 1) {
-        unsigned long long user;
-        unsigned long long sys;
-
-        ret = virCgroupGetCpuacctStat(priv->cgroup, &user, &sys);
-        if (ret < 0) {
-            virReportSystemError(-ret, "%s", _("unable to get cpu account"));
-            return -1;
-        }
-
-        if (virTypedParameterAssign(&params[1],
-                                    VIR_DOMAIN_CPU_STATS_USERTIME,
-                                    VIR_TYPED_PARAM_ULLONG, user) < 0)
-            return -1;
-        if (nparams > 2 &&
-            virTypedParameterAssign(&params[2],
-                                    VIR_DOMAIN_CPU_STATS_SYSTEMTIME,
-                                    VIR_TYPED_PARAM_ULLONG, sys) < 0)
-            return -1;
-
-        if (nparams > QEMU_NB_TOTAL_CPU_STAT_PARAM)
-            nparams = QEMU_NB_TOTAL_CPU_STAT_PARAM;
-    }
-
-    return nparams;
-}
-
 /* This function gets the sums of cpu time consumed by all vcpus.
  * For example, if there are 4 physical cpus, and 2 vcpus in a domain,
  * then for each vcpu, the cpuacct.usage_percpu looks like this:
@@ -16150,7 +16099,8 @@ qemuDomainGetCPUStats(virDomainPtr domain,
     }
 
     if (start_cpu == -1)
-        ret = qemuDomainGetTotalcpuStats(vm, params, nparams);
+        ret = virCgroupGetDomainTotalCpuStats(priv->cgroup,
+                                              params, nparams);
     else
         ret = qemuDomainGetPercpuStats(vm, params, nparams,
                                        start_cpu, ncpus);
index 867bd26f2262e62dbdf9417c7ebabdc27f070c4f..7427a21df80025d37162c910062c193b2d051247 100644 (file)
 #include "virhashcode.h"
 #include "virstring.h"
 #include "virsystemd.h"
+#include "virtypedparam.h"
 
 #define CGROUP_MAX_VAL 512
 
 #define VIR_FROM_THIS VIR_FROM_CGROUP
 
+#define CGROUP_NB_TOTAL_CPU_STAT_PARAM 3
+
 #if defined(__linux__) && defined(HAVE_GETMNTENT_R) && \
     defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK)
 # define VIR_CGROUP_SUPPORTED
@@ -2821,6 +2824,56 @@ virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms)
 }
 
 
+
+int
+virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
+                                virTypedParameterPtr params,
+                                int nparams)
+{
+    unsigned long long cpu_time;
+    int ret;
+
+    if (nparams == 0) /* return supported number of params */
+        return CGROUP_NB_TOTAL_CPU_STAT_PARAM;
+    /* entry 0 is cputime */
+    ret = virCgroupGetCpuacctUsage(group, &cpu_time);
+    if (ret < 0) {
+        virReportSystemError(-ret, "%s", _("unable to get cpu account"));
+        return -1;
+    }
+
+    if (virTypedParameterAssign(&params[0], VIR_DOMAIN_CPU_STATS_CPUTIME,
+                                VIR_TYPED_PARAM_ULLONG, cpu_time) < 0)
+        return -1;
+
+    if (nparams > 1) {
+        unsigned long long user;
+        unsigned long long sys;
+
+        ret = virCgroupGetCpuacctStat(group, &user, &sys);
+        if (ret < 0) {
+            virReportSystemError(-ret, "%s", _("unable to get cpu account"));
+            return -1;
+        }
+
+        if (virTypedParameterAssign(&params[1],
+                                    VIR_DOMAIN_CPU_STATS_USERTIME,
+                                    VIR_TYPED_PARAM_ULLONG, user) < 0)
+            return -1;
+        if (nparams > 2 &&
+            virTypedParameterAssign(&params[2],
+                                    VIR_DOMAIN_CPU_STATS_SYSTEMTIME,
+                                    VIR_TYPED_PARAM_ULLONG, sys) < 0)
+            return -1;
+
+        if (nparams > CGROUP_NB_TOTAL_CPU_STAT_PARAM)
+            nparams = CGROUP_NB_TOTAL_CPU_STAT_PARAM;
+    }
+
+    return nparams;
+}
+
+
 int
 virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares)
 {
index 3159a08b92c197a7291f7e59c21cc41ad56f8884..fae4d927e0937bc29e1472d054b4ae535b6a6f79 100644 (file)
@@ -201,6 +201,11 @@ int virCgroupDenyDevicePath(virCgroupPtr group,
                             const char *path,
                             int perms);
 
+int
+virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
+                                virTypedParameterPtr params,
+                                int nparams);
+
 int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
 int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);