mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3850: CPU cap should be per VM not per VCPU
Signed-off-by: Koushik Das <koushik@apache.org>
This commit is contained in:
parent
97b8f123a0
commit
a7dea8eecd
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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<String, String> args = (Map<String, String>)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");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue