1 | package test.simpat.models.article; |
---|
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 test.simpat.EnvironmentConditions; |
---|
15 | import eduni.simjava.Sim_system; |
---|
16 | import example.energy.BaseEnergyEstimationPlugin; |
---|
17 | import gridsim.dcworms.DCWormsTags; |
---|
18 | |
---|
19 | public class CpuEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
20 | |
---|
21 | private static double Pidle = 4; |
---|
22 | private static double Pfull = 26; |
---|
23 | |
---|
24 | private static int Tidle = 33; |
---|
25 | |
---|
26 | private double timestamp = 0; |
---|
27 | private double old_temperature = Tidle; |
---|
28 | private double new_temperature = -1; |
---|
29 | private double objective_temperature = Tidle; |
---|
30 | |
---|
31 | private boolean fan = false; |
---|
32 | |
---|
33 | private double next_timer = -1; |
---|
34 | |
---|
35 | private int cpu_temp_monitor = 0; |
---|
36 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
37 | PhysicalResource resource) { |
---|
38 | /*double powerConsumption = 0; |
---|
39 | |
---|
40 | Processor cpu = (Processor)resource; |
---|
41 | powerConsumption = Pidle + (Pfull- Pidle) * cpu.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
42 | |
---|
43 | return powerConsumption;*/ |
---|
44 | |
---|
45 | double processorLoad = 0; |
---|
46 | double powerConsumption = 0; |
---|
47 | Processor proc = (Processor)resource; |
---|
48 | if(resource.getPowerInterface().getPowerState().equals(StandardPowerStateName.OFF)) |
---|
49 | return 0; |
---|
50 | else { |
---|
51 | |
---|
52 | processorLoad = proc.getLoadInterface().getRecentUtilization().getValue(); |
---|
53 | double lowestLoadLevel = 100; |
---|
54 | double highestLoadLevel = 0; |
---|
55 | if(proc.getPowerInterface().getPState().getLoadPowerUsage().containsKey(new Double(processorLoad))){ |
---|
56 | powerConsumption = proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(processorLoad)); |
---|
57 | //System.out.println("power from profile: " + powerConsumption); |
---|
58 | } else { |
---|
59 | for(Double load: proc.getPowerInterface().getPState().getLoadPowerUsage().keySet()){ |
---|
60 | if(lowestLoadLevel > load){ |
---|
61 | lowestLoadLevel = load; |
---|
62 | } |
---|
63 | if(highestLoadLevel < load){ |
---|
64 | highestLoadLevel = load; |
---|
65 | } |
---|
66 | } |
---|
67 | if(processorLoad == 0){ |
---|
68 | try{ |
---|
69 | powerConsumption = proc.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage(); |
---|
70 | //System.out.println("load = 0; power = idle power usage: " + powerConsumption); |
---|
71 | } catch (Exception e){ |
---|
72 | powerConsumption = 0.7 * proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(highestLoadLevel)); |
---|
73 | //System.out.println("error load = 0; power = 0.7 max power: " + powerConsumption); |
---|
74 | } |
---|
75 | } else { |
---|
76 | |
---|
77 | double lowerLoadLevel = lowestLoadLevel; |
---|
78 | double higherLoadLevel = highestLoadLevel; |
---|
79 | |
---|
80 | try{ |
---|
81 | |
---|
82 | for(Double load: proc.getPowerInterface().getPState().getLoadPowerUsage().keySet()){ |
---|
83 | if(processorLoad > load){ |
---|
84 | lowerLoadLevel = load; |
---|
85 | } |
---|
86 | else if(processorLoad < load){ |
---|
87 | higherLoadLevel = load; |
---|
88 | break; |
---|
89 | } |
---|
90 | } |
---|
91 | double powerBelow; |
---|
92 | double powerAbove; |
---|
93 | double a; |
---|
94 | double b; |
---|
95 | if(lowerLoadLevel != higherLoadLevel) { |
---|
96 | powerBelow = proc.getPowerInterface().getPState().getLoadPowerUsage().get(lowerLoadLevel); |
---|
97 | powerAbove = proc.getPowerInterface().getPState().getLoadPowerUsage().get(higherLoadLevel); |
---|
98 | a = (powerAbove - powerBelow)/(higherLoadLevel - lowerLoadLevel); |
---|
99 | b = powerAbove - a * higherLoadLevel; |
---|
100 | } else { |
---|
101 | powerBelow = proc.getPowerInterface().getPState().getLoadPowerUsage().get(lowestLoadLevel); |
---|
102 | powerAbove = proc.getPowerInterface().getPState().getLoadPowerUsage().get(highestLoadLevel); |
---|
103 | a = (powerAbove - powerBelow)/(highestLoadLevel - lowestLoadLevel); |
---|
104 | b = powerAbove - a * highestLoadLevel; |
---|
105 | } |
---|
106 | powerConsumption = a * processorLoad + b; |
---|
107 | /*System.out.println("a" +lowestLoadLevel + ";" +highestLoadLevel); |
---|
108 | System.out.println("b" +lowerLoadLevel + ";" +higherLoadLevel); |
---|
109 | System.out.println("c" +powerBelow + ";" +powerAbove); |
---|
110 | System.out.println(resource.getFullName() + "load: " + processorLoad + "linear power estimation " + powerConsumption);*/ |
---|
111 | |
---|
112 | } catch (Exception e){ |
---|
113 | powerConsumption = 0.7 * proc.getPowerInterface().getPState().getLoadPowerUsage().get(new Double(highestLoadLevel)); |
---|
114 | //System.out.println("error; power = 0.7 max power: " + powerConsumption); |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | //System.out.println("estimated power consumption: " + powerConsumption); |
---|
120 | return powerConsumption; |
---|
121 | } |
---|
122 | |
---|
123 | @Override |
---|
124 | public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
125 | double future = -1; |
---|
126 | |
---|
127 | Processor cpu = (Processor) resource; |
---|
128 | |
---|
129 | double R = 0; |
---|
130 | double Rb = 0; |
---|
131 | double Rcv = 0; |
---|
132 | try{ |
---|
133 | Rb = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); |
---|
134 | } catch (Exception e){ |
---|
135 | // |
---|
136 | } |
---|
137 | |
---|
138 | double k = 0; |
---|
139 | try{ |
---|
140 | k = Double.valueOf(cpu.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue(); |
---|
141 | } catch (Exception e){ |
---|
142 | // |
---|
143 | } |
---|
144 | |
---|
145 | double a = 0; |
---|
146 | try{ |
---|
147 | a = Double.valueOf(cpu.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue(); |
---|
148 | } catch (Exception e){ |
---|
149 | a = 1; |
---|
150 | } |
---|
151 | |
---|
152 | double V = 0; |
---|
153 | |
---|
154 | for(Device device: cpu.getParent().getParent().getResourceCharacteristic().getDevices()){ |
---|
155 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
156 | if(Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1]) /*|| Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1]) - EnvironmentConditions.NODES_IN_A_ROW*/){ |
---|
157 | Fan fan = (Fan) device; |
---|
158 | V = fan.getAirflowInterface().getRecentAirflow().getValue(); |
---|
159 | break; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | Rcv = 1/ (k * Math.pow(V, a)); |
---|
165 | R = Rb + Rcv; |
---|
166 | double C = 0; |
---|
167 | try{ |
---|
168 | C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); |
---|
169 | } catch (Exception e){ |
---|
170 | // |
---|
171 | } |
---|
172 | // 1) look where we are |
---|
173 | double delta_t = Sim_system.clock() - timestamp; |
---|
174 | /***************model1*************/ |
---|
175 | //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/sink); |
---|
176 | |
---|
177 | /***************model2*************/ |
---|
178 | new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
179 | |
---|
180 | |
---|
181 | // 2) calculate if fan is needed ? |
---|
182 | if(new_temperature <= EnvironmentConditions.TFanLow) { |
---|
183 | fan = false; |
---|
184 | } |
---|
185 | if(new_temperature >= EnvironmentConditions.TFanHigh) { |
---|
186 | fan = true; |
---|
187 | } |
---|
188 | |
---|
189 | // 3) compute new objective |
---|
190 | double Tin = EnvironmentConditions.ROOM_TEMPERATURE; |
---|
191 | double Pcpu = cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
192 | new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); |
---|
193 | //new_temperature = (Pcpu * R + Tin) - (Pcpu * R + Tin - Tidle) * Math.exp(-Sim_system.clock()/(R * C));; |
---|
194 | |
---|
195 | |
---|
196 | NodeGroup ng = (NodeGroup) cpu.getParent().getParent(); |
---|
197 | for(Node n: ng.getNodes()){ |
---|
198 | if(Integer.valueOf(n.getName().split("_")[1]) - Integer.valueOf(cpu.getParent().getName().split("_")[1]) == EnvironmentConditions.NODES_IN_A_ROW){ |
---|
199 | Tin = n.getThermalInterface().getRecentTemperature().getValue(); |
---|
200 | |
---|
201 | } |
---|
202 | } |
---|
203 | Tin = (2 * Tin + cpu.getThermalInterface().getRecentTemperature().getValue())/3; |
---|
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 | |
---|
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(new_temperature < EnvironmentConditions.tempLevelMedium2Low){ |
---|
252 | if(cpu_temp_monitor != 1){ |
---|
253 | cpu_temp_monitor = 1; |
---|
254 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
255 | } |
---|
256 | } else if(new_temperature > EnvironmentConditions.tempLevelMedium2Low && new_temperature < EnvironmentConditions.tempLevelLow2Medium){ |
---|
257 | if(cpu_temp_monitor != 2){ |
---|
258 | cpu_temp_monitor = 2; |
---|
259 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
260 | } |
---|
261 | } else if(new_temperature > EnvironmentConditions.tempLevelLow2Medium && new_temperature < EnvironmentConditions.tempLevelHigh2Medium){ |
---|
262 | if(cpu_temp_monitor != 3){ |
---|
263 | cpu_temp_monitor = 3; |
---|
264 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
265 | } |
---|
266 | } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Medium && new_temperature < EnvironmentConditions.tempLevelMedium2High){ |
---|
267 | if(cpu_temp_monitor != 4){ |
---|
268 | cpu_temp_monitor = 4; |
---|
269 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
270 | } |
---|
271 | } else if(new_temperature > EnvironmentConditions.tempLevelMedium2High && new_temperature < EnvironmentConditions.tempLevelMax2High){ |
---|
272 | if(cpu_temp_monitor != 5){ |
---|
273 | cpu_temp_monitor = 5; |
---|
274 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
275 | } |
---|
276 | } else if(new_temperature > EnvironmentConditions.tempLevelMax2High && new_temperature < EnvironmentConditions.tempLevelHigh2Max){ |
---|
277 | if(cpu_temp_monitor != 6){ |
---|
278 | cpu_temp_monitor = 6; |
---|
279 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
280 | } |
---|
281 | } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Max){ |
---|
282 | if(cpu_temp_monitor != 7){ |
---|
283 | cpu_temp_monitor = 7; |
---|
284 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
285 | } |
---|
286 | } |
---|
287 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); |
---|
288 | |
---|
289 | return new_temperature; |
---|
290 | } |
---|
291 | } |
---|