Commit 5c168e18 authored by Anton Beloglazov's avatar Anton Beloglazov

- Moved PowerModel from PowerPe to PowerHost

- Removed PowerPe and Power.PeList
parent d61e8d1d
......@@ -199,7 +199,11 @@ public class HostDynamicWorkload extends Host {
* @return current utilization of CPU in percents
*/
public double getUtilizationOfCpu() {
return getUtilizationMips() / getTotalMips();
double utilization = getUtilizationMips() / getTotalMips();
if (utilization > 1 && utilization < 1.01) {
utilization = 1;
}
return utilization;
}
/**
......
......@@ -13,7 +13,7 @@ import java.util.List;
import org.cloudbus.cloudsim.HostDynamicWorkload;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.power.lists.PowerPeList;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
......@@ -24,6 +24,9 @@ import org.cloudbus.cloudsim.provisioners.RamProvisioner;
* @since CloudSim Toolkit 2.0
*/
public class PowerHost extends HostDynamicWorkload {
/** The power model. */
private PowerModel powerModel;
/**
* Instantiates a new host.
......@@ -41,8 +44,10 @@ public class PowerHost extends HostDynamicWorkload {
BwProvisioner bwProvisioner,
long storage,
List<? extends Pe> peList,
VmScheduler vmScheduler) {
VmScheduler vmScheduler,
PowerModel powerModel) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
setPowerModel(powerModel);
}
/**
......@@ -51,16 +56,48 @@ public class PowerHost extends HostDynamicWorkload {
* @return the power
*/
public double getPower() {
return PowerPeList.getPower(this.<PowerPe>getPeList());
double power = 0;
try {
power = getPowerModel().getPower(getUtilizationOfCpu());
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return power;
}
/**
* Gets the maximum power. For this moment only consumed by all PEs.
* Gets the max power that can be consumed by the host.
*
* @return the power
* @return the max power
*/
public double getMaxPower() {
return PowerPeList.getMaxPower(this.<PowerPe>getPeList());
double power = 0;
try {
power = getPowerModel().getPower(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return power;
}
/**
* Sets the power model.
*
* @param powerModel the new power model
*/
protected void setPowerModel(PowerModel powerModel) {
this.powerModel = powerModel;
}
/**
* Gets the power model.
*
* @return the power model
*/
public PowerModel getPowerModel() {
return powerModel;
}
}
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.provisioners.PeProvisioner;
/**
* PowerPe class enables simulation of power-aware PEs.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerPe extends Pe {
// TODO: move power model to PowerHost
/** The power model. */
private PowerModel powerModel;
/**
* Instantiates a new PowerPe.
*
* @param id the id
* @param peProvisioner the PowerPe provisioner
* @param powerModel the power model
*/
public PowerPe(int id, PeProvisioner peProvisioner, PowerModel powerModel) {
super(id, peProvisioner);
setPowerModel(powerModel);
}
/**
* Sets the power model.
*
* @param powerModel the new power model
*/
protected void setPowerModel(PowerModel powerModel) {
this.powerModel = powerModel;
}
/**
* Gets the power model.
*
* @return the power model
*/
public PowerModel getPowerModel() {
return powerModel;
}
}
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.lists;
import java.util.List;
import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.power.PowerPe;
/**
* PowerPeList is a collection of operations on lists of Power-enabled PEs.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerPeList extends PeList {
/**
* Gets the power. For this moment only consumed by all PEs.
*
* @param peList the pe list
*
* @return the power
*/
public static <T extends PowerPe> double getPower(List<PowerPe> peList) {
double power = 0;
for (PowerPe pe : peList) {
try {
power += pe.getPowerModel().getPower(pe.getPeProvisioner().getUtilization());
} catch (Exception e) {
e.printStackTrace();
}
}
return power;
}
/**
* Gets the maximum power. For this moment only consumed by all PEs.
*
* @param peList the pe list
*
* @return the power
*/
public static <T extends PowerPe> double getMaxPower(List<PowerPe> peList) {
double power = 0;
for (PowerPe pe : peList) {
try {
power += pe.getPowerModel().getPower(1.0);
} catch (Exception e) {
e.printStackTrace();
}
}
return power;
}
}
......@@ -14,8 +14,6 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.power.PowerPe;
import org.cloudbus.cloudsim.power.models.PowerModelSqrt;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
......@@ -34,17 +32,14 @@ public class HostDynamicWorkloadTest {
private static final int BW = 10000;
private static final double MIPS = 1000;
private static final double MAX_POWER = 200;
private static final double STATIC_POWER_PERCENT = 0.3;
private HostDynamicWorkload host;
private List<Pe> peList;
@Before
public void setUp() throws Exception {
peList = new ArrayList<Pe>();
peList.add(new PowerPe(0, new PeProvisionerSimple(MIPS), new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT)));
peList.add(new PowerPe(1, new PeProvisionerSimple(MIPS), new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT)));
peList.add(new Pe(0, new PeProvisionerSimple(MIPS)));
peList.add(new Pe(1, new PeProvisionerSimple(MIPS)));
host = new HostDynamicWorkload (
ID,
......
......@@ -17,8 +17,6 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.power.PowerPe;
import org.cloudbus.cloudsim.power.models.PowerModelSqrt;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
......@@ -40,9 +38,6 @@ public class HostTest {
//private static final int PES_NUMBER = 2;
private static final double MAX_POWER = 200;
private static final double STATIC_POWER_PERCENT = 0.3;
//private static final double CLOUDLET_LENGTH = 1000;
//private static final long CLOUDLET_FILE_SIZE = 300;
//private static final long CLOUDLET_OUTPUT_SIZE = 300;
......@@ -53,8 +48,8 @@ public class HostTest {
@Before
public void setUp() throws Exception {
peList = new ArrayList<Pe>();
peList.add(new PowerPe(0, new PeProvisionerSimple(MIPS), new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT)));
peList.add(new PowerPe(1, new PeProvisionerSimple(MIPS), new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT)));
peList.add(new Pe(0, new PeProvisionerSimple(MIPS)));
peList.add(new Pe(1, new PeProvisionerSimple(MIPS)));
host = new Host(
ID,
......
......@@ -8,26 +8,32 @@
package org.cloudbus.cloudsim.power;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertEquals;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelSqrt;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.junit.Test;
/**
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PeTest {
public class PowerHostTest {
private static final double MIPS = 1000;
private static final double MAX_POWER = 200;
private static final double STATIC_POWER_PERCENT = 0.3;
@Test
public void testGetPowerModel() {
PowerPe powerPe = new PowerPe(0, null, null);
assertNull(powerPe.getPowerModel());
PowerModel powerModel = new PowerModelSqrt(0, 0);
powerPe.setPowerModel(powerModel);
assertSame(powerModel, powerPe.getPowerModel());
public void testGetMaxPower() {
List<Pe> peList = new ArrayList<Pe>();
peList.add(new Pe(0, new PeProvisionerSimple(MIPS)));
PowerHost host = new PowerHost(0, null, null, 0, peList, null, new PowerModelLinear(MAX_POWER, STATIC_POWER_PERCENT));
assertEquals(MAX_POWER, host.getMaxPower(), 0);
}
}
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.lists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.power.PowerPe;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelSqrt;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.junit.Before;
import org.junit.Test;
/**
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PeListTest {
private static final double MIPS = 1000;
private static final double MAX_POWER = 200;
private static final double STATIC_POWER_PERCENT = 0.3;
private List<PowerPe> peList;
private PowerModel powerModel0;
private PowerModel powerModel1;
@Before
public void setUp() throws Exception {
peList = new ArrayList<PowerPe>();
powerModel0 = new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT);
powerModel1 = new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT);
peList.add(new PowerPe(0, new PeProvisionerSimple(MIPS), powerModel0));
peList.add(new PowerPe(1, new PeProvisionerSimple(MIPS), powerModel1));
}
@Test
public void testGetPower() throws Exception {
Vm vm0 = new Vm(0, 0, MIPS / 2, 1, 0, 0, 0, "", null);
Vm vm1 = new Vm(1, 0, MIPS / 2, 1, 0, 0, 0, "", null);
assertTrue(peList.get(0).getPeProvisioner().allocateMipsForVm(vm0, MIPS / 3));
assertTrue(peList.get(1).getPeProvisioner().allocateMipsForVm(vm1, MIPS / 5));
double expectedPower = powerModel0.getPower((MIPS / 3) / MIPS) + powerModel1.getPower((MIPS / 5) / MIPS);
assertEquals(expectedPower, PowerPeList.getPower(peList), 0);
}
}
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