[PATCH 2/3] qemu_driver: clamp value for setting sched cpu_shares with --config.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As shown in 'man virsh' about schedinfo:

           Note: The cpu_shares parameter has a valid value range of 0-262144;
	   Negative values are wrapped to positive, and larger values are capped at
           the maximum.  Therefore, -1 is a useful shorthand for 262144.
	   On the Linux kernel, the values 0 and 1 are automatically converted to
	   a minimal value of 2.
it works well with --live, but not with --config.

Example:
	# virsh schedinfo rhel7-ful --set cpu_shares=0 --config
		Scheduler      : posix
		cpu_shares     : 0
		vcpu_period    : 0
		vcpu_quota     : 0
		emulator_period: 0
		emulator_quota : 0
cpu_shares is 0 rather than expected 2.

What's worse, when we start it again, it is the default value of
cpu_shares 1024.

Because when we set the value of cpu_shares, when flag is --live,
write the value into cgroup/cpu.shares. Then it will convert the
value into the range of [2, 262144]. When flag is --config, we
set the value into vmdef immidiately and 0 means no settting for
cpu_shares. When we start vm again, libvirt use default value(1024)
for it.

This patch clamp the cpu_shares value when flag is --config, then
we will get then "correct" settting in output of virsh schedinfo
and value in cgroup after next booting of vm.

Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52ca47c..7648865 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -112,6 +112,8 @@ VIR_LOG_INIT("qemu.qemu_driver");
 #define QEMU_SCHED_MAX_PERIOD           1000000LL
 #define QEMU_SCHED_MIN_QUOTA               1000LL
 #define QEMU_SCHED_MAX_QUOTA  18446744073709551LL
+#define QEMU_SCHED_MIN_SHARES                 2LL
+#define QEMU_SCHED_MAX_SHARES            262144LL
 
 #if HAVE_LINUX_KVM_H
 # include <linux/kvm.h>
@@ -9063,7 +9065,9 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-                vmdef->cputune.shares = value_ul;
+                vmdef->cputune.shares = CLAMP(value_ul,
+                                              QEMU_SCHED_MIN_SHARES,
+                                              QEMU_SCHED_MAX_SHARES);
                 vmdef->cputune.sharesSpecified = true;
             }
 
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]