1 | package test.powerCapping; |
---|
2 | |
---|
3 | import org.joda.time.DateTime; |
---|
4 | |
---|
5 | import schedframe.resources.StandardResourceType; |
---|
6 | import schedframe.resources.computing.ComputingResource; |
---|
7 | import schedframe.resources.computing.Node; |
---|
8 | import schedframe.resources.computing.Processor; |
---|
9 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
10 | import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName; |
---|
11 | import schedframe.resources.devices.Device; |
---|
12 | import schedframe.resources.devices.Fan; |
---|
13 | import schedframe.resources.devices.PhysicalResource; |
---|
14 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
15 | import example.energy.BaseEnergyEstimationPlugin; |
---|
16 | |
---|
17 | public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
18 | |
---|
19 | //private static int OUT_START_ID = 0; |
---|
20 | //private static int OUT_END_ID = 8; |
---|
21 | |
---|
22 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
23 | PhysicalResource resource) { |
---|
24 | double powerConsumption = 0; |
---|
25 | Node node = (Node) resource; |
---|
26 | for(Processor cpu: node.getProcessors()){ |
---|
27 | try{ |
---|
28 | powerConsumption = powerConsumption + cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
29 | } catch (Exception e){ |
---|
30 | |
---|
31 | } |
---|
32 | } |
---|
33 | if(node.getPowerInterface().getPowerState().equals(StandardPowerStateName.ON)){ |
---|
34 | //powerConsumption = powerConsumption + CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION; |
---|
35 | for(Device device: node.getParent().getResourceCharacteristic().getDevices()){ |
---|
36 | if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){ |
---|
37 | Fan fan = (Fan) device; |
---|
38 | if(fan.getChilledResources().contains(node.getFullName())){ |
---|
39 | if(fan.getPowerInterface().getRecentPowerUsage().getValue() == -1){ |
---|
40 | try { |
---|
41 | powerConsumption = powerConsumption + fan.getAirflowInterface().getPowerConsumption(fan.getAirflowInterface().getAirflowState())/getNumberOfWorkingNodes(fan); |
---|
42 | } catch (NoSuchFieldException e) { |
---|
43 | // TODO Auto-generated catch block |
---|
44 | e.printStackTrace(); |
---|
45 | } |
---|
46 | }else |
---|
47 | powerConsumption = powerConsumption + fan.getPowerInterface().getRecentPowerUsage().getValue()/getNumberOfWorkingNodes(fan); |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | return powerConsumption; |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | private int getNumberOfWorkingNodes(Device device){ |
---|
58 | int quantity = 0; |
---|
59 | Fan fan = (Fan) device; |
---|
60 | for(ComputingResource compRes: device.getComputingResource().getChildren()){ |
---|
61 | Node node = (Node)compRes; |
---|
62 | if(node.getPowerInterface().getPowerState().equals(StandardPowerStateName.ON) && fan.getChilledResources().contains(node.getFullName())){ |
---|
63 | quantity++; |
---|
64 | } |
---|
65 | } |
---|
66 | return quantity; |
---|
67 | } |
---|
68 | |
---|
69 | private double getFactor(Device device){ |
---|
70 | int quantity = 0; |
---|
71 | |
---|
72 | double factor = 0;; |
---|
73 | Fan fan = (Fan) device; |
---|
74 | for(ComputingResource compRes: device.getComputingResource().getChildren()){ |
---|
75 | Node node = (Node)compRes; |
---|
76 | double nrOfComputingProcessor = 0; |
---|
77 | double meanCurrFrequency = 0; |
---|
78 | double meanMaxFrequency = 0; |
---|
79 | if(fan.getChilledResources().contains(node.getFullName()) && node.getPowerInterface().getPowerState().equals(StandardPowerStateName.ON) ){ |
---|
80 | quantity++; |
---|
81 | for(Processor proc: node.getProcessors()){ |
---|
82 | if(proc.getCores().size() != proc.getFreeCores().size()){ |
---|
83 | nrOfComputingProcessor++; |
---|
84 | } |
---|
85 | meanCurrFrequency = meanCurrFrequency + proc.getPowerInterface().getFrequency(); |
---|
86 | meanMaxFrequency = meanMaxFrequency + proc.getPowerInterface().getLowestPState().getFrequency(); |
---|
87 | } |
---|
88 | meanCurrFrequency = meanCurrFrequency/node.getProcessors().size(); |
---|
89 | meanMaxFrequency = meanMaxFrequency/node.getProcessors().size(); |
---|
90 | factor = factor + (meanCurrFrequency /meanMaxFrequency) * (0.5+ nrOfComputingProcessor/node.getProcessors().size()); |
---|
91 | //System.out.println(meanCurrFrequency + ";" + meanMaxFrequency + ";" + factor); |
---|
92 | } |
---|
93 | } |
---|
94 | return factor; |
---|
95 | } |
---|
96 | } |
---|