From a7dea8eecdee071e09cc90d6e7e47c8b93746bb1 Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Sun, 11 Aug 2013 00:37:36 +0530 Subject: [PATCH] CLOUDSTACK-3850: CPU cap should be per VM not per VCPU Signed-off-by: Koushik Das --- .../cloud/hypervisor/xen/resource/CitrixResourceBase.java | 4 ++-- .../hypervisor/xen/resource/XenServer56FP1Resource.java | 5 +++-- .../hypervisor/xen/resource/CitrixResourceBaseTest.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 66798b05364..338e74164dd 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -653,14 +653,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // weight based allocation - cpuWeight = (int)((speed*0.99) / _host.speed * _maxWeight); + cpuWeight = (int)((speed * 0.99) / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } if (vmSpec.getLimitCpuUse()) { long utilization = 0; // max CPU cap, default is unlimited - utilization = ((long)speed * 100 * vmSpec.getCpus()) / _host.speed ; + utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100); //vm.addToVCPUsParamsLive(conn, "cap", Long.toString(utilization)); currently xenserver doesnot support Xapi to add VCPUs params live. callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", Long.toString(utilization), "vmname", vmSpec.getName() ); } diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java index d230be10155..214dbd4059a 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java @@ -223,14 +223,15 @@ public class XenServer56FP1Resource extends XenServer56Resource { int cpuWeight = _maxWeight; // cpu_weight int utilization = 0; // max CPU cap, default is unlimited - // weight based allocation + // weight based allocation, CPU weight is calculated per VCPU cpuWeight = (int) ((speed * 0.99) / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } if (vmSpec.getLimitCpuUse()) { - utilization = (int) ((speed * 0.99) / _host.speed * 100); + // CPU cap is per VM, so need to assign cap based on the number of vcpus + utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100); } vcpuParams.put("weight", Integer.toString(cpuWeight)); diff --git a/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java b/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java index cb16ae2be15..920d6d24e62 100644 --- a/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java +++ b/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java @@ -145,7 +145,7 @@ public class CitrixResourceBaseTest { doNothing().when(vm).setVCPUsNumberLive(conn, 1L); doReturn(500).when(vmSpec).getMinSpeed(); doReturn(true).when(vmSpec).getLimitCpuUse(); - doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "100", "vmname", "i-2-3-VM"); + doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "99", "vmname", "i-2-3-VM"); Map args = (Map)mock(HashMap.class); when(host.callPlugin(conn, "vmops", "add_to_VCPUs_params_live", args)).thenReturn("Success"); doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "weight", "value", "253", "vmname", "i-2-3-VM"); @@ -154,6 +154,6 @@ public class CitrixResourceBaseTest { verify(vmSpec, times(1)).getLimitCpuUse(); verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "weight", "value", "253", "vmname", "i-2-3-VM"); - verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "100", "vmname", "i-2-3-VM"); + verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "99", "vmname", "i-2-3-VM"); } } \ No newline at end of file