[1500] | 1 | package experiments.simpat2014.models.recs; |
---|
[1469] | 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.devices.Device; |
---|
| 9 | import schedframe.resources.devices.Fan; |
---|
| 10 | import schedframe.resources.devices.PhysicalResource; |
---|
| 11 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 12 | import simulator.DataCenterWorkloadSimulator; |
---|
| 13 | import eduni.simjava.Sim_system; |
---|
| 14 | import example.energy.BaseEnergyEstimationPlugin; |
---|
[1500] | 15 | import experiments.simpat2014.EnvironmentConditions; |
---|
[1469] | 16 | import gridsim.dcworms.DCWormsTags; |
---|
| 17 | |
---|
| 18 | public class CpuEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
| 19 | |
---|
| 20 | private static double Pidle = 4; |
---|
| 21 | private static double Pfull = 50; |
---|
| 22 | |
---|
| 23 | private static int Tidle = 33; |
---|
| 24 | |
---|
| 25 | private double timestamp = 0; |
---|
| 26 | private double old_temperature = Tidle; |
---|
| 27 | private double new_temperature = -1; |
---|
| 28 | private double objective_temperature = Tidle; |
---|
| 29 | |
---|
| 30 | private boolean fan = false; |
---|
| 31 | |
---|
| 32 | private double next_timer = -1; |
---|
| 33 | |
---|
| 34 | private int cpu_temp_monitor = 0; |
---|
| 35 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
| 36 | PhysicalResource resource) { |
---|
| 37 | double powerConsumption = 0; |
---|
| 38 | |
---|
| 39 | Processor cpu = (Processor)resource; |
---|
| 40 | powerConsumption = Pidle + (Pfull- Pidle) * cpu.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
| 41 | |
---|
| 42 | return powerConsumption; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | @Override |
---|
| 46 | public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
| 47 | double future = -1; |
---|
| 48 | |
---|
| 49 | Processor cpu = (Processor) resource; |
---|
| 50 | |
---|
| 51 | double R = 0; |
---|
| 52 | double Rb = 0; |
---|
| 53 | double Rcv = 0; |
---|
| 54 | try{ |
---|
| 55 | Rb = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); |
---|
| 56 | } catch (Exception e){ |
---|
| 57 | // |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | double k = 0; |
---|
| 61 | try{ |
---|
| 62 | k = Double.valueOf(cpu.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue(); |
---|
| 63 | } catch (Exception e){ |
---|
| 64 | // |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | double a = 0; |
---|
| 68 | try{ |
---|
| 69 | a = Double.valueOf(cpu.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue(); |
---|
| 70 | } catch (Exception e){ |
---|
| 71 | a = 1; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | double V = 0; |
---|
| 75 | |
---|
| 76 | for(Device device: cpu.getParent().getParent().getResourceCharacteristic().getDevices()){ |
---|
| 77 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
| 78 | if(Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1])){ |
---|
| 79 | Fan fan = (Fan) device; |
---|
| 80 | V = fan.getAirflowInterface().getRecentAirflow().getValue(); |
---|
| 81 | break; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | Rcv = 1/ (k * Math.pow(V, a)); |
---|
| 87 | R = Rb + Rcv; |
---|
| 88 | |
---|
| 89 | double C = 0; |
---|
| 90 | try{ |
---|
| 91 | C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); |
---|
| 92 | } catch (Exception e){ |
---|
| 93 | // |
---|
| 94 | } |
---|
| 95 | // 1) look where we are |
---|
| 96 | double delta_t = Sim_system.clock() - timestamp; |
---|
| 97 | /***************model1*************/ |
---|
| 98 | //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/sink); |
---|
| 99 | |
---|
| 100 | /***************model2*************/ |
---|
| 101 | new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | // 2) calculate if fan is needed ? |
---|
| 105 | if(new_temperature <= EnvironmentConditions.TFanLow) { |
---|
| 106 | fan = false; |
---|
| 107 | } |
---|
| 108 | if(new_temperature >= EnvironmentConditions.TFanHigh) { |
---|
| 109 | fan = true; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // 3) compute new objective |
---|
| 113 | double Tin = EnvironmentConditions.ROOM_TEMPERATURE; |
---|
| 114 | double Pcpu = cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 115 | new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
| 116 | //new_temperature = (Pcpu * R + Tin) - (Pcpu * R + Tin - Tidle) * Math.exp(-Sim_system.clock()/(R * C));; |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | NodeGroup ng = (NodeGroup) cpu.getParent().getParent(); |
---|
| 120 | for(Node n: ng.getNodes()){ |
---|
| 121 | if(Integer.valueOf(n.getName().split("_")[1]) - Integer.valueOf(cpu.getParent().getName().split("_")[1]) == EnvironmentConditions.NODES_IN_A_ROW){ |
---|
| 122 | Tin = n.getThermalInterface().getRecentTemperature().getValue(); |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | /***************model1 - GEO1*************/ |
---|
| 127 | //double cpuLoad = cpu.getLoadInterface().getRecentUtilization().getValue(); |
---|
| 128 | //double targetTemp = Tidle + cpuLoad/100 * dTfull; |
---|
| 129 | //if(fan) { |
---|
| 130 | // targetTemp = targetTemp - dTfan; |
---|
| 131 | //} |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /***************model2 - GEO2*************/ |
---|
| 135 | //Node node = (Node) cpu.getParent(); |
---|
| 136 | //Pserv = node.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 137 | //double targetTemp = Pcpu * R + Tin; |
---|
| 138 | |
---|
| 139 | /***************model3 - GEO1 + GEO2*************/ |
---|
| 140 | /*double targetTemp = Pcpu * R + Tin; |
---|
| 141 | if(fan) { |
---|
| 142 | targetTemp = targetTemp - dTfan; |
---|
| 143 | }*/ |
---|
| 144 | |
---|
| 145 | /***************model4 - WP*************/ |
---|
| 146 | double targetTemp = Pcpu * R + Tin; |
---|
| 147 | |
---|
| 148 | // 4) check if we will need to tune fans |
---|
| 149 | if(fan && targetTemp < EnvironmentConditions.TFanLow) { |
---|
| 150 | double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow)); |
---|
| 151 | if(future == -1 || future > timer) { |
---|
| 152 | future = timer; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | if(!fan && targetTemp > EnvironmentConditions.TFanHigh) { |
---|
| 156 | double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanHigh)); |
---|
| 157 | if(future == -1 || future > timer) { |
---|
| 158 | future = timer; |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | // 5) save everything |
---|
| 163 | timestamp = Sim_system.clock(); |
---|
| 164 | old_temperature = new_temperature; |
---|
| 165 | objective_temperature = targetTemp; |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | if((future >= 0) && ((next_timer < Sim_system.clock()) || (next_timer >= future + Sim_system.clock()))) { |
---|
| 169 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(future, DCWormsTags.FANMGT, "Test"); |
---|
| 170 | next_timer = future + Sim_system.clock() - 0.01; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if(new_temperature > EnvironmentConditions.tempLevelMedium2Low && new_temperature < EnvironmentConditions.tempLevelLow2Medium){ |
---|
| 174 | if(cpu_temp_monitor != 1){ |
---|
| 175 | cpu_temp_monitor = 1; |
---|
| 176 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 177 | } |
---|
| 178 | } else if(new_temperature > EnvironmentConditions.tempLevelLow2Medium && new_temperature < EnvironmentConditions.tempLevelHigh2Medium){ |
---|
| 179 | if(cpu_temp_monitor != 2){ |
---|
| 180 | cpu_temp_monitor = 2; |
---|
| 181 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 182 | } |
---|
| 183 | } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Medium && new_temperature < EnvironmentConditions.tempLevelMedium2High){ |
---|
| 184 | if(cpu_temp_monitor != 3){ |
---|
| 185 | cpu_temp_monitor = 3; |
---|
| 186 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 187 | } |
---|
| 188 | } else if(new_temperature > EnvironmentConditions.tempLevelMedium2High){ |
---|
| 189 | if(cpu_temp_monitor != 4){ |
---|
| 190 | cpu_temp_monitor = 4; |
---|
| 191 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
| 195 | |
---|
| 196 | return new_temperature; |
---|
| 197 | } |
---|
| 198 | } |
---|