Commit 2bac5f52 authored by Anton Beloglazov's avatar Anton Beloglazov

- Minor updates to VmSchedulerSpaceShared

parent e6cbe43b
...@@ -22,7 +22,6 @@ import java.util.Map; ...@@ -22,7 +22,6 @@ import java.util.Map;
* This policy ignores requested number of MIPS. * This policy ignores requested number of MIPS.
* *
* @author Rodrigo N. Calheiros * @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 1.0
*/ */
public class VmSchedulerOportunisticSpaceShared extends VmScheduler { public class VmSchedulerOportunisticSpaceShared extends VmScheduler {
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
package org.cloudbus.cloudsim; package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
/** /**
* VmSchedulerSpaceShared is a VMM allocation policy that * VmSchedulerSpaceShared is a VMM allocation policy that
...@@ -26,77 +26,125 @@ import java.util.Vector; ...@@ -26,77 +26,125 @@ import java.util.Vector;
*/ */
public class VmSchedulerSpaceShared extends VmScheduler { public class VmSchedulerSpaceShared extends VmScheduler {
//Map containing VM ID and a vector of PEs allocated to this VM /** Map containing VM ID and a vector of PEs allocated to this VM. */
protected Map<String,Vector<Integer>> peAllocationMap; private Map<String, List<Integer>> peAllocationMap;
protected Vector<Integer> freePesVector;
/** The free pes vector. */
private List<Integer> freePes;
/**
* Instantiates a new vm scheduler space shared.
*
* @param pelist the pelist
*/
public VmSchedulerSpaceShared(List<? extends Pe> pelist) { public VmSchedulerSpaceShared(List<? extends Pe> pelist) {
super(pelist); super(pelist);
setPeAllocationMap(new HashMap<String, List<Integer>>());
this.peAllocationMap = new HashMap<String,Vector<Integer>>(); setFreePes(new ArrayList<Integer>());
for (int i = 0; i < pelist.size(); i++) {
freePesVector = new Vector<Integer>(); getFreePes().add(i);
for (int i=0;i<pelist.size();i++){
freePesVector.add(i);
} }
} }
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmScheduler#allocatePesForVm(org.cloudbus.cloudsim.Vm, java.util.List)
*/
/**
* TODO: rewrite using PeProvisioner
*/
@Override @Override
public boolean allocatePesForVm(Vm vm, List<Double> mipsShare) { public boolean allocatePesForVm(Vm vm, List<Double> mipsShare) {
//if there is no enough free PEs, fails //if there is no enough free PEs, fails
if (freePesVector.size() < mipsShare.size()) { if (getFreePes().size() < mipsShare.size()) {
return false; return false;
} }
double currentFreeMips = getAvailableMips(); double currentFreeMips = getAvailableMips();
Vector<Integer> chosenPEs = new Vector<Integer>(); List<Integer> chosenPes = new ArrayList<Integer>();
List<Double> newMipsList = new LinkedList<Double>(); List<Double> newMipsList = new LinkedList<Double>();
for(int i=0;i<mipsShare.size();i++){ for (int i = 0; i < mipsShare.size(); i++) {
int allocatedPe = freePesVector.remove(0); int allocatedPe = getFreePes().remove(0);
chosenPEs.add(allocatedPe); chosenPes.add(allocatedPe);
//add the smaller between requested MIPS and available MIPS: if PE supplied more capacity than requested, //add the smaller between requested MIPS and available MIPS: if PE supplied more capacity than requested,
//we reduce use of processor (and power consumption). Otherwise, we go PE's full power. //we reduce use of processor (and power consumption). Otherwise, we go PE's full power.
if(getPeList().get(allocatedPe).getMips() < mipsShare.get(i)){ if (getPeList().get(allocatedPe).getMips() < mipsShare.get(i)) {
newMipsList.add((double)getPeList().get(allocatedPe).getMips()); newMipsList.add((double) getPeList().get(allocatedPe).getMips());
currentFreeMips-=getPeList().get(allocatedPe).getMips(); currentFreeMips -= getPeList().get(allocatedPe).getMips();
} else { } else {
newMipsList.add(mipsShare.get(i)); newMipsList.add(mipsShare.get(i));
currentFreeMips-=mipsShare.get(i); currentFreeMips -= mipsShare.get(i);
} }
} }
peAllocationMap.put(vm.getUid(),chosenPEs); getPeAllocationMap().put(vm.getUid(), chosenPes);
getMipsMap().put(vm.getUid(),newMipsList); getMipsMap().put(vm.getUid(), newMipsList);
setAvailableMips(currentFreeMips); setAvailableMips(currentFreeMips);
return true; return true;
} }
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmScheduler#deallocatePesForVm(org.cloudbus.cloudsim.Vm)
*/
@Override @Override
public void deallocatePesForVm(Vm vm) { public void deallocatePesForVm(Vm vm) {
// free Pes
List<Integer> peVector = getPeAllocationMap().remove(vm.getUid());
//free Pes if (peVector == null) {
Vector<Integer> peVector = peAllocationMap.remove(vm.getUid()); Log.printLine(this.getClass() + ":[Error]: no Pes allocated for this VM.");
if(peVector==null){
Log.printLine(this.getClass()+":[Error]: no Pes allocated for this VM.");
return; return;
} }
while(!peVector.isEmpty()){ while (!peVector.isEmpty()) {
Integer element = peVector.remove(0); Integer element = peVector.remove(0);
freePesVector.add(element); getFreePes().add(element);
} }
//update use of mips // update use of mips
double currentMips=getAvailableMips(); double currentMips = getAvailableMips();
for (double mips: getMipsMap().get(vm.getUid())) { for (double mips : getMipsMap().get(vm.getUid())) {
currentMips+=mips; currentMips += mips;
} }
setAvailableMips(currentMips); setAvailableMips(currentMips);
} }
/**
* Sets the pe allocation map.
*
* @param peAllocationMap the pe allocation map
*/
protected void setPeAllocationMap(Map<String, List<Integer>> peAllocationMap) {
this.peAllocationMap = peAllocationMap;
}
/**
* Gets the pe allocation map.
*
* @return the pe allocation map
*/
protected Map<String, List<Integer>> getPeAllocationMap() {
return peAllocationMap;
}
/**
* Sets the free pes vector.
*
* @param freePes the new free pes vector
*/
protected void setFreePes(List<Integer> freePes) {
this.freePes = freePes;
}
/**
* Gets the free pes vector.
*
* @return the free pes vector
*/
protected List<Integer> getFreePes() {
return freePes;
}
} }
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