提交 d8e5b975 编写于 作者: D Daniel Henrique Barboza 提交者: Ján Tomko

vircgroup.c: add virCgroupSetupCpuShares()

The code that calls virCgroupSetCpuShares() and virCgroupGetCpuShares()
is repeated in 4 different places. Let's put it in a new
virCgroupSetupCpuShares() to avoid code repetition.

There's a reason of why we execute a Get in the same value we
just executed Set, explained in detail by commit 97814d8a.
Let's add a gist of the reasoning behind it as a comment in
this new function as well.
Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 867c554e
......@@ -1732,6 +1732,7 @@ virCgroupSetupBlkioDeviceWeight;
virCgroupSetupBlkioDeviceWriteBps;
virCgroupSetupBlkioDeviceWriteIops;
virCgroupSetupCpusetCpus;
virCgroupSetupCpuShares;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
......
......@@ -40,10 +40,7 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
{
if (def->cputune.sharesSpecified) {
unsigned long long val;
if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
return -1;
if (virCgroupGetCpuShares(cgroup, &val) < 0)
if (virCgroupSetupCpuShares(cgroup, def->cputune.shares, &val) < 0)
return -1;
def->cputune.shares = val;
}
......
......@@ -1959,10 +1959,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
if (def) {
unsigned long long val;
if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul) < 0)
goto endjob;
if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
if (virCgroupSetupCpuShares(priv->cgroup, params[i].value.ul,
&val) < 0)
goto endjob;
def->cputune.shares = val;
......
......@@ -894,11 +894,10 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
if (vm->def->cputune.sharesSpecified) {
unsigned long long val;
if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0)
if (virCgroupSetupCpuShares(priv->cgroup, vm->def->cputune.shares,
&val) < 0)
return -1;
if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
return -1;
if (vm->def->cputune.shares != val) {
vm->def->cputune.shares = val;
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
......
......@@ -10648,10 +10648,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
if (def) {
unsigned long long val;
if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
goto endjob;
if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
if (virCgroupSetupCpuShares(priv->cgroup, value_ul, &val) < 0)
goto endjob;
def->cputune.shares = val;
......
......@@ -3681,3 +3681,23 @@ virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask)
return 0;
}
/* Per commit 97814d8ab3, the Linux kernel can consider a 'shares'
* value of '0' and '1' as 2, and any value larger than a maximum
* is reduced to maximum.
*
* The 'realValue' pointer holds the actual 'shares' value set by
* the kernel if the function returned success. */
int
virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares,
unsigned long long *realValue)
{
if (virCgroupSetCpuShares(cgroup, shares) < 0)
return -1;
if (virCgroupGetCpuShares(cgroup, realValue) < 0)
return -1;
return 0;
}
......@@ -222,6 +222,8 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares,
unsigned long long *realValue);
int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period);
int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册