[pve-devel] [PATCH] implement cpuunit with cgroups

Alexandre Derumier aderumier at odiso.com
Tue Jun 2 08:06:45 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index f3cd41e..df30907 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -123,7 +123,7 @@ my $confdesc = {
     cpulimit => {
 	optional => 1,
 	type => 'integer',
-	description => "Limit of CPU usage in per cent. Note if the computer has 2 CPUs, it has total of 200% CPU time. Value '0' indicates no CPU limit.\n\nNOTE: This option is currently ignored.",
+	description => "Limit of CPU usage in per cent. Note if the computer has 2 CPUs, it has total of 200% CPU time. Value '0' indicates no CPU limit.\n\n.",
 	minimum => 0,
 	default => 0,
     },
@@ -2562,6 +2562,10 @@ sub config_to_command {
     push @$cmd, '--slice', "qemu";
     push @$cmd, '--unit', $vmid;
     push @$cmd, '-p', "CPUShares=$cpuunits";
+    if ($conf->{cpulimit}) {
+	my $cpulimit = $conf->{cpulimit} * 100;
+	push @$cmd, '-p', "CPUQuota=$cpulimit"."\%";
+    }
 
     push @$cmd, '/usr/bin/kvm';
 
@@ -3831,6 +3835,8 @@ sub vmconfig_hotplug_pending {
 		qemu_memory_hotplug($vmid, $conf, $defaults, $opt);
 	    } elsif ($opt eq 'cpuunits') {
 		cgroups_write("cpu", $vmid, "cpu.shares", $defaults->{cpuunits});
+	    } elsif ($opt eq 'cpulimit') {
+		cgroups_write("cpu", $vmid, "cpu.cfs_quota_us", -1);
 	    } else {
 		die "skip\n";
 	    }
@@ -3886,6 +3892,9 @@ sub vmconfig_hotplug_pending {
 		$value = qemu_memory_hotplug($vmid, $conf, $defaults, $opt, $value);
 	    } elsif ($opt eq 'cpuunits') {
 		cgroups_write("cpu", $vmid, "cpu.shares", $conf->{pending}->{$opt});
+	    } elsif ($opt eq 'cpulimit') {
+		my $cpulimit = $conf->{pending}->{$opt} == 0 ? -1 : $conf->{pending}->{$opt} * 100000;
+		cgroups_write("cpu", $vmid, "cpu.cfs_quota_us", $cpulimit);
 	    } else {
 		die "skip\n";  # skip non-hot-pluggable options
 	    }
-- 
2.1.4




More information about the pve-devel mailing list