Commit e1e89aec authored by Ahmad Siavashi's avatar Ahmad Siavashi

vm allocation revised. not tested yet.

parent c5aee0a8
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>modules</artifactId>
......@@ -16,11 +18,30 @@
<artifactId>cloudsim</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.vandermeer</groupId>
<artifactId>asciitable</artifactId>
<version>0.3.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
</dependencies>
</project>
......@@ -221,8 +221,9 @@ public class GpuDatacenter extends Datacenter {
vm.updateVmProcessing(CloudSim.clock(),
getVmAllocationPolicy().getHost(vm).getVmScheduler().getAllocatedMipsForVm(vm));
GpuHost gpuHost = (GpuHost) getVmAllocationPolicy().getHost(vm);
if (vgpu != null) {
GpuVmAllocationPolicy gpuVmAllocationPolicy = (GpuVmAllocationPolicy) getVmAllocationPolicy();
GpuHost gpuHost = (GpuHost) gpuVmAllocationPolicy.getHost(vgpu);
vgpu.updateTaskProcessing(CloudSim.clock(), gpuHost.getVideoCardAllocationPolicy().getVgpuVideoCardMap()
.get(vgpu).getVgpuScheduler().getAllocatedMipsForVgpu(vgpu));
}
......
package org.cloudbus.cloudsim.gpu;
import java.util.HashMap;
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.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* {@link GpuVmAllocationPolicy} extends {@link VmAllocationPolicy} to support GPU-enabled VM placement.
*
* @author Ahmad Siavashi
*
*/
public abstract class GpuVmAllocationPolicy extends VmAllocationPolicy {
/**
* The map between each VM and its allocated host. The map key is a VM UID and
* the value is the allocated host for that VM.
*/
private Map<String, Host> vmTable;
/**
* @param list
*/
public GpuVmAllocationPolicy(List<? extends Host> list) {
super(list);
setVmTable(new HashMap<String, Host>());
}
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deallocateHostForVm(Vm vm) {
Host host = getVmTable().remove(vm.getUid());
if (host != null) {
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm deallocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
host.vmDestroy(vm);
}
}
public Host getHost(Vgpu vgpu) {
return getVmTable().get(vgpu.getVm().getUid());
}
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
/**
* @return the vmTable
*/
protected Map<String, Host> getVmTable() {
return vmTable;
}
/**
* @param vmTable
* the vmTable to set
*/
protected void setVmTable(Map<String, Host> vmTable) {
this.vmTable = vmTable;
}
}
......@@ -12,7 +12,7 @@ import org.cloudbus.cloudsim.lists.PeList;
* {@link GpuVmAllocationPolicyMaxMipsFirst} extends
* {@link GpuVmAllocationPolicySimple} to implement a VM placement algorithm.
* Initially, it sorts {@link GpuHost GpuHosts} based on their fastest
* {@link Pgpu GPU}, then employes first-fit algorithm to place VMs. sorts
* {@link Pgpu GPU}, then employs first-fit algorithm to place VMs. sorts
*
* @author Ahmad Siavashi
*
......
package org.cloudbus.cloudsim.gpu;
import java.util.HashMap;
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.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* {@link GpuVmAllocationPolicySimple} extends {@link VmAllocationPolicy} and
* {@link GpuVmAllocationPolicySimple} extends {@link GpuVmAllocationPolicy} and
* implements first-fit algorithm for VM placement.
*
* @author Ahmad Siavashi
*
*/
public class GpuVmAllocationPolicySimple extends VmAllocationPolicy {
/**
* The map between each VM and its allocated host. The map key is a VM UID and
* the value is the allocated host for that VM.
*/
private Map<String, Host> vmTable;
public class GpuVmAllocationPolicySimple extends GpuVmAllocationPolicy {
/**
* @param list
*/
public GpuVmAllocationPolicySimple(List<? extends Host> list) {
super(list);
setVmTable(new HashMap<String, Host>());
}
@Override
......@@ -61,46 +51,4 @@ public class GpuVmAllocationPolicySimple extends VmAllocationPolicy {
}
return false;
}
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deallocateHostForVm(Vm vm) {
Host host = getVmTable().remove(vm.getUid());
if (host != null) {
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm deallocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
host.vmDestroy(vm);
}
}
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
/**
* @return the vmTable
*/
protected Map<String, Host> getVmTable() {
return vmTable;
}
/**
* @param vmTable
* the vmTable to set
*/
protected void setVmTable(Map<String, Host> vmTable) {
this.vmTable = vmTable;
}
}
package org.cloudbus.cloudsim.gpu.remote;
import java.util.ArrayList;
import java.util.HashMap;
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.GpuVmAllocationPolicy;
import org.cloudbus.cloudsim.gpu.GpuVmAllocationPolicySimple;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
/**
* This class extends {@link GpuVmAllocationPolicy} to add support for GPU
* remoting.
*
* @author Ahmad Siavashi
*
*/
public abstract class RemoteGpuVmAllocationPolicy extends GpuVmAllocationPolicy{
private List<GpuHost> gpuHostList;
private Map<Vgpu, GpuHost> remoteVgpuHosts;
/**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
* remoting.
*
* @see {@link GpuVmAllocationPolicySimple}
*/
public RemoteGpuVmAllocationPolicy(List<? extends Host> list) {
super(list);
setRemoteVgpuHosts(new HashMap<>());
setGpuHostList(new ArrayList<>());
updateGpuHosts(getHostList());
}
// Allocates a remote vGPU on a GPU-equipped host
protected boolean allocateRemoteVgpu(Vgpu vgpu) {
// if Vm has a remote Vgpu
for (GpuHost gpuHost : getGpuHostList()) {
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
getRemoteVgpuHosts().put(vgpu, gpuHost);
if (isVgpuAllocated) {
Log.formatLine("%.2f: Vgpu of VM #" + vgpu.getVm().getId() + " has been allocated to the host #"
+ gpuHost.getId(), CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vgpu allocation', 'vm': "
+ vgpu.getVm().getId() + ", 'host': " + gpuHost.getId() + "}");
return true;
}
}
return false;
}
protected boolean isVgpuRemote(Vgpu vgpu) {
if (vgpu.getType() == RemoteVgpuTags.REMOTE_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.REMOTE_SHARED) {
return true;
}
return false;
}
// Add GPU-equipped hosts
protected void updateGpuHosts(List<PowerGpuHost> hosts) {
getGpuHostList().clear();
for (PowerGpuHost host : hosts) {
if (host.getVideoCardAllocationPolicy() != null) {
getGpuHostList().add(host);
}
}
}
@Override
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);
}
@Override
public Host getHost(Vgpu vgpu) {
if (isVgpuRemote(vgpu)) {
return getRemoteVgpuHosts().get(vgpu);
}else {
return super.getHost(vgpu);
}
}
public List<GpuHost> getGpuHostList() {
return gpuHostList;
}
protected void setGpuHostList(List<GpuHost> gpuHosts) {
this.gpuHostList = gpuHosts;
}
public Map<Vgpu, GpuHost> getRemoteVgpuHosts() {
return remoteVgpuHosts;
}
protected void setRemoteVgpuHosts(Map<Vgpu, GpuHost> remoteVgpuHosts) {
this.remoteVgpuHosts = remoteVgpuHosts;
}
}
package org.cloudbus.cloudsim.gpu.remote;
import java.util.ArrayList;
import java.util.HashMap;
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.GpuVmAllocationPolicySimple;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
/**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
* remoting.
* This class extends {@link RemoteGpuVmAllocationPolicy} and implements
* first-fit GPU host allocation.
*
* @author Ahmad Siavashi
*
*/
public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySimple {
private List<GpuHost> gpuHostList;
private Map<Vgpu, GpuHost> remoteVgpuHosts;
public class RemoteGpuVmAllocationPolicyFirstFit extends RemoteGpuVmAllocationPolicy {
/**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
* remoting.
* This class extends {@link RemoteGpuVmAllocationPolicy} and implements
* first-fit GPU host allocation.
*
* @see {@link GpuVmAllocationPolicySimple}
*/
public RemoteGpuVmAllocationPolicyFirstFit(List<? extends Host> list) {
super(list);
setRemoteVgpuHosts(new HashMap<>());
setGpuHostList(new ArrayList<>());
updateGpuHosts(getHostList());
}
@Override
......@@ -72,65 +61,16 @@ public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySi
return false;
}
// Allocates a remote vGPU on a GPU-equipped host
protected boolean allocateRemoteVgpu(Vgpu vgpu) {
// if Vm has a remote Vgpu
for (GpuHost gpuHost : getGpuHostList()) {
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
getRemoteVgpuHosts().put(vgpu, gpuHost);
if (isVgpuAllocated) {
Log.formatLine("%.2f: Vgpu of VM #" + vgpu.getVm().getId() + " has been allocated to the host #"
+ gpuHost.getId(), CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vgpu allocation', 'vm': "
+ vgpu.getVm().getId() + ", 'host': " + gpuHost.getId() + "}");
@Override
public boolean allocateHostForVm(Vm vm) {
if (!getVmTable().containsKey(vm.getUid())) {
for (Host host : getHostList()) {
boolean result = allocateHostForVm(vm, host);
if (result) {
return true;
}
}
return false;
}
protected boolean isVgpuRemote(Vgpu vgpu) {
if (vgpu.getType() == RemoteVgpuTags.REMOTE_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.REMOTE_SHARED) {
return true;
}
return false;
}
// Add GPU-equipped hosts
protected void updateGpuHosts(List<PowerGpuHost> hosts) {
getGpuHostList().clear();
for (PowerGpuHost host : hosts) {
if (host.getVideoCardAllocationPolicy() != null) {
getGpuHostList().add(host);
}
}
}
@Override
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 setGpuHostList(List<GpuHost> gpuHosts) {
this.gpuHostList = gpuHosts;
}
public Map<Vgpu, GpuHost> getRemoteVgpuHosts() {
return remoteVgpuHosts;
}
protected void setRemoteVgpuHosts(Map<Vgpu, GpuHost> remoteVgpuHosts) {
this.remoteVgpuHosts = remoteVgpuHosts;
}
}
......@@ -3,7 +3,6 @@ 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;
......@@ -12,7 +11,6 @@ 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
......
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