Skip to content

Commit a7dea8e

Browse files
Harikrishna Patnalakoushik-das
authored andcommitted
CLOUDSTACK-3850: CPU cap should be per VM not per VCPU
Signed-off-by: Koushik Das <koushik@apache.org>
1 parent 97b8f12 commit a7dea8e

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,14 @@ protected void scaleVM(Connection conn, VM vm, VirtualMachineTO vmSpec, Host hos
653653

654654
// weight based allocation
655655

656-
cpuWeight = (int)((speed*0.99) / _host.speed * _maxWeight);
656+
cpuWeight = (int)((speed * 0.99) / _host.speed * _maxWeight);
657657
if (cpuWeight > _maxWeight) {
658658
cpuWeight = _maxWeight;
659659
}
660660

661661
if (vmSpec.getLimitCpuUse()) {
662662
long utilization = 0; // max CPU cap, default is unlimited
663-
utilization = ((long)speed * 100 * vmSpec.getCpus()) / _host.speed ;
663+
utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100);
664664
//vm.addToVCPUsParamsLive(conn, "cap", Long.toString(utilization)); currently xenserver doesnot support Xapi to add VCPUs params live.
665665
callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", Long.toString(utilization), "vmname", vmSpec.getName() );
666666
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,15 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
223223
int cpuWeight = _maxWeight; // cpu_weight
224224
int utilization = 0; // max CPU cap, default is unlimited
225225

226-
// weight based allocation
226+
// weight based allocation, CPU weight is calculated per VCPU
227227
cpuWeight = (int) ((speed * 0.99) / _host.speed * _maxWeight);
228228
if (cpuWeight > _maxWeight) {
229229
cpuWeight = _maxWeight;
230230
}
231231

232232
if (vmSpec.getLimitCpuUse()) {
233-
utilization = (int) ((speed * 0.99) / _host.speed * 100);
233+
// CPU cap is per VM, so need to assign cap based on the number of vcpus
234+
utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100);
234235
}
235236

236237
vcpuParams.put("weight", Integer.toString(cpuWeight));

‎plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void testScaleVMF3() throws Types.XenAPIException, XmlRpcException {
145145
doNothing().when(vm).setVCPUsNumberLive(conn, 1L);
146146
doReturn(500).when(vmSpec).getMinSpeed();
147147
doReturn(true).when(vmSpec).getLimitCpuUse();
148-
doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "100", "vmname", "i-2-3-VM");
148+
doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "99", "vmname", "i-2-3-VM");
149149
Map<String, String> args = (Map<String, String>)mock(HashMap.class);
150150
when(host.callPlugin(conn, "vmops", "add_to_VCPUs_params_live", args)).thenReturn("Success");
151151
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 void testScaleVMF3() throws Types.XenAPIException, XmlRpcException {
154154

155155
verify(vmSpec, times(1)).getLimitCpuUse();
156156
verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "weight", "value", "253", "vmname", "i-2-3-VM");
157-
verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "100", "vmname", "i-2-3-VM");
157+
verify(_resource, times(1)).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "99", "vmname", "i-2-3-VM");
158158
}
159159
}

0 commit comments

Comments
 (0)