1 | package test.powerCapping; |
---|
2 | |
---|
3 | import schedframe.events.scheduling.EventReason; |
---|
4 | import schedframe.resources.computing.ComputingResource; |
---|
5 | import schedframe.resources.computing.Node; |
---|
6 | import schedframe.resources.computing.Processor; |
---|
7 | import schedframe.resources.computing.profiles.energy.EnergyEvent; |
---|
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 example.energy.BaseEnergyEstimationPlugin; |
---|
14 | |
---|
15 | public class FanEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
16 | |
---|
17 | public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry, |
---|
18 | PhysicalResource resource) { |
---|
19 | |
---|
20 | double powerConsumption = 0; |
---|
21 | |
---|
22 | Fan fan = (Fan) resource; |
---|
23 | try { |
---|
24 | powerConsumption = fan.getAirThroughputInterface().getPowerConsumption(fan.getAirThroughputInterface().getAirThroughputState()); |
---|
25 | } catch (NoSuchFieldException e) { |
---|
26 | // TODO Auto-generated catch block |
---|
27 | e.printStackTrace(); |
---|
28 | } |
---|
29 | |
---|
30 | /*if(resource.getAirThroughputInterface().getAirThroughputState().getName().equals(new UserAirThroughputStateName("1").getName())){ |
---|
31 | powerConsumption = CoolEmAllTestbedMeasurements.SINGLE_FAN_OFF_POWER_CONSUMPTION; |
---|
32 | } else { |
---|
33 | powerConsumption = CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION; |
---|
34 | }*/ |
---|
35 | return powerConsumption * getFactor(fan)/(double)fan.getChilledResources().size(); |
---|
36 | } |
---|
37 | |
---|
38 | public double estimateAirThroughput(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
39 | |
---|
40 | double airThroughput = 0; |
---|
41 | Fan fan = (Fan) resource; |
---|
42 | try { |
---|
43 | if(event.getReason() == EventReason.SIM_INIT) |
---|
44 | airThroughput = fan.getAirThroughputInterface().getAirFlow(fan.getAirThroughputInterface().getAirThroughputState()); |
---|
45 | else |
---|
46 | airThroughput = fan.getAirThroughputInterface().getAirFlow(fan.getAirThroughputInterface().getAirThroughputState()); |
---|
47 | } catch (NoSuchFieldException e) { |
---|
48 | // TODO Auto-generated catch block |
---|
49 | e.printStackTrace(); |
---|
50 | } |
---|
51 | |
---|
52 | /*if(event.getReason() == EventReason.SIM_INIT){ |
---|
53 | if(resource.getAirThroughputInterface().getAirThroughputState().getName().equals(new UserAirThroughputStateName("1").getName())){ |
---|
54 | airThroughput = CoolEmAllTestbedMeasurements.SINGLE_FAN_OFF_AIR_FLOW; |
---|
55 | } else { |
---|
56 | airThroughput = CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_AIR_FLOW; |
---|
57 | } |
---|
58 | } |
---|
59 | else { |
---|
60 | if(resource.getAirThroughputInterface().getAirThroughputState().getName().equals(new UserAirThroughputStateName("1").getName())){ |
---|
61 | airThroughput = CoolEmAllTestbedMeasurements.SINGLE_FAN_OFF_AIR_FLOW; |
---|
62 | } else { |
---|
63 | airThroughput = CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_AIR_FLOW; |
---|
64 | } |
---|
65 | }*/ |
---|
66 | |
---|
67 | |
---|
68 | return airThroughput * getFactor(fan)/(double)fan.getChilledResources().size(); |
---|
69 | } |
---|
70 | |
---|
71 | private int getNumberOfWorkingNodes(Device device){ |
---|
72 | int quantity = 0; |
---|
73 | Fan fan = (Fan) device; |
---|
74 | for(ComputingResource compRes: device.getComputingResource().getChildren()){ |
---|
75 | Node node = (Node)compRes; |
---|
76 | if(fan.getChilledResources().contains(node.getFullName()) && node.getPowerInterface().getPowerState().equals(StandardPowerStateName.ON) ){ |
---|
77 | quantity++; |
---|
78 | } |
---|
79 | } |
---|
80 | return quantity; |
---|
81 | } |
---|
82 | |
---|
83 | private double getFactor(Device device){ |
---|
84 | int quantity = 0; |
---|
85 | |
---|
86 | double factor = 0;; |
---|
87 | Fan fan = (Fan) device; |
---|
88 | for(ComputingResource compRes: device.getComputingResource().getChildren()){ |
---|
89 | Node node = (Node)compRes; |
---|
90 | double nrOfComputingProcessor = 0; |
---|
91 | double meanCurrFrequency = 0; |
---|
92 | double meanMaxFrequency = 0; |
---|
93 | if(fan.getChilledResources().contains(node.getFullName()) && node.getPowerInterface().getPowerState().equals(StandardPowerStateName.ON) ){ |
---|
94 | quantity++; |
---|
95 | for(Processor proc: node.getProcessors()){ |
---|
96 | if(proc.getCores().size() != proc.getFreeCores().size()){ |
---|
97 | nrOfComputingProcessor++; |
---|
98 | meanCurrFrequency = meanCurrFrequency + proc.getPowerInterface().getFrequency(); |
---|
99 | meanMaxFrequency = meanMaxFrequency + proc.getPowerInterface().getLowestPState().getFrequency(); |
---|
100 | } else { |
---|
101 | meanCurrFrequency = meanCurrFrequency + proc.getPowerInterface().getHighestPState().getFrequency(); |
---|
102 | meanMaxFrequency = meanMaxFrequency + proc.getPowerInterface().getLowestPState().getFrequency(); |
---|
103 | } |
---|
104 | |
---|
105 | } |
---|
106 | meanCurrFrequency = meanCurrFrequency/node.getProcessors().size(); |
---|
107 | meanMaxFrequency = meanMaxFrequency/node.getProcessors().size(); |
---|
108 | factor = factor + (meanCurrFrequency /meanMaxFrequency) * (0.5+ nrOfComputingProcessor/node.getProcessors().size()); |
---|
109 | } |
---|
110 | } |
---|
111 | return factor; |
---|
112 | } |
---|
113 | } |
---|