On 01/20/2014 07:12 PM, Thorsten Behrens wrote: > To reuse this from other drivers, like lxc. > --- > > Notes on v2: > - renamed to proper camel case: virCgroupGetDomainTotalCpuStats > > src/libvirt_private.syms | 1 + > src/qemu/qemu_driver.c | 54 ++---------------------------------------------- > src/util/vircgroup.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ > src/util/vircgroup.h | 5 +++++ > 4 files changed, 61 insertions(+), 52 deletions(-) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index e4815b3..97198d1 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -1013,6 +1013,7 @@ virCgroupGetCpuCfsQuota; > virCgroupGetCpusetCpus; > virCgroupGetCpusetMems; > virCgroupGetCpuShares; > +virCgroupGetDomainTotalCpuStats; > virCgroupGetFreezerState; > virCgroupGetMemoryHardLimit; > virCgroupGetMemorySoftLimit; > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index ebb77dc..a1e45c3 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -105,7 +105,6 @@ > > #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 > @@ -15304,56 +15303,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(¶ms[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(¶ms[1], > - VIR_DOMAIN_CPU_STATS_USERTIME, > - VIR_TYPED_PARAM_ULLONG, user) < 0) > - return -1; > - if (nparams > 2 && > - virTypedParameterAssign(¶ms[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: > @@ -15552,7 +15501,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); > diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c > index 83fcefc..66045fb 100644 > --- a/src/util/vircgroup.c > +++ b/src/util/vircgroup.c > @@ -51,11 +51,14 @@ > #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 > @@ -2629,6 +2632,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(¶ms[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(¶ms[1], > + VIR_DOMAIN_CPU_STATS_USERTIME, > + VIR_TYPED_PARAM_ULLONG, user) < 0) > + return -1; > + if (nparams > 2 && > + virTypedParameterAssign(¶ms[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) > { > diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h > index cd6b27b..b42bddc 100644 > --- a/src/util/vircgroup.h > +++ b/src/util/vircgroup.h > @@ -185,6 +185,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); > > Just rename and move, ACK thanks! -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list