Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/util/vircgroupv2.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 61c881f7e2..c6e66189bb 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1458,6 +1458,37 @@ virCgroupV2SupportsCpuBW(virCgroupPtr cgroup)
}
+static int
+virCgroupV2GetCpuacctUsage(virCgroupPtr group,
+ unsigned long long *usage)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+ char *tmp;
+
+ if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
+ "cpu.stat", &str) < 0) {
+ return -1;
+ }
+
+ if (!(tmp = strstr(str, "usage_usec "))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse cpu usage stat '%s'"), str);
+ return -1;
+ }
+ tmp += strlen("usage_usec ");
+
+ if (virStrToLong_ull(tmp, &tmp, 10, usage) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to parse value '%s' as number."),
tmp);
+ return -1;
+ }
+
+ *usage *= 1000;
+
+ return 0;
+}
+
+
virCgroupBackend virCgroupV2Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V2,
@@ -1513,6 +1544,8 @@ virCgroupBackend virCgroupV2Backend = {
.setCpuCfsQuota = virCgroupV2SetCpuCfsQuota,
.getCpuCfsQuota = virCgroupV2GetCpuCfsQuota,
.supportsCpuBW = virCgroupV2SupportsCpuBW,
+
+ .getCpuacctUsage = virCgroupV2GetCpuacctUsage,
};
--
2.17.1