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
97814d8ab3.
Let's add a gist of the reasoning behind it as a comment in
this new function as well.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
virCgroupSetupBlkioDeviceWriteBps;
virCgroupSetupBlkioDeviceWriteIops;
virCgroupSetupCpusetCpus;
+virCgroupSetupCpuShares;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
{
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;
}
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;
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,
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;
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;
+}
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);