Commit d61e8d1d authored by Anton Beloglazov's avatar Anton Beloglazov

- Fixed MIPS allocation to PEs for time-shared VM scheduling: MIPS of single VM…

- Fixed MIPS allocation to PEs for time-shared VM scheduling: MIPS of single VM can be split among several PEs with the only constraint that MIPS of the VM < MIPS of a single PE, as VMs cannot be parallelized
parent a4d90aab
...@@ -81,7 +81,16 @@ public class HostDynamicWorkload extends Host { ...@@ -81,7 +81,16 @@ public class HostDynamicWorkload extends Host {
double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm); double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm);
Log.formatLine("%.2f: [Host #" + getId() + "] Total allocated MIPS for VM #" + vm.getId() + " (Host #" + vm.getHost().getId() + ") is %.2f, was requested %.2f out of total %.2f (%.2f%%)", CloudSim.clock(), totalAllocatedMips, totalRequestedMips, vm.getMips(), totalRequestedMips / vm.getMips() * 100); if (!Log.isDisabled()) {
Log.formatLine("%.2f: [Host #" + getId() + "] Total allocated MIPS for VM #" + vm.getId() + " (Host #" + vm.getHost().getId() + ") is %.2f, was requested %.2f out of total %.2f (%.2f%%)", CloudSim.clock(), totalAllocatedMips, totalRequestedMips, vm.getMips(), totalRequestedMips / vm.getMips() * 100);
List<Pe> pes = getVmScheduler().getPesAllocatedForVM(vm);
StringBuilder pesString = new StringBuilder();
for (Pe pe : pes) {
pesString.append(String.format(" PE #" + pe.getId() + ": %.2f.", pe.getPeProvisioner().getTotalAllocatedMipsForVm(vm)));
}
Log.formatLine("%.2f: [Host #" + getId() + "] MIPS for VM #" + vm.getId() + " by PEs (" + getPesNumber() + " * " + getVmScheduler().getPeCapacity() + ")." + pesString, CloudSim.clock());
}
if (getVmsMigratingIn().contains(vm)) { if (getVmsMigratingIn().contains(vm)) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock()); Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock());
...@@ -103,20 +112,6 @@ public class HostDynamicWorkload extends Host { ...@@ -103,20 +112,6 @@ public class HostDynamicWorkload extends Host {
return smallerTime; return smallerTime;
} }
// /**
// * Gets the mips for migrating in vm.
// *
// * @param vm the vm
// * @return the mips for migrating in vm
// */
// protected List<Double> getMipsForMigratingInVm(Vm vm) {
// List<Double> mipsForMigratingIn = new LinkedList<Double>();
// for (Double mips : vm.getCurrentRequestedMips()) {
// mipsForMigratingIn.add(mips * 0.1); // 10% of the requested MIPS
// }
// return mipsForMigratingIn;
// }
/** /**
* Gets the completed vms. * Gets the completed vms.
......
...@@ -28,6 +28,9 @@ public abstract class VmScheduler { ...@@ -28,6 +28,9 @@ public abstract class VmScheduler {
/** The peList. */ /** The peList. */
private List<? extends Pe> peList; private List<? extends Pe> peList;
/** The map of VMs to PEs. */
private Map<String, List<Pe>> peMap;
/** The MIPS that are currently allocated to the VMs. */ /** The MIPS that are currently allocated to the VMs. */
private Map<String, List<Double>> mipsMap; private Map<String, List<Double>> mipsMap;
...@@ -51,6 +54,7 @@ public abstract class VmScheduler { ...@@ -51,6 +54,7 @@ public abstract class VmScheduler {
*/ */
public VmScheduler(List<? extends Pe> pelist) { public VmScheduler(List<? extends Pe> pelist) {
setPeList(pelist); setPeList(pelist);
setPeMap(new HashMap<String, List<Pe>>());
setMipsMap(new HashMap<String, List<Double>>()); setMipsMap(new HashMap<String, List<Double>>());
setAvailableMips(PeList.getTotalMips(getPeList())); setAvailableMips(PeList.getTotalMips(getPeList()));
setVmsMigratingIn(new ArrayList<String>()); setVmsMigratingIn(new ArrayList<String>());
...@@ -83,8 +87,6 @@ public abstract class VmScheduler { ...@@ -83,8 +87,6 @@ public abstract class VmScheduler {
/** /**
* Releases PEs allocated to all the VMs. * Releases PEs allocated to all the VMs.
* *
* @param vm the vm
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -95,6 +97,16 @@ public abstract class VmScheduler { ...@@ -95,6 +97,16 @@ public abstract class VmScheduler {
pe.getPeProvisioner().deallocateMipsForAllVms(); pe.getPeProvisioner().deallocateMipsForAllVms();
} }
} }
/**
* Gets the pes allocated for vm.
*
* @param vm the vm
* @return the pes allocated for vm
*/
public List<Pe> getPesAllocatedForVM(Vm vm) {
return getPeMap().get(vm.getUid());
}
/** /**
* Returns the MIPS share of each Pe that is allocated to a given VM. * Returns the MIPS share of each Pe that is allocated to a given VM.
...@@ -166,6 +178,7 @@ public abstract class VmScheduler { ...@@ -166,6 +178,7 @@ public abstract class VmScheduler {
/** /**
* Gets the vm list. * Gets the vm list.
* *
* @param <T> the generic type
* @return the vm list * @return the vm list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -176,6 +189,7 @@ public abstract class VmScheduler { ...@@ -176,6 +189,7 @@ public abstract class VmScheduler {
/** /**
* Sets the vm list. * Sets the vm list.
* *
* @param <T> the generic type
* @param peList the pe list * @param peList the pe list
*/ */
protected <T extends Pe> void setPeList(List<T> peList) { protected <T extends Pe> void setPeList(List<T> peList) {
...@@ -253,5 +267,23 @@ public abstract class VmScheduler { ...@@ -253,5 +267,23 @@ public abstract class VmScheduler {
protected void setVmsMigratingIn(List<String> vmsMigratingIn) { protected void setVmsMigratingIn(List<String> vmsMigratingIn) {
this.vmsMigratingIn = vmsMigratingIn; this.vmsMigratingIn = vmsMigratingIn;
} }
/**
* Gets the pe map.
*
* @return the pe map
*/
public Map<String, List<Pe>> getPeMap() {
return peMap;
}
/**
* Sets the pe map.
*
* @param peMap the pe map
*/
protected void setPeMap(Map<String, List<Pe>> peMap) {
this.peMap = peMap;
}
} }
...@@ -11,6 +11,7 @@ package org.cloudbus.cloudsim; ...@@ -11,6 +11,7 @@ package org.cloudbus.cloudsim;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -18,7 +19,6 @@ import java.util.Map.Entry; ...@@ -18,7 +19,6 @@ import java.util.Map.Entry;
import org.cloudbus.cloudsim.lists.PeList; import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.provisioners.PeProvisioner; import org.cloudbus.cloudsim.provisioners.PeProvisioner;
// TODO: Auto-generated Javadoc
/** /**
* VmSchedulerTimeShared is a VMM allocation policy that * VmSchedulerTimeShared is a VMM allocation policy that
* allocates one or more Pe to a VM, and allows sharing * allocates one or more Pe to a VM, and allows sharing
...@@ -52,9 +52,6 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -52,9 +52,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
*/ */
@Override @Override
public boolean allocatePesForVm(Vm vm, List<Double> mipsShareRequested) { public boolean allocatePesForVm(Vm vm, List<Double> mipsShareRequested) {
if (getVmsMigratingIn().contains(vm.getUid()) && getVmsMigratingOut().contains(vm.getUid())) {
Log.print("found\n");
}
/** /**
* TODO: add the same to RAM and BW provisioners * TODO: add the same to RAM and BW provisioners
*/ */
...@@ -160,31 +157,38 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -160,31 +157,38 @@ public class VmSchedulerTimeShared extends VmScheduler {
* Update allocation of VMs on PEs. * Update allocation of VMs on PEs.
*/ */
protected void updatePeProvisioning() { protected void updatePeProvisioning() {
getPeMap().clear();
for (Pe pe : getPeList()) {
pe.getPeProvisioner().deallocateMipsForAllVms();
}
Iterator<Pe> peIterator = getPeList().iterator(); Iterator<Pe> peIterator = getPeList().iterator();
Pe pe = peIterator.next(); Pe pe = peIterator.next();
PeProvisioner peProvisioner = pe.getPeProvisioner(); PeProvisioner peProvisioner = pe.getPeProvisioner();
peProvisioner.deallocateMipsForAllVms();
double availableMips = peProvisioner.getAvailableMips(); double availableMips = peProvisioner.getAvailableMips();
for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) { for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
String vmUid = entry.getKey(); String vmUid = entry.getKey();
getPeMap().put(vmUid, new LinkedList<Pe>());
for (double mips : entry.getValue()) { for (double mips : entry.getValue()) {
if (availableMips >= mips) { while (mips >= 0.1) {
peProvisioner.allocateMipsForVm(vmUid, mips); if (availableMips >= mips) {
availableMips -= mips; peProvisioner.allocateMipsForVm(vmUid, mips);
} else { getPeMap().get(vmUid).add(pe);
while (mips >= 0) { availableMips -= mips;
break;
} else {
peProvisioner.allocateMipsForVm(vmUid, availableMips); peProvisioner.allocateMipsForVm(vmUid, availableMips);
getPeMap().get(vmUid).add(pe);
mips -= availableMips; mips -= availableMips;
if (mips <= 0.1) { if (mips <= 0.1) {
mips = 0;
break; break;
} }
if (!peIterator.hasNext()) { if (!peIterator.hasNext()) {
Log.printLine("There is no enough MIPS (" + mips + ") to accommodate VM " + vmUid); Log.printLine("There is no enough MIPS (" + mips + ") to accommodate VM " + vmUid);
System.exit(0);
} }
pe = peIterator.next(); pe = peIterator.next();
peProvisioner = pe.getPeProvisioner(); peProvisioner = pe.getPeProvisioner();
peProvisioner.deallocateMipsForAllVms();
availableMips = peProvisioner.getAvailableMips(); availableMips = peProvisioner.getAvailableMips();
} }
} }
......
...@@ -20,6 +20,7 @@ import org.cloudbus.cloudsim.provisioners.PeProvisioner; ...@@ -20,6 +20,7 @@ import org.cloudbus.cloudsim.provisioners.PeProvisioner;
*/ */
public class PowerPe extends Pe { public class PowerPe extends Pe {
// TODO: move power model to PowerHost
/** The power model. */ /** The power model. */
private PowerModel powerModel; private PowerModel powerModel;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment