mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
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:
parent
857aac1f55
commit
c840448ebb
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user