]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
cgroup: Implement cpu.cfs_period_us and cpu.cfs_quota_us tuning API
authorWen Congyang <wency@cn.fujitsu.com>
Thu, 21 Jul 2011 07:21:05 +0000 (15:21 +0800)
committerWen Congyang <wency@cn.fujitsu.com>
Thu, 21 Jul 2011 09:11:12 +0000 (17:11 +0800)
This patch provides 4 APIs to get and set cpu.cfs_period_us and cpu.cfs_quota_us.

src/libvirt_private.syms
src/util/cgroup.c
src/util/cgroup.h

index 096d9b0328dc97d31f7baf2c411ef58f829a41d8..98b125b4b7f608076afe5dd2492f265f548b0318 100644 (file)
@@ -71,6 +71,8 @@ virCgroupForVcpu;
 virCgroupFree;
 virCgroupGetBlkioWeight;
 virCgroupGetCpuShares;
+virCgroupGetCpuCfsPeriod;
+virCgroupGetCpuCfsQuota;
 virCgroupGetCpuacctUsage;
 virCgroupGetFreezerState;
 virCgroupGetMemoryHardLimit;
@@ -85,6 +87,8 @@ virCgroupPathOfController;
 virCgroupRemove;
 virCgroupSetBlkioWeight;
 virCgroupSetCpuShares;
+virCgroupSetCpuCfsPeriod;
+virCgroupSetCpuCfsQuota;
 virCgroupSetFreezerState;
 virCgroupSetMemory;
 virCgroupSetMemoryHardLimit;
index a0921d7f23a535813c5019e15f15d438325f991b..9fe561d49fb5247ad98929f2b8bbe365d1c8c989 100644 (file)
@@ -398,8 +398,6 @@ static int virCgroupSetValueI64(virCgroupPtr group,
     return rc;
 }
 
-#if 0
-/* This is included for completeness, but not yet used */
 static int virCgroupGetValueI64(virCgroupPtr group,
                                 int controller,
                                 const char *key,
@@ -419,7 +417,6 @@ out:
 
     return rc;
 }
-#endif
 
 static int virCgroupGetValueU64(virCgroupPtr group,
                                 int controller,
@@ -1384,6 +1381,84 @@ int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
                                 "cpu.shares", shares);
 }
 
+/**
+ * virCgroupSetCpuCfsPeriod:
+ *
+ * @group: The cgroup to change cpu.cfs_period_us for
+ * @cfs_period: The bandwidth period in usecs
+ *
+ * Returns: 0 on success
+ */
+int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
+{
+    /* The cfs_period shoule be greater or equal than 1ms, and less or equal
+     * than 1s.
+     */
+    if (cfs_period < 1000 || cfs_period > 1000000)
+        return -EINVAL;
+
+    return virCgroupSetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_period_us", cfs_period);
+}
+
+/**
+ * virCgroupGetCpuCfsPeriod:
+ *
+ * @group: The cgroup to get cpu.cfs_period_us for
+ * @cfs_period: Pointer to the returned bandwidth period in usecs
+ *
+ * Returns: 0 on success
+ */
+int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
+{
+    return virCgroupGetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_period_us", cfs_period);
+}
+
+/**
+ * virCgroupSetCpuCfsQuota:
+ *
+ * @group: The cgroup to change cpu.cfs_quota_us for
+ * @cfs_quota: the cpu bandwidth (in usecs) that this tg will be allowed to
+ *             consume over period
+ *
+ * Returns: 0 on success
+ */
+int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
+{
+    if (cfs_quota >= 0) {
+        /* The cfs_quota shoule be greater or equal than 1ms */
+        if (cfs_quota < 1000)
+            return -EINVAL;
+
+        /* check overflow */
+        if (cfs_quota > ULLONG_MAX / 1000)
+            return -EINVAL;
+    }
+
+    return virCgroupSetValueI64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_quota_us", cfs_quota);
+}
+
+/**
+ * virCgroupGetCpuCfsQuota:
+ *
+ * @group: The cgroup to get cpu.cfs_quota_us for
+ * @cfs_quota: Pointer to the returned cpu bandwidth (in usecs) that this tg
+ *             will be allowed to consume over period
+ *
+ * Returns: 0 on success
+ */
+int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
+{
+    return virCgroupGetValueI64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_quota_us", cfs_quota);
+}
+
 int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage)
 {
     return virCgroupGetValueU64(group,
index 1d04418b4c0ea9cceddb6ae137cefdd2b75abce4..d190bb3c56961d837b9632922a68f2b946e56b0e 100644 (file)
@@ -104,6 +104,12 @@ int virCgroupDenyDevicePath(virCgroupPtr group,
 int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
 int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
 
+int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period);
+int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period);
+
+int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota);
+int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota);
+
 int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
 
 int virCgroupSetFreezerState(virCgroupPtr group, const char *state);