cpuacct cgroup provides per cpu cputime. Add an interface
for that.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
---
src/libvirt_private.syms | 1 +
src/util/cgroup.c | 27 +++++++++++++++++++++++++++
src/util/cgroup.h | 2 ++
3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ba7739d..f7a1ee7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -70,6 +70,7 @@ virCgroupFree;
virCgroupGetBlkioWeight;
virCgroupGetCpuShares;
virCgroupGetCpuacctUsage;
+virCgroupGetCpuacctUsagePercpu;
virCgroupGetFreezerState;
virCgroupGetMemoryHardLimit;
virCgroupGetMemorySoftLimit;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index afe8731..58ea805 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -1329,6 +1329,33 @@ int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long
*usage)
"cpuacct.usage", usage);
}
+int virCgroupGetCpuacctUsagePercpu(virCgroupPtr group,
+ int nr, unsigned long long *usage)
+{
+ int i, rc;
+ char *strval = NULL;
+ char *startp, *endp;
+ unsigned long long int value;
+
+ memset(usage, 0, sizeof(unsigned long long) * nr);
+
+ rc = virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
+ "cpuacct.usage_percpu", &strval);
+ if (rc)
+ goto out;
+
+ for (i = 0, startp = strval; i < nr; i++) {
+ if (virStrToLong_ull(startp, &endp, 10, &value))
+ break;
+ startp = endp;
+ usage[i] = value;
+ }
+ rc = i;
+out:
+ VIR_FREE(strval);
+ return rc;
+}
+
int virCgroupSetFreezerState(virCgroupPtr group, const char *state)
{
return virCgroupSetValueStr(group,
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 8ae756d..31cbcba 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -100,6 +100,8 @@ int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long
shares);
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
+int virCgroupGetCpuacctUsagePercpu(virCgroupPtr group,
+ int nr, unsigned long long *usage);
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
int virCgroupGetFreezerState(virCgroupPtr group, char **state);
--
1.7.4.1