render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 39640f2e78035b667588513395187a96ae71d6c4 Mon Sep 17 00:00:00 2001
Message-Id: <39640f2e78035b667588513395187a96ae71d6c4@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:57 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuCfsPeriod
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit c840448ebbeb3d4c34eafecf9c9c31c86f2f020f)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <93321a564a636498ef3e4144af737bcfc6e0f07a.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 18 ++----------------
 src/util/vircgroupbackend.h | 10 ++++++++++
 src/util/vircgroupv1.c      | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 953e353ec3..f4d995b22a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2227,19 +2227,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
 int
 virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
 {
-    /* The cfs_period should be greater or equal than 1ms, and less or equal
-     * than 1s.
-     */
-    if (cfs_period < 1000 || cfs_period > 1000000) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("cfs_period '%llu' must be in range (1000, 1000000)"),
-                       cfs_period);
-        return -1;
-    }
-
-    return virCgroupSetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.cfs_period_us", cfs_period);
+    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period);
 }
 
 
@@ -2254,9 +2242,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
 int
 virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
 {
-    return virCgroupGetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.cfs_period_us", cfs_period);
+    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 54fbead8a2..7dc1f77bfd 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -284,6 +284,14 @@ typedef int
 (*virCgroupGetCpuSharesCB)(virCgroupPtr group,
                            unsigned long long *shares);
 
+typedef int
+(*virCgroupSetCpuCfsPeriodCB)(virCgroupPtr group,
+                              unsigned long long cfs_period);
+
+typedef int
+(*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group,
+                              unsigned long long *cfs_period);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -341,6 +349,8 @@ struct _virCgroupBackend {
 
     virCgroupSetCpuSharesCB setCpuShares;
     virCgroupGetCpuSharesCB getCpuShares;
+    virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
+    virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 537845bafe..dc4cf1e9db 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1786,6 +1786,36 @@ virCgroupV1GetCpuShares(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetCpuCfsPeriod(virCgroupPtr group,
+                           unsigned long long cfs_period)
+{
+    /* The cfs_period should be greater or equal than 1ms, and less or equal
+     * than 1s.
+     */
+    if (cfs_period < 1000 || cfs_period > 1000000) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("cfs_period '%llu' must be in range (1000, 1000000)"),
+                       cfs_period);
+        return -1;
+    }
+
+    return virCgroupSetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_period_us", cfs_period);
+}
+
+
+static int
+virCgroupV1GetCpuCfsPeriod(virCgroupPtr group,
+                           unsigned long long *cfs_period)
+{
+    return virCgroupGetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_period_us", cfs_period);
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1841,6 +1871,8 @@ virCgroupBackend virCgroupV1Backend = {
 
     .setCpuShares = virCgroupV1SetCpuShares,
     .getCpuShares = virCgroupV1GetCpuShares,
+    .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
+    .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
 };
 
 
-- 
2.22.0