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