render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Pablo Greco 40546a
From 39640f2e78035b667588513395187a96ae71d6c4 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <39640f2e78035b667588513395187a96ae71d6c4@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:57 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuCfsPeriod
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit c840448ebbeb3d4c34eafecf9c9c31c86f2f020f)
Pablo Greco 40546a
Pablo Greco 40546a
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Message-Id: <93321a564a636498ef3e4144af737bcfc6e0f07a.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/util/vircgroup.c        | 18 ++----------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h | 10 ++++++++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 32 ++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 44 insertions(+), 16 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index 953e353ec3..f4d995b22a 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -2227,19 +2227,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
Pablo Greco 40546a
 int
Pablo Greco 40546a
 virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    /* The cfs_period should be greater or equal than 1ms, and less or equal
Pablo Greco 40546a
-     * than 1s.
Pablo Greco 40546a
-     */
Pablo Greco 40546a
-    if (cfs_period < 1000 || cfs_period > 1000000) {
Pablo Greco 40546a
-        virReportError(VIR_ERR_INVALID_ARG,
Pablo Greco 40546a
-                       _("cfs_period '%llu' must be in range (1000, 1000000)"),
Pablo Greco 40546a
-                       cfs_period);
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return virCgroupSetValueU64(group,
Pablo Greco 40546a
-                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
-                                "cpu.cfs_period_us", cfs_period);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -2254,9 +2242,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
Pablo Greco 40546a
 int
Pablo Greco 40546a
 virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    return virCgroupGetValueU64(group,
Pablo Greco 40546a
-                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
-                                "cpu.cfs_period_us", cfs_period);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
index 54fbead8a2..7dc1f77bfd 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -284,6 +284,14 @@ typedef int
Pablo Greco 40546a
 (*virCgroupGetCpuSharesCB)(virCgroupPtr group,
Pablo Greco 40546a
                            unsigned long long *shares);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupSetCpuCfsPeriodCB)(virCgroupPtr group,
Pablo Greco 40546a
+                              unsigned long long cfs_period);
Pablo Greco 40546a
+
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group,
Pablo Greco 40546a
+                              unsigned long long *cfs_period);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -341,6 +349,8 @@ struct _virCgroupBackend {
Pablo Greco 40546a
 
Pablo Greco 40546a
     virCgroupSetCpuSharesCB setCpuShares;
Pablo Greco 40546a
     virCgroupGetCpuSharesCB getCpuShares;
Pablo Greco 40546a
+    virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
Pablo Greco 40546a
+    virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
 typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index 537845bafe..dc4cf1e9db 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -1786,6 +1786,36 @@ virCgroupV1GetCpuShares(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1SetCpuCfsPeriod(virCgroupPtr group,
Pablo Greco 40546a
+                           unsigned long long cfs_period)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    /* The cfs_period should be greater or equal than 1ms, and less or equal
Pablo Greco 40546a
+     * than 1s.
Pablo Greco 40546a
+     */
Pablo Greco 40546a
+    if (cfs_period < 1000 || cfs_period > 1000000) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INVALID_ARG,
Pablo Greco 40546a
+                       _("cfs_period '%llu' must be in range (1000, 1000000)"),
Pablo Greco 40546a
+                       cfs_period);
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return virCgroupSetValueU64(group,
Pablo Greco 40546a
+                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
+                                "cpu.cfs_period_us", cfs_period);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1GetCpuCfsPeriod(virCgroupPtr group,
Pablo Greco 40546a
+                           unsigned long long *cfs_period)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    return virCgroupGetValueU64(group,
Pablo Greco 40546a
+                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
+                                "cpu.cfs_period_us", cfs_period);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -1841,6 +1871,8 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
 
Pablo Greco 40546a
     .setCpuShares = virCgroupV1SetCpuShares,
Pablo Greco 40546a
     .getCpuShares = virCgroupV1GetCpuShares,
Pablo Greco 40546a
+    .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
Pablo Greco 40546a
+    .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a