render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From e0764ef7577519de460fc2c2d52127eafb077200 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <e0764ef7577519de460fc2c2d52127eafb077200@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:50 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2GetCpuacctUsage
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 567fcbdca56ac409e856a0be8425b2218d02fe81)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <26dc66d290ee4d5a4ba67470552df9d2fa4ae86b.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 33 +++++++++++++++++++++++++++++++++
c480ed
 1 file changed, 33 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 55f79af204..afa243b3c7 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -1456,6 +1456,37 @@ virCgroupV2SupportsCpuBW(virCgroupPtr cgroup)
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2GetCpuacctUsage(virCgroupPtr group,
c480ed
+                           unsigned long long *usage)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+    char *tmp;
c480ed
+
c480ed
+    if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c480ed
+                             "cpu.stat", &str) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (!(tmp = strstr(str, "usage_usec "))) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("cannot parse cpu usage stat '%s'"), str);
c480ed
+        return -1;
c480ed
+    }
c480ed
+    tmp += strlen("usage_usec ");
c480ed
+
c480ed
+    if (virStrToLong_ull(tmp, &tmp, 10, usage) < 0) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("Failed to parse value '%s' as number."), tmp);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    *usage *= 1000;
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -1511,6 +1542,8 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .setCpuCfsQuota = virCgroupV2SetCpuCfsQuota,
c480ed
     .getCpuCfsQuota = virCgroupV2GetCpuCfsQuota,
c480ed
     .supportsCpuBW = virCgroupV2SupportsCpuBW,
c480ed
+
c480ed
+    .getCpuacctUsage = virCgroupV2GetCpuacctUsage,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed