Commit 189e9254 authored by Ahmad Siavashi's avatar Ahmad Siavashi

finished. untested yet

parent bfeda768
...@@ -143,25 +143,22 @@ public abstract class VgpuScheduler { ...@@ -143,25 +143,22 @@ public abstract class VgpuScheduler {
} }
/** /**
* Returns pGPUs allocated memories in ascending order. * Returns the available memory for all on-board pGPUs.
*/ */
public Map<Pgpu, Integer> getPgpusAllocatedMemory() { public Map<Pgpu, Integer> getPgpusAvailableMemory() {
Map<Pgpu, Integer> pgpusAllocatedMemory = new HashMap<>(); Map<Pgpu, Integer> pgpusAvailableMemory = new HashMap<>();
for (Pgpu pgpu : getPgpuList()) { for (Pgpu pgpu : getPgpuList()) {
Integer allocatedMemory = 0; Integer availableMemory = pgpu.getGddramProvisioner().getAvailableGddram();
for (Vgpu vgpu : getPgpuVgpuMap().get(pgpu)) { pgpusAvailableMemory.put(pgpu, availableMemory);
allocatedMemory += vgpu.getGddram();
} }
pgpusAllocatedMemory.put(pgpu, allocatedMemory); return pgpusAvailableMemory;
}
return pgpusAllocatedMemory;
} }
/** /**
* Returns maximum free memory on GPUs. Assuming all on-board GPUs are the same. * Returns maximum free memory on GPUs. Assuming all on-board GPUs are the same.
*/ */
public int getMaxFreeMemory() { public int getMaxFreeMemory() {
Integer minAllocatedMemory = Collections.min(getPgpusAllocatedMemory().values()); Integer minAllocatedMemory = Collections.min(getPgpusAvailableMemory().values());
int maxFreeMemory = getPgpuList().get(0).getGddramProvisioner().getGddram() - minAllocatedMemory; int maxFreeMemory = getPgpuList().get(0).getGddramProvisioner().getGddram() - minAllocatedMemory;
return maxFreeMemory; return maxFreeMemory;
} }
......
...@@ -35,13 +35,13 @@ public abstract class VideoCardAllocationPolicy { ...@@ -35,13 +35,13 @@ public abstract class VideoCardAllocationPolicy {
/** /**
* Return allocated memory of every video card's least loaded GPU. * Return allocated memory of every video card's least loaded GPU.
*/ */
public Map<VideoCard, Integer> getVideoCardsAllocatedMemory(){ public Map<VideoCard, Integer> getVideoCardsAvailableMemory(){
Map<VideoCard, Integer> videoCardsAllocatedMemory = new HashMap<>(); Map<VideoCard, Integer> videoCardsAvailableMemory = new HashMap<>();
for(VideoCard videoCard : getVideoCards()) { for(VideoCard videoCard : getVideoCards()) {
Integer allocatedMemoryPgpu = Collections.min(videoCard.getVgpuScheduler().getPgpusAllocatedMemory().values()); Integer pgpuAvailableMemory = Collections.min(videoCard.getVgpuScheduler().getPgpusAvailableMemory().values());
videoCardsAllocatedMemory.put(videoCard, allocatedMemoryPgpu); videoCardsAvailableMemory.put(videoCard, pgpuAvailableMemory);
} }
return videoCardsAllocatedMemory; return videoCardsAvailableMemory;
} }
/** /**
......
...@@ -48,11 +48,11 @@ public class VideoCardAllocationPolicyLeastLoad extends VideoCardAllocationPolic ...@@ -48,11 +48,11 @@ public class VideoCardAllocationPolicyLeastLoad extends VideoCardAllocationPolic
VideoCard videoCard = Collections.min(candidates, new Comparator<VideoCard>() { VideoCard videoCard = Collections.min(candidates, new Comparator<VideoCard>() {
@Override @Override
public int compare(VideoCard videoCard1, VideoCard videoCard2) { public int compare(VideoCard videoCard1, VideoCard videoCard2) {
Integer minAllocatedMemoryVideoCard1 = Collections Integer videoCard1maxAvailableMemory = Collections
.min(videoCard1.getVgpuScheduler().getPgpusAllocatedMemory().values()); .max(videoCard1.getVgpuScheduler().getPgpusAvailableMemory().values());
Integer minAllocatedMemoryVideoCard2 = Collections Integer videoCard2maxAvailableMemory = Collections
.min(videoCard2.getVgpuScheduler().getPgpusAllocatedMemory().values()); .max(videoCard2.getVgpuScheduler().getPgpusAvailableMemory().values());
return Integer.compare(minAllocatedMemoryVideoCard1, minAllocatedMemoryVideoCard2); return Integer.compare(videoCard1maxAvailableMemory, videoCard2maxAvailableMemory);
} }
}); });
// Allocate the given vGPU on the selected video card // Allocate the given vGPU on the selected video card
......
...@@ -9,6 +9,7 @@ import org.cloudbus.cloudsim.Host; ...@@ -9,6 +9,7 @@ import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log; import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.gpu.GpuHost;
import org.cloudbus.cloudsim.gpu.GpuVm; import org.cloudbus.cloudsim.gpu.GpuVm;
import org.cloudbus.cloudsim.gpu.GpuVmAllocationPolicySimple; import org.cloudbus.cloudsim.gpu.GpuVmAllocationPolicySimple;
import org.cloudbus.cloudsim.gpu.Vgpu; import org.cloudbus.cloudsim.gpu.Vgpu;
...@@ -23,8 +24,8 @@ import org.cloudbus.cloudsim.gpu.power.PowerGpuHost; ...@@ -23,8 +24,8 @@ import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
*/ */
public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySimple { public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySimple {
private List<PowerGpuHost> gpuHosts; private List<GpuHost> gpuHostList;
private Map<Vgpu, RemoteGpuHost> remoteVgpuHosts; private Map<Vgpu, GpuHost> remoteVgpuHosts;
/** /**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU * This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
...@@ -35,7 +36,7 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -35,7 +36,7 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
public RemoteGpuVmAllocationPolicyFirstFit(List<? extends Host> list) { public RemoteGpuVmAllocationPolicyFirstFit(List<? extends Host> list) {
super(list); super(list);
setRemoteVgpuHosts(new HashMap<>()); setRemoteVgpuHosts(new HashMap<>());
setGpuHosts(new ArrayList<>()); setGpuHostList(new ArrayList<>());
updateGpuHosts(getHostList()); updateGpuHosts(getHostList());
} }
...@@ -56,6 +57,7 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -56,6 +57,7 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
+ ", 'host': " + host.getId() + "}"); + ", 'host': " + host.getId() + "}");
return true; return true;
} }
// else if it has a remote vGPU, then
if (allocateRemoteVgpu(vgpu)) { if (allocateRemoteVgpu(vgpu)) {
getVmTable().put(vm.getUid(), host); getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
...@@ -73,11 +75,14 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -73,11 +75,14 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
// Allocates a remote vGPU on a GPU-equipped host // Allocates a remote vGPU on a GPU-equipped host
protected boolean allocateRemoteVgpu(Vgpu vgpu) { protected boolean allocateRemoteVgpu(Vgpu vgpu) {
// if Vm has a remote Vgpu // if Vm has a remote Vgpu
for (PowerGpuHost gpuHost : getGpuHosts()) { for (GpuHost gpuHost : getGpuHostList()) {
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw()); boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
getRemoteVgpuHosts().put(vgpu, gpuHost);
if (isVgpuAllocated) { if (isVgpuAllocated) {
Log.formatLine("%.2f: Vgpu of VM #" + vgpu.getVm().getId() + " has been allocated to the host #" Log.formatLine("%.2f: Vgpu of VM #" + vgpu.getVm().getId() + " has been allocated to the host #"
+ gpuHost.getId(), CloudSim.clock()); + gpuHost.getId(), CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vgpu allocation', 'vm': "
+ vgpu.getVm().getId() + ", 'host': " + gpuHost.getId() + "}");
return true; return true;
} }
} }
...@@ -93,27 +98,38 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi ...@@ -93,27 +98,38 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
// Add GPU-equipped hosts // Add GPU-equipped hosts
protected void updateGpuHosts(List<PowerGpuHost> hosts) { protected void updateGpuHosts(List<PowerGpuHost> hosts) {
getGpuHosts().clear(); getGpuHostList().clear();
for (PowerGpuHost host : hosts) { for (PowerGpuHost host : hosts) {
if (host.getVideoCardAllocationPolicy() != null) { if (host.getVideoCardAllocationPolicy() != null) {
getGpuHosts().add(host); getGpuHostList().add(host);
} }
} }
} }
public List<PowerGpuHost> getGpuHosts() { @Override
return gpuHosts; public void deallocateHostForVm(Vm vm) {
super.deallocateHostForVm(vm);
Vgpu vgpu = ((GpuVm) vm).getVgpu();
if (vgpu == null || !isVgpuRemote(vgpu)) {
return;
}
getRemoteVgpuHosts().get(vgpu).getVideoCardAllocationPolicy().deallocate(vgpu);
getRemoteVgpuHosts().remove(vgpu);
}
public List<GpuHost> getGpuHostList() {
return gpuHostList;
} }
protected void setGpuHosts(List<PowerGpuHost> gpuHosts) { protected void setGpuHostList(List<GpuHost> gpuHosts) {
this.gpuHosts = gpuHosts; this.gpuHostList = gpuHosts;
} }
public Map<Vgpu, RemoteGpuHost> getRemoteVgpuHosts() { public Map<Vgpu, GpuHost> getRemoteVgpuHosts() {
return remoteVgpuHosts; return remoteVgpuHosts;
} }
protected void setRemoteVgpuHosts(Map<Vgpu, RemoteGpuHost> remoteVgpuHosts) { protected void setRemoteVgpuHosts(Map<Vgpu, GpuHost> remoteVgpuHosts) {
this.remoteVgpuHosts = remoteVgpuHosts; this.remoteVgpuHosts = remoteVgpuHosts;
} }
......
...@@ -37,44 +37,68 @@ public class RemoteGpuVmAllocationPolicyLeastLoad extends RemoteGpuVmAllocationP ...@@ -37,44 +37,68 @@ public class RemoteGpuVmAllocationPolicyLeastLoad extends RemoteGpuVmAllocationP
@Override @Override
public boolean allocateHostForVm(Vm vm) { public boolean allocateHostForVm(Vm vm) {
GpuVm gpuVm = (GpuVm) vm; Vgpu vgpu = ((GpuVm) vm).getVgpu();
if (gpuVm.getVgpu() != null) { if (vgpu == null) {
sortHosts(); for (Host host : getHostList()) {
boolean result = host.vmCreate(vm);
if (result) {
getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
return true;
} }
return super.allocateHostForVm(vm);
} }
} else {
@Override // Sort GPU-equipped hosts based on video cards' available memory in descending
public boolean allocateHostForVm(Vm vm, Host host) { // order.
GpuVm gpuVm = (GpuVm) vm; sortGpuHosts();
if (gpuVm.getVgpu() != null) { if (!isVgpuRemote(vgpu)) {
sortHosts(); for (Host host : getGpuHostList()) {
boolean result = host.vmCreate(vm);
if (result) {
getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': "
+ vm.getId() + ", 'host': " + host.getId() + "}");
return true;
} }
return super.allocateHostForVm(vm, host);
} }
return false;
protected void sortHosts() { } else {
Collections.sort(getHostList(), new Comparator<GpuHost>() { for (Host host : getGpuHostList()) {
@Override boolean result = host.vmCreate(vm);
public int compare(GpuHost arg0, GpuHost arg1) { if (result) {
// TODO result = allocateRemoteVgpu(vgpu);
return 0; if (result) {
getVmTable().put(vm.getUid(), host);
Log.formatLine(
"%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': "
+ vm.getId() + ", 'host': " + host.getId() + "}");
return true;
}
getRemoteVgpuHosts().get(vgpu).getVideoCardAllocationPolicy().deallocate(vgpu);
} }
}); }
}
}
return false;
} }
@Override protected void sortGpuHosts() {
protected boolean allocateRemoteVgpu(Vgpu vgpu) { Collections.sort(getGpuHostList(), Collections.reverseOrder(new Comparator<GpuHost>() {
Collections.sort(getGpuHosts(), new Comparator<PowerGpuHost>() { public int compare(GpuHost gpuHost1, GpuHost gpuHost2) {
public int compare(PowerGpuHost gpuHost1, PowerGpuHost gpuHost2) { Integer host1MaxAvailableMemory = Collections
Integer minAllocatedMemoryHost1 = Collections .max(gpuHost1.getVideoCardAllocationPolicy().getVideoCardsAvailableMemory().values());
.min(gpuHost1.getVideoCardAllocationPolicy().getVideoCardsAllocatedMemory().values()); Integer host2MaxAvailableMemory = Collections
Integer minAllocatedMemoryHost2 = Collections .max(gpuHost2.getVideoCardAllocationPolicy().getVideoCardsAvailableMemory().values());
.min(gpuHost2.getVideoCardAllocationPolicy().getVideoCardsAllocatedMemory().values()); return Integer.compare(host1MaxAvailableMemory, host2MaxAvailableMemory);
return Integer.compare(minAllocatedMemoryHost1, minAllocatedMemoryHost2);
}; };
}); }));
return super.allocateRemoteVgpu(vgpu);
} }
} }
/**
*
*/
package org.cloudbus.cloudsim.gpu.selection; package org.cloudbus.cloudsim.gpu.selection;
import java.util.Collections; import java.util.Collections;
...@@ -12,7 +9,7 @@ import org.cloudbus.cloudsim.gpu.VgpuScheduler; ...@@ -12,7 +9,7 @@ import org.cloudbus.cloudsim.gpu.VgpuScheduler;
/** /**
* {@link PgpuSelectionPolicyLeastLoad} implements {@link PgpuSelectionPolicy} * {@link PgpuSelectionPolicyLeastLoad} implements {@link PgpuSelectionPolicy}
* and selects the Pgpu with the least allocated memory. * and selects the Pgpu with the maximum available memory.
* *
* @author Ahmad Siavashi * @author Ahmad Siavashi
* *
...@@ -37,11 +34,9 @@ public class PgpuSelectionPolicyLeastLoad implements PgpuSelectionPolicy { ...@@ -37,11 +34,9 @@ public class PgpuSelectionPolicyLeastLoad implements PgpuSelectionPolicy {
return Collections.min(pgpuList, new Comparator<Pgpu>() { return Collections.min(pgpuList, new Comparator<Pgpu>() {
@Override @Override
public int compare(Pgpu pgpu1, Pgpu pgpu2) { public int compare(Pgpu pgpu1, Pgpu pgpu2) {
int pgpu1AllocatedMemory = pgpu1.getGddramProvisioner().getGddram() int pgpu1AvailableMemory = pgpu1.getGddramProvisioner().getAvailableGddram();
- pgpu1.getGddramProvisioner().getAvailableGddram(); int pgpu2AvailableMemory = pgpu2.getGddramProvisioner().getAvailableGddram();
int pgpu2AllocatedMemory = pgpu2.getGddramProvisioner().getGddram() return Integer.compare(pgpu1AvailableMemory, pgpu2AvailableMemory);
- 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