Commit bfeda768 authored by Ahmad Siavashi's avatar Ahmad Siavashi

LeastLoad VM allocation not completed. FirstFit need remote vGPU deallocation

parent a873dea4
package org.cloudbus.cloudsim.gpu; package org.cloudbus.cloudsim.gpu;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -101,9 +102,9 @@ public abstract class VgpuScheduler { ...@@ -101,9 +102,9 @@ public abstract class VgpuScheduler {
public abstract void deallocatePgpuForVgpu(Vgpu vgpu); public abstract void deallocatePgpuForVgpu(Vgpu vgpu);
/** /**
* Releases PEs allocated to all the Vgpus of the video card the VgpuScheduler is * Releases PEs allocated to all the Vgpus of the video card the VgpuScheduler
* associated to. After that, all PEs will be available to be used on demand for * is associated to. After that, all PEs will be available to be used on demand
* requesting Vgpus. * for requesting Vgpus.
*/ */
public void deallocatePgpusForAllVgpus() { public void deallocatePgpusForAllVgpus() {
getMipsMap().clear(); getMipsMap().clear();
...@@ -141,6 +142,31 @@ public abstract class VgpuScheduler { ...@@ -141,6 +142,31 @@ public abstract class VgpuScheduler {
return getMipsMap().get(vgpu); return getMipsMap().get(vgpu);
} }
/**
* Returns pGPUs allocated memories in ascending order.
*/
public Map<Pgpu, Integer> getPgpusAllocatedMemory() {
Map<Pgpu, Integer> pgpusAllocatedMemory = new HashMap<>();
for (Pgpu pgpu : getPgpuList()) {
Integer allocatedMemory = 0;
for (Vgpu vgpu : getPgpuVgpuMap().get(pgpu)) {
allocatedMemory += vgpu.getGddram();
}
pgpusAllocatedMemory.put(pgpu, allocatedMemory);
}
return pgpusAllocatedMemory;
}
/**
* Returns maximum free memory on GPUs. Assuming all on-board GPUs are the same.
*/
public int getMaxFreeMemory() {
Integer minAllocatedMemory = Collections.min(getPgpusAllocatedMemory().values());
int maxFreeMemory = getPgpuList().get(0).getGddramProvisioner().getGddram() - minAllocatedMemory;
return maxFreeMemory;
}
/** /**
* Gets the total allocated MIPS for a Vgpu along all its allocated PEs. * Gets the total allocated MIPS for a Vgpu along all its allocated PEs.
* *
...@@ -187,7 +213,9 @@ public abstract class VgpuScheduler { ...@@ -187,7 +213,9 @@ public abstract class VgpuScheduler {
/** /**
* Returns the Pgpu allocated to the given Vgpu. * Returns the Pgpu allocated to the given Vgpu.
* @param vgpu the vgpu *
* @param vgpu
* the vgpu
* @return the pgpu allocated to the given vgpu * @return the pgpu allocated to the given vgpu
*/ */
public Pgpu getPgpuForVgpu(Vgpu vgpu) { public Pgpu getPgpuForVgpu(Vgpu vgpu) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.cloudbus.cloudsim.gpu.allocation; package org.cloudbus.cloudsim.gpu.allocation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -31,6 +32,18 @@ public abstract class VideoCardAllocationPolicy { ...@@ -31,6 +32,18 @@ public abstract class VideoCardAllocationPolicy {
setVideoCards(videoCards); setVideoCards(videoCards);
} }
/**
* Return allocated memory of every video card's least loaded GPU.
*/
public Map<VideoCard, Integer> getVideoCardsAllocatedMemory(){
Map<VideoCard, Integer> videoCardsAllocatedMemory = new HashMap<>();
for(VideoCard videoCard : getVideoCards()) {
Integer allocatedMemoryPgpu = Collections.min(videoCard.getVgpuScheduler().getPgpusAllocatedMemory().values());
videoCardsAllocatedMemory.put(videoCard, allocatedMemoryPgpu);
}
return videoCardsAllocatedMemory;
}
/** /**
* Allocate PCIe bandwidth to the vgpu * Allocate PCIe bandwidth to the vgpu
* *
......
...@@ -58,6 +58,13 @@ public class VideoCardAllocationPolicyDepthFirst extends VideoCardAllocationPoli ...@@ -58,6 +58,13 @@ public class VideoCardAllocationPolicyDepthFirst extends VideoCardAllocationPoli
} }
return result; return result;
} }
@Override
public boolean deallocate(Vgpu vgpu) {
VideoCard videoCard = getVgpuVideoCardMap().get(vgpu);
getVideoCardVgpuMap().get(videoCard).remove(vgpu);
return super.deallocate(vgpu);
}
/** /**
* @return the videoCardVgpuMap * @return the videoCardVgpuMap
......
package org.cloudbus.cloudsim.gpu.allocation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VideoCard;
/**
* Selects the video card with GPU with least allocated memory.
*
* @author Ahmad Siavashi
*
*/
public class VideoCardAllocationPolicyLeastLoad extends VideoCardAllocationPolicy {
private Map<VideoCard, List<Vgpu>> videoCardVgpuMap;
/**
* Selects the video card with GPU with least allocated memory.
*/
public VideoCardAllocationPolicyLeastLoad(List<? extends VideoCard> videoCards) {
super(videoCards);
setVideoCardVgpuMap(new HashMap<>());
for (VideoCard videoCard : getVideoCards()) {
getVideoCardVgpuMap().put(videoCard, new ArrayList<>());
}
}
@Override
public boolean allocate(Vgpu vgpu, int PCIeBw) {
List<VideoCard> candidates = new ArrayList<>();
// Collect candidates
for (VideoCard videoCard : getVideoCards()) {
if (videoCard.getVgpuScheduler().isSuitable(vgpu)) {
candidates.add(videoCard);
}
}
// If not suitable card was found then return false
if (candidates.size() == 0) {
return false;
}
// Find the one with the least allocated GPU memory
VideoCard videoCard = Collections.min(candidates, new Comparator<VideoCard>() {
@Override
public int compare(VideoCard videoCard1, VideoCard videoCard2) {
Integer minAllocatedMemoryVideoCard1 = Collections
.min(videoCard1.getVgpuScheduler().getPgpusAllocatedMemory().values());
Integer minAllocatedMemoryVideoCard2 = Collections
.min(videoCard2.getVgpuScheduler().getPgpusAllocatedMemory().values());
return Integer.compare(minAllocatedMemoryVideoCard1, minAllocatedMemoryVideoCard2);
}
});
// Allocate the given vGPU on the selected video card
videoCard.getVgpuScheduler().allocatePgpuForVgpu(vgpu, vgpu.getCurrentRequestedMips(),
vgpu.getCurrentRequestedGddram(), vgpu.getCurrentRequestedBw());
getVgpuVideoCardMap().put(vgpu, videoCard);
return true;
}
@Override
public boolean deallocate(Vgpu vgpu) {
VideoCard videoCard = getVgpuVideoCardMap().get(vgpu);
getVideoCardVgpuMap().get(videoCard).remove(vgpu);
return super.deallocate(vgpu);
}
public Map<VideoCard, List<Vgpu>> getVideoCardVgpuMap() {
return videoCardVgpuMap;
}
public void setVideoCardVgpuMap(Map<VideoCard, List<Vgpu>> videoCardVgpuMap) {
this.videoCardVgpuMap = videoCardVgpuMap;
};
}
...@@ -55,19 +55,14 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -55,19 +55,14 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId() Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}"); + ", 'host': " + host.getId() + "}");
return true; return true;
} }
// if Vm has a remote Vgpu if (allocateRemoteVgpu(vgpu)) {
for (PowerGpuHost gpuHost : getGpuHosts()) { getVmTable().put(vm.getUid(), host);
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw()); Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
if (isVgpuAllocated) { CloudSim.clock());
getVmTable().put(vm.getUid(), host); Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), + ", 'host': " + host.getId() + "}");
CloudSim.clock()); return true;
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
return true;
}
} }
// failed to find a remote GPU -> free allocated resources // failed to find a remote GPU -> free allocated resources
host.vmDestroy(vm); host.vmDestroy(vm);
...@@ -75,6 +70,20 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -75,6 +70,20 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
return false; return false;
} }
// Allocates a remote vGPU on a GPU-equipped host
protected boolean allocateRemoteVgpu(Vgpu vgpu) {
// if Vm has a remote Vgpu
for (PowerGpuHost gpuHost : getGpuHosts()) {
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
if (isVgpuAllocated) {
Log.formatLine("%.2f: Vgpu of VM #" + vgpu.getVm().getId() + " has been allocated to the host #"
+ gpuHost.getId(), CloudSim.clock());
return true;
}
}
return false;
}
protected boolean isVgpuRemote(Vgpu vgpu) { protected boolean isVgpuRemote(Vgpu vgpu) {
if (vgpu.getType() == RemoteVgpuTags.REMOTE_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.REMOTE_SHARED) { if (vgpu.getType() == RemoteVgpuTags.REMOTE_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.REMOTE_SHARED) {
return true; return true;
......
package org.cloudbus.cloudsim.gpu.remote;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.gpu.GpuHost;
import org.cloudbus.cloudsim.gpu.GpuVm;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
/**
* This class extends {@link RemoteGpuVmAllocationPolicyFirstFit} and allocates
* GPU-enabled VMs on GPU hosts with least loaded (i.t.o. allocated memory)
* pGPUs.
*
* @author Ahmad Siavashi
*
*/
public class RemoteGpuVmAllocationPolicyLeastLoad extends RemoteGpuVmAllocationPolicyFirstFit {
/**
* This class extends {@link RemoteGpuVmAllocationPolicyFirstFit} and allocates
* GPU-enabled VMs on GPU hosts with least loaded (i.t.o. allocated memory)
* pGPUs.
*
* @see {@link RemoteGpuVmAllocationPolicyLeastLoad}
*/
public RemoteGpuVmAllocationPolicyLeastLoad(List<? extends Host> list) {
super(list);
}
@Override
public boolean allocateHostForVm(Vm vm) {
GpuVm gpuVm = (GpuVm) vm;
if (gpuVm.getVgpu() != null) {
sortHosts();
}
return super.allocateHostForVm(vm);
}
@Override
public boolean allocateHostForVm(Vm vm, Host host) {
GpuVm gpuVm = (GpuVm) vm;
if (gpuVm.getVgpu() != null) {
sortHosts();
}
return super.allocateHostForVm(vm, host);
}
protected void sortHosts() {
Collections.sort(getHostList(), new Comparator<GpuHost>() {
@Override
public int compare(GpuHost arg0, GpuHost arg1) {
// TODO
return 0;
}
});
}
@Override
protected boolean allocateRemoteVgpu(Vgpu vgpu) {
Collections.sort(getGpuHosts(), new Comparator<PowerGpuHost>() {
public int compare(PowerGpuHost gpuHost1, PowerGpuHost gpuHost2) {
Integer minAllocatedMemoryHost1 = Collections
.min(gpuHost1.getVideoCardAllocationPolicy().getVideoCardsAllocatedMemory().values());
Integer minAllocatedMemoryHost2 = Collections
.min(gpuHost2.getVideoCardAllocationPolicy().getVideoCardsAllocatedMemory().values());
return Integer.compare(minAllocatedMemoryHost1, minAllocatedMemoryHost2);
};
});
return super.allocateRemoteVgpu(vgpu);
}
}
/**
*
*/
package org.cloudbus.cloudsim.gpu.selection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
/**
* {@link PgpuSelectionPolicyLeastLoad} implements {@link PgpuSelectionPolicy}
* and selects the Pgpu with the least allocated memory.
*
* @author Ahmad Siavashi
*
*/
public class PgpuSelectionPolicyLeastLoad implements PgpuSelectionPolicy {
public PgpuSelectionPolicyLeastLoad() {
super();
}
/*
* (non-Javadoc)
*
* @see org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy#selectPgpu(org.
* cloudbus.cloudsim.gpu.VgpuScheduler, java.util.List)
*/
@Override
public <T extends VgpuScheduler> Pgpu selectPgpu(T scheduler, List<? extends Pgpu> pgpuList) {
if (pgpuList.isEmpty()) {
return null;
}
return Collections.min(pgpuList, new Comparator<Pgpu>() {
@Override
public int compare(Pgpu pgpu1, Pgpu pgpu2) {
int pgpu1AllocatedMemory = pgpu1.getGddramProvisioner().getGddram()
- pgpu1.getGddramProvisioner().getAvailableGddram();
int pgpu2AllocatedMemory = pgpu2.getGddramProvisioner().getGddram()
- pgpu2.getGddramProvisioner().getAvailableGddram();
return Integer.compare(pgpu1AllocatedMemory, pgpu2AllocatedMemory);
}
});
}
}
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