vircgroup: extract virCgroupV1(Set|Get)CpuCfsPeriod

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-17 16:22:30 +02:00
parent 857aac1f55
commit c840448ebb
3 changed files with 44 additions and 16 deletions

View File

@ -2223,19 +2223,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
int int
virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
{ {
/* The cfs_period should be greater or equal than 1ms, and less or equal VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period);
* 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);
} }
@ -2250,9 +2238,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
int int
virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
{ {
return virCgroupGetValueU64(group, VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period);
VIR_CGROUP_CONTROLLER_CPU,
"cpu.cfs_period_us", cfs_period);
} }

View File

@ -284,6 +284,14 @@ typedef int
(*virCgroupGetCpuSharesCB)(virCgroupPtr group, (*virCgroupGetCpuSharesCB)(virCgroupPtr group,
unsigned long long *shares); 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 { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
@ -341,6 +349,8 @@ struct _virCgroupBackend {
virCgroupSetCpuSharesCB setCpuShares; virCgroupSetCpuSharesCB setCpuShares;
virCgroupGetCpuSharesCB getCpuShares; virCgroupGetCpuSharesCB getCpuShares;
virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;

View File

@ -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 = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
@ -1840,6 +1870,8 @@ virCgroupBackend virCgroupV1Backend = {
.setCpuShares = virCgroupV1SetCpuShares, .setCpuShares = virCgroupV1SetCpuShares,
.getCpuShares = virCgroupV1GetCpuShares, .getCpuShares = virCgroupV1GetCpuShares,
.setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
.getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
}; };