[1593] | 1 | package experiments.e2dc2015.models.arm; |
---|
| 2 | |
---|
| 3 | import schedframe.resources.StandardResourceType; |
---|
| 4 | import schedframe.resources.computing.Node; |
---|
| 5 | import schedframe.resources.computing.Processor; |
---|
| 6 | import schedframe.resources.computing.coolemall.NodeGroup; |
---|
| 7 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
| 8 | import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName; |
---|
| 9 | import schedframe.resources.devices.Device; |
---|
| 10 | import schedframe.resources.devices.Fan; |
---|
| 11 | import schedframe.resources.devices.PhysicalResource; |
---|
| 12 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 13 | import simulator.DataCenterWorkloadSimulator; |
---|
| 14 | import eduni.simjava.Sim_system; |
---|
| 15 | import example.energy.BaseEnergyEstimationPlugin; |
---|
| 16 | import experiments.e2dc2015.EnvironmentConditions; |
---|
| 17 | import gridsim.dcworms.DCWormsTags; |
---|
| 18 | |
---|
| 19 | public class CpuEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | private double timestamp = 0; |
---|
| 23 | private double old_temperature = EnvironmentConditions.arm_cpuTidle; |
---|
| 24 | private double new_temperature = -1; |
---|
| 25 | private double objective_temperature = EnvironmentConditions.arm_cpuTidle; |
---|
| 26 | |
---|
| 27 | private boolean fan = false; |
---|
| 28 | |
---|
| 29 | private double next_timer = -1; |
---|
| 30 | |
---|
| 31 | private int cpu_temp_monitor = 0; |
---|
| 32 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
| 33 | PhysicalResource resource) { |
---|
| 34 | /*double powerConsumption = 0; |
---|
| 35 | |
---|
| 36 | Processor cpu = (Processor)resource; |
---|
| 37 | powerConsumption = Pidle + (Pfull- Pidle) * cpu.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
| 38 | |
---|
| 39 | return powerConsumption;*/ |
---|
| 40 | |
---|
| 41 | double processorLoad = 0; |
---|
| 42 | double powerConsumption = 0; |
---|
| 43 | Processor proc = (Processor)resource; |
---|
| 44 | if(resource.getPowerInterface().getPowerState().equals(StandardPowerStateName.OFF)) |
---|
| 45 | return 0; |
---|
| 46 | else { |
---|
| 47 | processorLoad = proc.getLoadInterface().getRecentUtilization().getValue(); |
---|
| 48 | double lowestLoadLevel = 100; |
---|
| 49 | double highestLoadLevel = 0; |
---|
| 50 | if(proc.getPowerInterface().getPState().getLoadPowerUsage().containsKey(new Double(processorLoad))){ |
---|
| 51 | powerConsumption = proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(processorLoad)); |
---|
| 52 | } else { |
---|
| 53 | for(Double load: proc.getPowerInterface().getPState().getLoadPowerUsage().keySet()){ |
---|
| 54 | if(lowestLoadLevel > load){ |
---|
| 55 | lowestLoadLevel = load; |
---|
| 56 | } |
---|
| 57 | if(highestLoadLevel < load){ |
---|
| 58 | highestLoadLevel = load; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | if(processorLoad == 0){ |
---|
| 62 | try{ |
---|
| 63 | powerConsumption = proc.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage(); |
---|
| 64 | } catch (Exception e){ |
---|
| 65 | powerConsumption = 0.7 * proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(highestLoadLevel)); |
---|
| 66 | } |
---|
| 67 | } else { |
---|
| 68 | |
---|
| 69 | double lowerLoadLevel = lowestLoadLevel; |
---|
| 70 | double higherLoadLevel = highestLoadLevel; |
---|
| 71 | |
---|
| 72 | try{ |
---|
| 73 | |
---|
| 74 | for(Double load: proc.getPowerInterface().getPState().getLoadPowerUsage().keySet()){ |
---|
| 75 | if(processorLoad > load){ |
---|
| 76 | lowerLoadLevel = load; |
---|
| 77 | } |
---|
| 78 | else if(processorLoad < load){ |
---|
| 79 | higherLoadLevel = load; |
---|
| 80 | break; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | double powerBelow; |
---|
| 84 | double powerAbove; |
---|
| 85 | double a; |
---|
| 86 | double b; |
---|
| 87 | if(lowerLoadLevel != higherLoadLevel) { |
---|
| 88 | powerBelow = proc.getPowerInterface().getPState().getLoadPowerUsage().get(lowerLoadLevel); |
---|
| 89 | powerAbove = proc.getPowerInterface().getPState().getLoadPowerUsage().get(higherLoadLevel); |
---|
| 90 | a = (powerAbove - powerBelow)/(higherLoadLevel - lowerLoadLevel); |
---|
| 91 | b = powerAbove - a * higherLoadLevel; |
---|
| 92 | } else { |
---|
| 93 | powerBelow = proc.getPowerInterface().getPState().getLoadPowerUsage().get(lowestLoadLevel); |
---|
| 94 | powerAbove = proc.getPowerInterface().getPState().getLoadPowerUsage().get(highestLoadLevel); |
---|
| 95 | a = (powerAbove - powerBelow)/(highestLoadLevel - lowestLoadLevel); |
---|
| 96 | b = powerAbove - a * highestLoadLevel; |
---|
| 97 | } |
---|
| 98 | powerConsumption = a * processorLoad + b; |
---|
| 99 | } catch (Exception e){ |
---|
| 100 | powerConsumption = 0.7 * proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(highestLoadLevel)); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | return powerConsumption; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | @Override |
---|
| 109 | public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
| 110 | double future = -1; |
---|
| 111 | |
---|
| 112 | Processor cpu = (Processor) resource; |
---|
| 113 | |
---|
| 114 | double R = 0; |
---|
| 115 | double Rb = 0; |
---|
| 116 | double Rcv = 0; |
---|
| 117 | try{ |
---|
| 118 | Rb = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); |
---|
| 119 | } catch (Exception e){ |
---|
| 120 | // |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | double k = 0; |
---|
| 124 | try{ |
---|
| 125 | k = Double.valueOf(cpu.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue(); |
---|
| 126 | } catch (Exception e){ |
---|
| 127 | // |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | double a = 0; |
---|
| 131 | try{ |
---|
| 132 | a = Double.valueOf(cpu.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue(); |
---|
| 133 | } catch (Exception e){ |
---|
| 134 | a = 1; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | double V = 0; |
---|
| 138 | |
---|
| 139 | //System.out.println("------ " + cpu.getFullName()); |
---|
| 140 | for(Device device: cpu.getParent().getParent().getResourceCharacteristic().getDevices()){ |
---|
| 141 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
| 142 | int fanId = Integer.valueOf(device.getName().split("_")[1]).intValue(); |
---|
| 143 | int nodeId = Integer.valueOf(cpu.getParent().getName().split("_")[1]).intValue(); |
---|
| 144 | //System.out.println(device.getName() + "; " + cpu.getParent().getName()); |
---|
| 145 | //System.out.println(fanId + "; " + nodeId); |
---|
| 146 | if(nodeId == fanId /*|| Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1]) - EnvironmentConditions.NODES_IN_A_ROW*/){ |
---|
| 147 | Fan fan = (Fan) device; |
---|
| 148 | V = fan.getAirflowInterface().getRecentAirflow().getValue(); |
---|
| 149 | break; |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | //System.out.println("V: " + V); |
---|
| 154 | Rcv = 1/ (k * Math.pow(V, a)); |
---|
| 155 | R = Rb + Rcv; |
---|
| 156 | double C = 0; |
---|
| 157 | try{ |
---|
| 158 | C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); |
---|
| 159 | } catch (Exception e){ |
---|
| 160 | // |
---|
| 161 | } |
---|
| 162 | // 1) look where we are |
---|
| 163 | double delta_t = Sim_system.clock() - timestamp; |
---|
| 164 | /***************model1*************/ |
---|
| 165 | //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/sink); |
---|
| 166 | |
---|
| 167 | /***************model2*************/ |
---|
| 168 | //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | // 2) calculate if fan is needed ? |
---|
| 172 | if(new_temperature <= EnvironmentConditions.TFanLow) { |
---|
| 173 | fan = false; |
---|
| 174 | } |
---|
| 175 | if(new_temperature >= EnvironmentConditions.TFanHigh) { |
---|
| 176 | fan = true; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | // 3) compute new objective |
---|
| 180 | double Tin = EnvironmentConditions.ROOM_TEMPERATURE; |
---|
| 181 | double Pcpu = cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 182 | new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
| 183 | //new_temperature = (Pcpu * R + Tin) - (Pcpu * R + Tin - Tidle) * Math.exp(-Sim_system.clock()/(R * C));; |
---|
| 184 | |
---|
| 185 | //System.out.println("getting inlet...: "); |
---|
| 186 | NodeGroup ng = (NodeGroup) cpu.getParent().getParent(); |
---|
| 187 | for(Node n: ng.getNodes()){ |
---|
| 188 | int cpuNodeId = Integer.valueOf(cpu.getParent().getName().split("_")[1]).intValue(); |
---|
| 189 | int nodeId = Integer.valueOf(n.getName().split("_")[1]).intValue(); |
---|
| 190 | //System.out.println(cpuNodeId + "; " + nodeId); |
---|
| 191 | if(nodeId - cpuNodeId == 9){ |
---|
| 192 | if(n.getThermalInterface().getRecentTemperature().getValue() == 0){ |
---|
| 193 | Tin = EnvironmentConditions.arm_nodeTidle; |
---|
| 194 | } else |
---|
| 195 | Tin = n.getThermalInterface().getRecentTemperature().getValue(); |
---|
| 196 | //System.out.println("======" + cpu.getFullName() + " previous node: " + n.getFullName() + "; " + Tin); |
---|
| 197 | break; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | if(cpu.getThermalInterface().getRecentTemperature().getValue() == 0) |
---|
| 201 | Tin = (2 * Tin + EnvironmentConditions.arm_cpuTidle)/3; |
---|
| 202 | else |
---|
| 203 | Tin = (2 * Tin + 4*cpu.getThermalInterface().getRecentTemperature().getValue())/6; |
---|
| 204 | /***************model1 - GEO1*************/ |
---|
| 205 | //double cpuLoad = cpu.getLoadInterface().getRecentUtilization().getValue(); |
---|
| 206 | //double targetTemp = Tidle + cpuLoad/100 * dTfull; |
---|
| 207 | //if(fan) { |
---|
| 208 | // targetTemp = targetTemp - dTfan; |
---|
| 209 | //} |
---|
| 210 | System.out.println(new_temperature + "; " + objective_temperature + "; " + Tin + "; " + Pcpu + "; " + R); |
---|
| 211 | |
---|
| 212 | /***************model2 - GEO2*************/ |
---|
| 213 | //Node node = (Node) cpu.getParent(); |
---|
| 214 | //Pserv = node.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 215 | //double targetTemp = Pcpu * R + Tin; |
---|
| 216 | |
---|
| 217 | /***************model3 - GEO1 + GEO2*************/ |
---|
| 218 | /*double targetTemp = Pcpu * R + Tin; |
---|
| 219 | if(fan) { |
---|
| 220 | targetTemp = targetTemp - dTfan; |
---|
| 221 | }*/ |
---|
| 222 | |
---|
| 223 | /***************model4 - WP*************/ |
---|
| 224 | double targetTemp = Pcpu * R + Tin; |
---|
| 225 | //System.out.println("----------" + targetTemp + ": " + Pcpu + ": " + R + ": " + Tin); |
---|
| 226 | // 4) check if we will need to tune fans |
---|
| 227 | if(fan && targetTemp < EnvironmentConditions.TFanLow) { |
---|
| 228 | double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow)); |
---|
| 229 | if(future == -1 || future > timer) { |
---|
| 230 | future = timer; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | if(!fan && targetTemp > EnvironmentConditions.TFanHigh) { |
---|
| 234 | double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanHigh)); |
---|
| 235 | if(future == -1 || future > timer) { |
---|
| 236 | future = timer; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | // 5) save everything |
---|
| 241 | timestamp = Sim_system.clock(); |
---|
| 242 | old_temperature = new_temperature; |
---|
| 243 | objective_temperature = targetTemp; |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | if((future >= 0) && ((next_timer < Sim_system.clock()) || (next_timer >= future + Sim_system.clock()))) { |
---|
| 247 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(future, DCWormsTags.FANMGT, "Test"); |
---|
| 248 | next_timer = future + Sim_system.clock() - 0.01; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | if(Sim_system.clock() == 0) |
---|
| 252 | return new_temperature; |
---|
| 253 | if(new_temperature < EnvironmentConditions.tempLevelMedium2Low){ |
---|
| 254 | if(cpu_temp_monitor != 1){ |
---|
| 255 | cpu_temp_monitor = 1; |
---|
| 256 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 257 | } |
---|
| 258 | } else if(new_temperature > EnvironmentConditions.tempLevelMedium2Low && new_temperature < EnvironmentConditions.tempLevelLow2Medium){ |
---|
| 259 | if(cpu_temp_monitor != 2){ |
---|
| 260 | cpu_temp_monitor = 2; |
---|
| 261 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 262 | } |
---|
| 263 | } else if(new_temperature > EnvironmentConditions.tempLevelLow2Medium && new_temperature < EnvironmentConditions.tempLevelHigh2Medium){ |
---|
| 264 | if(cpu_temp_monitor != 3){ |
---|
| 265 | cpu_temp_monitor = 3; |
---|
| 266 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 267 | } |
---|
| 268 | } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Medium && new_temperature < EnvironmentConditions.tempLevelMedium2High){ |
---|
| 269 | if(cpu_temp_monitor != 4){ |
---|
| 270 | cpu_temp_monitor = 4; |
---|
| 271 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 272 | } |
---|
| 273 | } else if(new_temperature > EnvironmentConditions.tempLevelMedium2High && new_temperature < EnvironmentConditions.tempLevelMax2High){ |
---|
| 274 | if(cpu_temp_monitor != 5){ |
---|
| 275 | cpu_temp_monitor = 5; |
---|
| 276 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 277 | } |
---|
| 278 | } else if(new_temperature > EnvironmentConditions.tempLevelMax2High && new_temperature < EnvironmentConditions.tempLevelHigh2Max){ |
---|
| 279 | if(cpu_temp_monitor != 6){ |
---|
| 280 | cpu_temp_monitor = 6; |
---|
| 281 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 282 | } |
---|
| 283 | } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Max){ |
---|
| 284 | if(cpu_temp_monitor != 7){ |
---|
| 285 | cpu_temp_monitor = 7; |
---|
| 286 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 290 | //System.out.println("cpu temp:" + new_temperature); |
---|
| 291 | return new_temperature; |
---|
| 292 | } |
---|
| 293 | } |
---|