1 | package test.article2.recs.plugins.energy; |
---|
2 | |
---|
3 | import java.io.FileInputStream; |
---|
4 | import java.io.FileNotFoundException; |
---|
5 | import java.io.IOException; |
---|
6 | |
---|
7 | import java.util.Map; |
---|
8 | import java.util.PropertyResourceBundle; |
---|
9 | import java.util.ResourceBundle; |
---|
10 | |
---|
11 | import schedframe.events.scheduling.EventReason; |
---|
12 | import schedframe.resources.computing.ComputingNode; |
---|
13 | import schedframe.resources.computing.ComputingResource; |
---|
14 | import schedframe.resources.computing.Core; |
---|
15 | import schedframe.resources.computing.Processor; |
---|
16 | import schedframe.resources.computing.profiles.energy.EnergyEvent; |
---|
17 | import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; |
---|
18 | import schedframe.resources.units.PEUnit; |
---|
19 | import schedframe.resources.units.ProcessingElements; |
---|
20 | import schedframe.resources.units.ResourceUnit; |
---|
21 | import schedframe.resources.units.ResourceUnitName; |
---|
22 | import schedframe.resources.units.StandardResourceUnitName; |
---|
23 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
24 | import test.article2.recs.utils.AppType; |
---|
25 | import test.article2.recs.utils.TaskToApp; |
---|
26 | import dcworms.schedframe.scheduling.ExecTask; |
---|
27 | import dcworms.schedframe.scheduling.Executable; |
---|
28 | import example.energy.BaseEnergyEstimationPlugin; |
---|
29 | |
---|
30 | public abstract class RecsNodeBaseEEP extends BaseEnergyEstimationPlugin{ |
---|
31 | |
---|
32 | private static String POWER_DATA_FILE_NAME = "src/test/article2/recs/data/power_data.properties"; |
---|
33 | |
---|
34 | private static int LEFT_ID = -1; |
---|
35 | private static int RIGHT_ID = +1; |
---|
36 | |
---|
37 | private static int BEHIND_ID = +9; |
---|
38 | |
---|
39 | private static int LEFT_BEHIND_ID = +8; |
---|
40 | private static int RIGHT_BEHIND_ID = +10; |
---|
41 | |
---|
42 | private static int OUT_START_ID = 0; |
---|
43 | private static int OUT_END_ID = 8; |
---|
44 | |
---|
45 | private static int START_ID = 0; |
---|
46 | private static int END_ID = 17; |
---|
47 | |
---|
48 | private ResourceBundle powBundle; |
---|
49 | |
---|
50 | private TaskToApp taskToApp = new TaskToApp(); |
---|
51 | |
---|
52 | private static double [] knownLoadLevels = {0.25, 0.5, 0.75, 1}; |
---|
53 | |
---|
54 | public double estimateAirThroughput(EnergyEvent event, JobRegistry jobRegistry, ComputingResource resource) { |
---|
55 | |
---|
56 | double airThroughput = 0; |
---|
57 | try { |
---|
58 | if(event.getReason() == EventReason.SIM_INIT) |
---|
59 | airThroughput = resource.getAirThroughputInterface().getAirFlow(StandardAirThroughputStateName.FAN_OFF); |
---|
60 | else |
---|
61 | airThroughput = resource.getAirThroughputInterface().getAirFlow(resource.getAirThroughputInterface().getAirThroughputState()); |
---|
62 | } catch (NoSuchFieldException e) { |
---|
63 | // TODO Auto-generated catch block |
---|
64 | e.printStackTrace(); |
---|
65 | } |
---|
66 | |
---|
67 | Integer resId = Integer.parseInt(resource.getName().split("_")[1]); |
---|
68 | if(resId >= OUT_START_ID && resId <= OUT_END_ID){ |
---|
69 | for(ComputingResource compResource: resource.getParent().getChildren()){ |
---|
70 | Integer id = Integer.parseInt(compResource.getName().split("_")[1]); |
---|
71 | if(id - resId == 9 || id - resId == -9){ |
---|
72 | try { |
---|
73 | airThroughput = airThroughput + compResource.getAirThroughputInterface().getAirFlow(compResource.getAirThroughputInterface().getAirThroughputState())/2; |
---|
74 | } catch (NoSuchFieldException e) { |
---|
75 | |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | return airThroughput; |
---|
82 | //throw new RuntimeException("Not implemented."); |
---|
83 | } |
---|
84 | |
---|
85 | public double estimateTemperature(EnergyEvent event, JobRegistry jobRegistry, ComputingResource resource) { |
---|
86 | double tout = 0; |
---|
87 | double tin = 21.3; |
---|
88 | double Q = 0.0056085; |
---|
89 | double C = 1004; |
---|
90 | double delta1 = 1.780594389/2; |
---|
91 | double delta2 = 2.162043729/2; |
---|
92 | double ro = 1.168; |
---|
93 | double power1 = resource.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
94 | double power2 = 0; |
---|
95 | |
---|
96 | Integer resId = Integer.parseInt(resource.getName().split("_")[1]); |
---|
97 | |
---|
98 | for(ComputingResource compResource: resource.getParent().getChildren()){ |
---|
99 | Integer id = Integer.parseInt(compResource.getName().split("_")[1]); |
---|
100 | if(id - resId == 9 || id - resId == -9){ |
---|
101 | power2 = compResource.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
102 | |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | tout = tin + delta1 * (power1/(Q * C * ro)) + delta2 * (power2/(Q * C * ro));; |
---|
108 | return tout; |
---|
109 | /*double temperature = 0; |
---|
110 | ComputingNode node = (ComputingNode) resource; |
---|
111 | for(Processor cpu: node.getProcessors()){ |
---|
112 | try{ |
---|
113 | temperature = temperature + cpu.getThermalInterface().getRecentTemperature().getValue(); |
---|
114 | } catch (Exception e){ |
---|
115 | |
---|
116 | } |
---|
117 | } |
---|
118 | return temperature/2;*/ |
---|
119 | //return 100; |
---|
120 | } |
---|
121 | |
---|
122 | protected String createQuery(ExecTask task) { |
---|
123 | Executable exec = (Executable)task; |
---|
124 | Map<ResourceUnitName, ResourceUnit> allocatedResources = exec.getUsedResources().getLast().getResourceUnits(); |
---|
125 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
126 | |
---|
127 | String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getAppLoad(task); |
---|
128 | return query; |
---|
129 | } |
---|
130 | |
---|
131 | private String getApplicationType(ExecTask task){ |
---|
132 | AppType appType = taskToApp.getAppType(task); |
---|
133 | return appType.toString(); |
---|
134 | } |
---|
135 | |
---|
136 | private String getNodeCategory(PEUnit peUnit){ |
---|
137 | |
---|
138 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
139 | if(pe.get(0) instanceof ComputingNode) |
---|
140 | return ((ComputingNode)pe.get(0)).getCategory(); |
---|
141 | if(pe.get(0) instanceof Processor) |
---|
142 | return ((Processor)pe.get(0)).getParent().getCategory(); |
---|
143 | Core core = (Core)pe.get(0); |
---|
144 | return core.getParent().getParent().getCategory(); |
---|
145 | } |
---|
146 | |
---|
147 | private int getFrequency(PEUnit peUnit){ |
---|
148 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
149 | if(pe.get(0) instanceof ComputingNode) |
---|
150 | return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); |
---|
151 | if(pe.get(0) instanceof Processor) |
---|
152 | return Double.valueOf(((Processor)pe.get(0)).getPowerInterface().getFrequency()).intValue(); |
---|
153 | Core core = (Core)pe.get(0); |
---|
154 | Processor proc = (Processor) core.getParent(); |
---|
155 | double freq = proc.getPowerInterface().getFrequency(); |
---|
156 | return Double.valueOf(freq).intValue(); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | private double getAppLoad(ExecTask task){ |
---|
161 | double appLoad = taskToApp.getAppLoad(task); |
---|
162 | return appLoad; |
---|
163 | } |
---|
164 | |
---|
165 | protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{ |
---|
166 | ResourceBundle powBundle = getPowBundle(); |
---|
167 | double measuredPower = 0; |
---|
168 | try{ |
---|
169 | measuredPower = Double.valueOf(powBundle.getString(query)).doubleValue(); |
---|
170 | } catch(Exception e){ |
---|
171 | double queryLoad = Double.valueOf(query.split("\\.")[3] + "." + query.split("\\.")[4]).doubleValue(); |
---|
172 | |
---|
173 | double loadBelow = 0; |
---|
174 | double loadAbove = 0; |
---|
175 | |
---|
176 | for(int i = 0; i < knownLoadLevels.length; i++){ |
---|
177 | if(queryLoad > knownLoadLevels[i]){ |
---|
178 | loadBelow = knownLoadLevels[i]; |
---|
179 | loadAbove = knownLoadLevels[i+1]; |
---|
180 | } |
---|
181 | } |
---|
182 | String queryBelow = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + loadBelow; |
---|
183 | String queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + loadAbove; |
---|
184 | |
---|
185 | double measuredBelow = Double.valueOf(powBundle.getString(queryBelow)).doubleValue(); |
---|
186 | double measuredAbove = Double.valueOf(powBundle.getString(queryAbove)).doubleValue(); |
---|
187 | double a = (measuredAbove - measuredBelow)/(loadAbove - loadBelow); |
---|
188 | double b = measuredAbove - a * loadAbove; |
---|
189 | measuredPower = a * queryLoad + b; |
---|
190 | |
---|
191 | } |
---|
192 | return measuredPower; |
---|
193 | } |
---|
194 | |
---|
195 | private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ |
---|
196 | if(powBundle == null){ |
---|
197 | powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); |
---|
198 | } |
---|
199 | return powBundle; |
---|
200 | } |
---|
201 | } |
---|