1 | package experiments.simpat2014.models.article; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.List; |
---|
6 | import java.util.Map; |
---|
7 | import java.util.Random; |
---|
8 | |
---|
9 | import schedframe.events.scheduling.SchedulingEvent; |
---|
10 | import schedframe.resources.CoolEmAllResourceType; |
---|
11 | import schedframe.resources.ResourceStatus; |
---|
12 | import schedframe.resources.StandardResourceType; |
---|
13 | import schedframe.resources.computing.ComputingResource; |
---|
14 | import schedframe.resources.computing.Core; |
---|
15 | import schedframe.resources.computing.Node; |
---|
16 | import schedframe.resources.computing.Processor; |
---|
17 | import schedframe.resources.computing.Rack; |
---|
18 | import schedframe.resources.computing.coolemall.ComputeBox1; |
---|
19 | import schedframe.resources.computing.coolemall.NodeGroup; |
---|
20 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
21 | import schedframe.resources.computing.profiles.energy.ResourceEventType; |
---|
22 | import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName; |
---|
23 | import schedframe.resources.computing.profiles.energy.power.PState; |
---|
24 | import schedframe.resources.devices.Device; |
---|
25 | import schedframe.resources.devices.Fan; |
---|
26 | import schedframe.resources.units.ProcessingElements; |
---|
27 | import schedframe.resources.units.ResourceUnit; |
---|
28 | import schedframe.resources.units.ResourceUnitName; |
---|
29 | import schedframe.resources.units.StandardResourceUnitName; |
---|
30 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
31 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
32 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
33 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
34 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
35 | import schedframe.scheduling.plugin.ModuleList; |
---|
36 | import schedframe.scheduling.queue.TaskQueue; |
---|
37 | import schedframe.scheduling.queue.TaskQueueList; |
---|
38 | import schedframe.scheduling.tasks.TaskInterface; |
---|
39 | import simulator.DataCenterWorkloadSimulator; |
---|
40 | import test.Node_Fan_Mapping; |
---|
41 | import eduni.simjava.Sim_system; |
---|
42 | import example.energy.coolemall.CoolEmAllTestbedMeasurements; |
---|
43 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
44 | import experiments.simpat2014.EnvironmentConditions; |
---|
45 | import gridsim.dcworms.DCWormsTags; |
---|
46 | |
---|
47 | public class FCFSBF_RandomPluginPowerCapping extends BaseLocalSchedulingPlugin { |
---|
48 | |
---|
49 | private Random rand; |
---|
50 | |
---|
51 | private Map<String, Double> powerCapsLevels; |
---|
52 | private Map<String, Double> powerUpgradesLevels; |
---|
53 | private Map<String, Double> currentFrequencyLevels; |
---|
54 | |
---|
55 | public FCFSBF_RandomPluginPowerCapping () { |
---|
56 | rand = new Random(5); |
---|
57 | currentFrequencyLevels = new HashMap<String, Double>(); |
---|
58 | powerCapsLevels = new HashMap<String, Double>(); |
---|
59 | powerUpgradesLevels = new HashMap<String, Double>(); |
---|
60 | } |
---|
61 | |
---|
62 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
63 | ResourceManager resManager, ModuleList modules) { |
---|
64 | |
---|
65 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
66 | SchedulingPlan plan = new SchedulingPlan(); |
---|
67 | // choose the events types to serve. |
---|
68 | // Different actions for different events are possible. |
---|
69 | switch (event.getType()) { |
---|
70 | case TIMER: |
---|
71 | |
---|
72 | System.out.println("##" + Sim_system.clock()); |
---|
73 | DataCenterWorkloadSimulator.getEventManager().sendToResources(StandardResourceType.Processor, 0.0, new ResourceEvent(ResourceEventType.TIMER, null)); |
---|
74 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(EnvironmentConditions.SYSTEM_UDPATE_INTERVAL, DCWormsTags.TIMER, "Test"); |
---|
75 | break; |
---|
76 | case START_TASK_EXECUTION: |
---|
77 | case TASK_FINISHED: |
---|
78 | //case TIMER: |
---|
79 | // our tasks are placed only in first queue (see |
---|
80 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
81 | TaskQueue q = queues.get(0); |
---|
82 | |
---|
83 | // check all tasks in queue |
---|
84 | for (int i = 0; i < q.size(); i++) { |
---|
85 | TaskInterface<?> task = q.get(i); |
---|
86 | // if status of the tasks in READY |
---|
87 | if (task.getStatus() == DCWormsTags.READY) { |
---|
88 | |
---|
89 | if(resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Core, ResourceStatus.FREE).size() == 0) |
---|
90 | break; |
---|
91 | |
---|
92 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task); |
---|
93 | if (choosenResources != null) { |
---|
94 | addToSchedulingPlan(plan, task, choosenResources); |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | break; |
---|
99 | case RESOURCE_POWER_LIMIT_EXCEEDED: |
---|
100 | powerCap(resManager, event.getSource().toString()); |
---|
101 | break; |
---|
102 | case RESOURCE_TEMPERATURE_LIMIT_EXCEEDED: |
---|
103 | manageFans(resourceManager.getResourceByName(event.getSource())); |
---|
104 | break; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | return plan; |
---|
109 | } |
---|
110 | |
---|
111 | private void manageFans(ComputingResource cr ){ |
---|
112 | //System.out.println("tuning fans"); |
---|
113 | double temp = cr.getThermalInterface().getRecentTemperature().getValue(); |
---|
114 | double prevTemp; |
---|
115 | if(cr.getThermalInterface().getTemperatureHistory().size() == 1) |
---|
116 | prevTemp = temp; |
---|
117 | else { |
---|
118 | prevTemp = cr.getThermalInterface().getTemperatureHistory().get(cr.getThermalInterface().getTemperatureHistory().size() - 2).getValue(); |
---|
119 | } |
---|
120 | |
---|
121 | //System.out.println(prevTemp+ "; " + temp); |
---|
122 | boolean getingHotter = prevTemp < temp; |
---|
123 | boolean getingColder = prevTemp > temp; |
---|
124 | Node n = (Node) cr.getParent(); |
---|
125 | for(Device d: n.getParent().getResourceCharacteristic().getDevices()){ |
---|
126 | //System.out.println(d.getName() + "; " + n.getName()); |
---|
127 | if(Integer.valueOf(d.getName().split("_")[1]).intValue() == Integer.valueOf(n.getName().split("_")[1]).intValue() || Integer.valueOf(d.getName().split("_")[1]).intValue() == Integer.valueOf(n.getName().split("_")[1]).intValue() - EnvironmentConditions.NODES_IN_A_ROW){ |
---|
128 | Fan f = (Fan) d; |
---|
129 | int speed; |
---|
130 | try{ |
---|
131 | speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue(); |
---|
132 | } catch(Exception e){ |
---|
133 | speed = 0; |
---|
134 | } |
---|
135 | if(getingHotter){ |
---|
136 | if(temp > EnvironmentConditions.tempLevelLow2Medium && temp < EnvironmentConditions.tempLevelMedium2High){ |
---|
137 | if(speed < 60){ |
---|
138 | //System.out.println("+++++++++ low 2 medium"); |
---|
139 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60")); |
---|
140 | } |
---|
141 | } else if (temp > EnvironmentConditions.tempLevelMedium2High && temp < EnvironmentConditions.tempLevelHigh2Max) { |
---|
142 | if(speed < 80){ |
---|
143 | //System.out.println("++++++++medium 2 high"); |
---|
144 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80")); |
---|
145 | } |
---|
146 | } else if (temp > EnvironmentConditions.tempLevelHigh2Max) { |
---|
147 | if(speed < 100){ |
---|
148 | //System.out.println("++++++++high 2 max"); |
---|
149 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100")); |
---|
150 | } |
---|
151 | } |
---|
152 | } else if (getingColder){ |
---|
153 | if(temp > EnvironmentConditions.tempLevelHigh2Medium && temp < EnvironmentConditions.tempLevelMax2High){ |
---|
154 | if(speed == 100){ |
---|
155 | //System.out.println("-------- max 2 high"); |
---|
156 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80")); |
---|
157 | } |
---|
158 | } else if(temp > EnvironmentConditions.tempLevelMedium2Low && temp < EnvironmentConditions.tempLevelHigh2Medium){ |
---|
159 | if(speed >= 80){ |
---|
160 | //System.out.println("-------- high 2 medium"); |
---|
161 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60")); |
---|
162 | } |
---|
163 | } else if (temp < EnvironmentConditions.tempLevelMedium2Low) { |
---|
164 | if(speed >= 60){ |
---|
165 | //System.out.println("-------- medium 2 low"); |
---|
166 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30")); |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
175 | ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
176 | |
---|
177 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(); |
---|
178 | |
---|
179 | List<Node> nodes = resourceManager.getNodes(); |
---|
180 | List<Node> avNodes = filterNodes(nodes, task); |
---|
181 | if(avNodes.size() == 0) |
---|
182 | return null; |
---|
183 | Node node = randomNode(avNodes); |
---|
184 | int cpuRequest; |
---|
185 | try { |
---|
186 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
187 | } catch (NoSuchFieldException e) { |
---|
188 | cpuRequest = 0; |
---|
189 | } |
---|
190 | |
---|
191 | if (cpuRequest != 0) { |
---|
192 | |
---|
193 | List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(); |
---|
194 | List<Core> cores = node.getCores(); |
---|
195 | for (int i = 0; i < cores.size() && cpuRequest > 0; i++) { |
---|
196 | if (cores.get(i).getStatus() == ResourceStatus.FREE) { |
---|
197 | choosenResources.add(cores.get(i)); |
---|
198 | cpuRequest--; |
---|
199 | } |
---|
200 | } |
---|
201 | if (cpuRequest > 0) { |
---|
202 | return null; |
---|
203 | } |
---|
204 | |
---|
205 | //choosenResources.add(node.getProcessors().get(0)); |
---|
206 | ProcessingElements pe = new ProcessingElements(); |
---|
207 | pe.addAll(choosenResources); |
---|
208 | map.put(StandardResourceUnitName.PE, pe); |
---|
209 | return map; |
---|
210 | } |
---|
211 | return null; |
---|
212 | } |
---|
213 | |
---|
214 | private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task){ |
---|
215 | List<Node> filteredNodes = new ArrayList<Node>(); |
---|
216 | int cpuRequest; |
---|
217 | try { |
---|
218 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
219 | } catch (NoSuchFieldException e) { |
---|
220 | cpuRequest = 0; |
---|
221 | } |
---|
222 | for (Node node : nodes) { |
---|
223 | |
---|
224 | if (cpuRequest != 0) { |
---|
225 | |
---|
226 | List<Core> cores = node.getCores(); |
---|
227 | if (cores.size() < cpuRequest) { |
---|
228 | if(cores.size() == 0){ |
---|
229 | if(node.getProcessors().size() < cpuRequest) |
---|
230 | continue; |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | int freeCores = 0; |
---|
235 | for(Core core: cores){ |
---|
236 | if(core.getStatus() == ResourceStatus.FREE) |
---|
237 | freeCores++; |
---|
238 | } |
---|
239 | |
---|
240 | if(freeCores < cpuRequest) |
---|
241 | continue; |
---|
242 | |
---|
243 | filteredNodes.add(node); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | return filteredNodes; |
---|
248 | } |
---|
249 | |
---|
250 | private Node randomNode(List<Node> nodes){ |
---|
251 | return nodes.get(rand.nextInt(nodes.size())); |
---|
252 | } |
---|
253 | |
---|
254 | private void powerCap(ResourceManager resManager, String resName){ |
---|
255 | ComputingResource compRes = resManager.getResourceByName(resName); |
---|
256 | //for(ComputingResource compRes: resManager.getResourcesOfType(CoolEmAllResourceType.NodeGroup)){ |
---|
257 | if(!powerCapsLevels.containsKey(compRes.getFullName()) || !powerUpgradesLevels.containsKey(compRes.getFullName())){ |
---|
258 | loadThresholds(compRes); |
---|
259 | } |
---|
260 | double powerConsumption = compRes.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
261 | //System.out.println(compRes.getFullName() + " current: " + powerConsumption); |
---|
262 | if(powerConsumption > powerCapsLevels.get(compRes.getFullName())){ |
---|
263 | NodeGroup nodeGroup = (NodeGroup) compRes; |
---|
264 | List<Processor> processors = nodeGroup.getProcessors(); |
---|
265 | |
---|
266 | double currentFrequencyLevel = 0; |
---|
267 | if(currentFrequencyLevels.get(compRes.getFullName()) != null){ |
---|
268 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
269 | } else { |
---|
270 | currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); |
---|
271 | } |
---|
272 | boolean overThreshold = true; |
---|
273 | boolean canDoBetter = true; |
---|
274 | |
---|
275 | while(overThreshold && canDoBetter){ |
---|
276 | //System.out.println(compRes.getFullName() + " - downgrading"); |
---|
277 | int procNumberWithoutChange = 0; |
---|
278 | boolean improvement = false; |
---|
279 | //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); |
---|
280 | for (Processor proc: processors){ |
---|
281 | PState currPState = proc.getPowerInterface().getPState(); |
---|
282 | //System.out.println(proc.getFullName() + " - checking"); |
---|
283 | if(currPState.getFrequency() <= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ |
---|
284 | //System.out.println("operating same level"); |
---|
285 | procNumberWithoutChange++; |
---|
286 | continue; |
---|
287 | } |
---|
288 | if (proc.getFreeCores().size() == proc.getCores().size()){ |
---|
289 | //System.out.println("free"); |
---|
290 | procNumberWithoutChange++; |
---|
291 | continue; |
---|
292 | } |
---|
293 | |
---|
294 | double lowerFrequency = proc.getPowerInterface().getHighestPState().getFrequency(); |
---|
295 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
296 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
297 | if(pState.getFrequency() > lowerFrequency && pState.getFrequency() < currPState.getFrequency()){ |
---|
298 | lowerFrequency = pState.getFrequency(); |
---|
299 | } |
---|
300 | } |
---|
301 | //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); |
---|
302 | if(lowerFrequency < currentFrequencyLevel){ |
---|
303 | //System.out.println(compRes.getFullName() + " - changing current frequency level"); |
---|
304 | currentFrequencyLevels.put(compRes.getFullName(), lowerFrequency); |
---|
305 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
306 | } |
---|
307 | |
---|
308 | if(lowerFrequency != currPState.getFrequency()) { |
---|
309 | //System.out.println(proc.getFullName() + " - lowering frequency"); |
---|
310 | proc.getPowerInterface().setFrequency(lowerFrequency); |
---|
311 | Node n = proc.getNode(); |
---|
312 | for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ |
---|
313 | |
---|
314 | if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ |
---|
315 | Fan fan = (Fan) device; |
---|
316 | |
---|
317 | if(fan.getChilledResources().contains(n.getFullName())){ |
---|
318 | fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30")); |
---|
319 | } |
---|
320 | } |
---|
321 | } |
---|
322 | improvement = true; |
---|
323 | } |
---|
324 | if(lowerFrequency == proc.getPowerInterface().getHighestPState().getFrequency()){ |
---|
325 | canDoBetter = false; |
---|
326 | } else { |
---|
327 | canDoBetter = true; |
---|
328 | } |
---|
329 | if(compRes.getPowerInterface().getRecentPowerUsage().getValue() <= powerCapsLevels.get(compRes.getFullName())){ |
---|
330 | overThreshold = false; |
---|
331 | break; |
---|
332 | } |
---|
333 | } |
---|
334 | if(procNumberWithoutChange == processors.size() || improvement == false){ |
---|
335 | //System.out.println(compRes.getFullName() + " - failed to improve"); |
---|
336 | double nextFrequencyLevel = processors.get(0).getPowerInterface().getHighestPState().getFrequency(); |
---|
337 | for (Processor proc: processors){ |
---|
338 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
339 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
340 | if(pState.getFrequency() > nextFrequencyLevel && pState.getFrequency() < currentFrequencyLevel){ |
---|
341 | nextFrequencyLevel = pState.getFrequency(); |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); |
---|
346 | currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); |
---|
347 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
348 | if(currentFrequencyLevel == processors.get(0).getPowerInterface().getHighestPState().getFrequency()){ |
---|
349 | canDoBetter = false; |
---|
350 | } |
---|
351 | procNumberWithoutChange = 0; |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | } else if (powerConsumption < powerUpgradesLevels.get(compRes.getFullName())) { |
---|
356 | NodeGroup nodeGroup = (NodeGroup) compRes; |
---|
357 | List<Processor> processors = nodeGroup.getProcessors(); |
---|
358 | |
---|
359 | double currentFrequencyLevel = 0; |
---|
360 | if(currentFrequencyLevels.get(compRes.getFullName()) != null){ |
---|
361 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
362 | } else { |
---|
363 | currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); |
---|
364 | } |
---|
365 | boolean overThreshold = true; |
---|
366 | boolean canDoBetter = true; |
---|
367 | |
---|
368 | while(overThreshold && canDoBetter){ |
---|
369 | //System.out.println(compRes.getFullName() + " - downgrading"); |
---|
370 | int procNumberWithoutChange = 0; |
---|
371 | boolean improvement = false; |
---|
372 | //System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel); |
---|
373 | for (Processor proc: processors){ |
---|
374 | PState currPState = proc.getPowerInterface().getPState(); |
---|
375 | //System.out.println(proc.getFullName() + " - checking"); |
---|
376 | if(currPState.getFrequency() >= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){ |
---|
377 | //System.out.println("operating same level"); |
---|
378 | procNumberWithoutChange++; |
---|
379 | continue; |
---|
380 | } |
---|
381 | if (proc.getFreeCores().size() == proc.getCores().size()){ |
---|
382 | //System.out.println("free"); |
---|
383 | procNumberWithoutChange++; |
---|
384 | continue; |
---|
385 | } |
---|
386 | |
---|
387 | double higherFrequency = proc.getPowerInterface().getLowestPState().getFrequency(); |
---|
388 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
389 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
390 | if(pState.getFrequency() < higherFrequency && pState.getFrequency() > currPState.getFrequency()){ |
---|
391 | higherFrequency = pState.getFrequency(); |
---|
392 | } |
---|
393 | } |
---|
394 | //System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency); |
---|
395 | if(higherFrequency > currentFrequencyLevel){ |
---|
396 | //System.out.println(compRes.getFullName() + " - changing current frequency level"); |
---|
397 | currentFrequencyLevels.put(compRes.getFullName(), higherFrequency); |
---|
398 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
399 | } |
---|
400 | |
---|
401 | if(higherFrequency != currPState.getFrequency()) { |
---|
402 | //System.out.println(proc.getFullName() + " - lowering frequency"); |
---|
403 | proc.getPowerInterface().setFrequency(higherFrequency); |
---|
404 | Node n = proc.getNode(); |
---|
405 | for(Device device: n.getParent().getResourceCharacteristic().getDevices()){ |
---|
406 | |
---|
407 | if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ |
---|
408 | Fan fan = (Fan) device; |
---|
409 | |
---|
410 | if(fan.getChilledResources().contains(n.getFullName())){ |
---|
411 | fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30")); |
---|
412 | } |
---|
413 | } |
---|
414 | } |
---|
415 | improvement = true; |
---|
416 | } |
---|
417 | if(higherFrequency == proc.getPowerInterface().getLowestPState().getFrequency()){ |
---|
418 | canDoBetter = false; |
---|
419 | } else { |
---|
420 | canDoBetter = true; |
---|
421 | } |
---|
422 | if(compRes.getPowerInterface().getRecentPowerUsage().getValue() >= powerCapsLevels.get(compRes.getFullName())){ |
---|
423 | overThreshold = false; |
---|
424 | break; |
---|
425 | } |
---|
426 | } |
---|
427 | if(procNumberWithoutChange == processors.size() || improvement == false){ |
---|
428 | //System.out.println(compRes.getFullName() + " - failed to improve"); |
---|
429 | double nextFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency(); |
---|
430 | for (Processor proc: processors){ |
---|
431 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
432 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
433 | if(pState.getFrequency() < nextFrequencyLevel && pState.getFrequency() > currentFrequencyLevel){ |
---|
434 | nextFrequencyLevel = pState.getFrequency(); |
---|
435 | } |
---|
436 | } |
---|
437 | } |
---|
438 | //System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel); |
---|
439 | currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel); |
---|
440 | currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName()); |
---|
441 | if(currentFrequencyLevel == processors.get(0).getPowerInterface().getLowestPState().getFrequency()){ |
---|
442 | canDoBetter = false; |
---|
443 | } |
---|
444 | procNumberWithoutChange = 0; |
---|
445 | } |
---|
446 | } |
---|
447 | |
---|
448 | } |
---|
449 | //} |
---|
450 | //if(Sim_system.clock() > 1000 && Sim_system.clock() < 1100 || Sim_system.clock() > 3400) |
---|
451 | //System.out.println(currentFrequencyLevels); |
---|
452 | |
---|
453 | } |
---|
454 | |
---|
455 | private void loadThresholds(ComputingResource compResource){ |
---|
456 | |
---|
457 | double pcLevel = 0; |
---|
458 | double puLevel = 0; |
---|
459 | |
---|
460 | /*NodeGroup ng = (NodeGroup) compResource; |
---|
461 | for(Processor proc: ng.getProcessors()){ |
---|
462 | PState highestPState = proc.getPowerInterface().getHighestPState(); |
---|
463 | PState secondHighestPState = proc.getPowerInterface().getLowestPState(); |
---|
464 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
465 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
466 | if(pState.getFrequency() < secondHighestPState.getFrequency() && pState.getFrequency() > highestPState.getFrequency()){ |
---|
467 | secondHighestPState = pState; |
---|
468 | } |
---|
469 | } |
---|
470 | double maxMinPowerUsage = 0; |
---|
471 | double powerUsage = 0; |
---|
472 | |
---|
473 | for(Double load: highestPState.getLoadPowerUsage().keySet()){ |
---|
474 | powerUsage = highestPState.getLoadPowerUsage().get(load); |
---|
475 | if(powerUsage > maxMinPowerUsage){ |
---|
476 | maxMinPowerUsage= powerUsage; |
---|
477 | } |
---|
478 | } |
---|
479 | pcLevel = pcLevel + maxMinPowerUsage; |
---|
480 | |
---|
481 | maxMinPowerUsage = 0; |
---|
482 | powerUsage = 0; |
---|
483 | |
---|
484 | for(Double load: secondHighestPState.getLoadPowerUsage().keySet()){ |
---|
485 | powerUsage = secondHighestPState.getLoadPowerUsage().get(load); |
---|
486 | if(powerUsage > maxMinPowerUsage){ |
---|
487 | maxMinPowerUsage= powerUsage; |
---|
488 | } |
---|
489 | } |
---|
490 | puLevel = puLevel + maxMinPowerUsage; |
---|
491 | |
---|
492 | } |
---|
493 | |
---|
494 | puLevel = (pcLevel * pcLevel / puLevel); |
---|
495 | |
---|
496 | */ |
---|
497 | |
---|
498 | pcLevel = EnvironmentConditions.powerCapLevel; |
---|
499 | puLevel = EnvironmentConditions.powerUpgradeLevel; |
---|
500 | |
---|
501 | powerCapsLevels.put(compResource.getFullName(), pcLevel); |
---|
502 | powerUpgradesLevels.put(compResource.getFullName(), puLevel); |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|