diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 562071824b039af72f2170919d93c49290c77f6c..8594f75eafe6fb66ebac7d56805bd108a6c54deb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2223,19 +2223,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); } @@ -2250,9 +2238,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 54fbead8a2be916f9b902497246596fc03925be9..7dc1f77bfd04244b6832b83b1355efe581a4e166 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 9ce10fcbad74a8e5921031e6b469fb5c22f6038d..f1760d474d48ad8b9b0d6b7cc8c5ed07c8dac8ca 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1785,6 +1785,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, @@ -1840,6 +1870,8 @@ virCgroupBackend virCgroupV1Backend = { .setCpuShares = virCgroupV1SetCpuShares, .getCpuShares = virCgroupV1GetCpuShares, + .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod, + .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod, };