1 | package test.thermal.recs.plugins.energy; |
---|
2 | |
---|
3 | import java.io.FileInputStream; |
---|
4 | import java.io.FileNotFoundException; |
---|
5 | import java.io.IOException; |
---|
6 | import java.util.Arrays; |
---|
7 | import java.util.HashMap; |
---|
8 | import java.util.List; |
---|
9 | import java.util.Map; |
---|
10 | import java.util.PropertyResourceBundle; |
---|
11 | import java.util.ResourceBundle; |
---|
12 | |
---|
13 | import schedframe.resources.computing.Node; |
---|
14 | import schedframe.resources.computing.Core; |
---|
15 | import schedframe.resources.computing.Processor; |
---|
16 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
17 | import schedframe.resources.devices.PhysicalResource; |
---|
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.thermal.recs.utils.AppType; |
---|
25 | import test.thermal.recs.utils.TaskToApp; |
---|
26 | import dcworms.schedframe.scheduling.ExecTask; |
---|
27 | import dcworms.schedframe.scheduling.Executable; |
---|
28 | |
---|
29 | public class RecsNodeModelEEP extends RecsNodeBaseEEP{ |
---|
30 | |
---|
31 | private static String POWER_DATA_FILE_NAME = "src/test/thermal/recs/data/power_data.properties"; |
---|
32 | private static String LOAD_DATA_FILE_NAME = "src/test/thermal/recs/data/load.properties"; |
---|
33 | |
---|
34 | private ResourceBundle loadBundle; |
---|
35 | |
---|
36 | private ResourceBundle powBundle; |
---|
37 | |
---|
38 | private TaskToApp taskToApp = new TaskToApp(); |
---|
39 | |
---|
40 | |
---|
41 | static int HIT = 0; |
---|
42 | static int MISSED = 0; |
---|
43 | |
---|
44 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
45 | PhysicalResource resource) { |
---|
46 | double powerConsumption = 0; |
---|
47 | Node node = (Node) resource; |
---|
48 | |
---|
49 | try { |
---|
50 | if(jobRegistry.getRunningTasks().size() > 0) { |
---|
51 | powerConsumption = powerConsumption + getMeasuredPower(createQuery(jobRegistry.getRunningTasks().get(0))); |
---|
52 | } |
---|
53 | else { |
---|
54 | for(Processor cpu: node.getProcessors()){ |
---|
55 | try{ |
---|
56 | //powerConsumption = powerConsumption + cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
57 | } catch (Exception e){ |
---|
58 | |
---|
59 | } |
---|
60 | } |
---|
61 | try { |
---|
62 | powerConsumption = powerConsumption + node.getPowerInterface().getPowerConsumption(node.getPowerInterface().getPowerState()); |
---|
63 | } catch (NoSuchFieldException e) { |
---|
64 | } |
---|
65 | } |
---|
66 | } catch (FileNotFoundException e) { |
---|
67 | // TODO Auto-generated catch block |
---|
68 | e.printStackTrace(); |
---|
69 | } catch (IOException e) { |
---|
70 | // TODO Auto-generated catch block |
---|
71 | e.printStackTrace(); |
---|
72 | } |
---|
73 | |
---|
74 | return powerConsumption; |
---|
75 | } |
---|
76 | |
---|
77 | private String getApplicationType(ExecTask task){ |
---|
78 | AppType appType = taskToApp.getAppType(task); |
---|
79 | return appType.toString(); |
---|
80 | } |
---|
81 | |
---|
82 | protected String createQuery(ExecTask task) { |
---|
83 | Executable exec = (Executable)task; |
---|
84 | Map<ResourceUnitName, ResourceUnit> allocatedResources = exec.getAllocatedResources().getLast().getResourceUnits(); |
---|
85 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
86 | |
---|
87 | String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task); |
---|
88 | return query; |
---|
89 | } |
---|
90 | |
---|
91 | private String getNodeCategory(PEUnit peUnit){ |
---|
92 | |
---|
93 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
94 | if(pe.get(0) instanceof Node) |
---|
95 | return ((Node)pe.get(0)).getCategory(); |
---|
96 | if(pe.get(0) instanceof Processor) |
---|
97 | return ((Processor)pe.get(0)).getParent().getCategory(); |
---|
98 | Core core = (Core)pe.get(0); |
---|
99 | return core.getParent().getParent().getCategory(); |
---|
100 | } |
---|
101 | |
---|
102 | private int getFrequency(PEUnit peUnit){ |
---|
103 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
104 | if(pe.get(0) instanceof Node) |
---|
105 | return Double.valueOf(((Node)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); |
---|
106 | if(pe.get(0) instanceof Processor) |
---|
107 | return Double.valueOf(((Processor)pe.get(0)).getPowerInterface().getFrequency()).intValue(); |
---|
108 | Core core = (Core)pe.get(0); |
---|
109 | Processor proc = (Processor) core.getParent(); |
---|
110 | double freq = proc.getPowerInterface().getFrequency(); |
---|
111 | return Double.valueOf(freq).intValue(); |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | private int getCoreCnt(ExecTask task){ |
---|
116 | double cpuReq; |
---|
117 | try { |
---|
118 | cpuReq = task.getCpuCntRequest(); |
---|
119 | } catch (NoSuchFieldException e) { |
---|
120 | cpuReq = 1; |
---|
121 | } |
---|
122 | return Double.valueOf(cpuReq).intValue(); |
---|
123 | } |
---|
124 | |
---|
125 | private double getAppLoad(ExecTask task){ |
---|
126 | double appLoad = taskToApp.getAppLoad(task); |
---|
127 | return appLoad; |
---|
128 | } |
---|
129 | |
---|
130 | protected double getMeasuredPowerOld(String query) throws FileNotFoundException, IOException{ |
---|
131 | |
---|
132 | HashMap<String, List<Integer>> knownCoreCntMap = new HashMap<String, List<Integer>>(); |
---|
133 | Integer [] knownCoreCntI = {1, 3, 5, 7}; |
---|
134 | List<Integer> knonwCoreCntListI = Arrays.asList(knownCoreCntI); |
---|
135 | knownCoreCntMap.put("Intel_i7", knonwCoreCntListI); |
---|
136 | |
---|
137 | |
---|
138 | Integer [] knownCoreCntA = {1, 3}; |
---|
139 | List<Integer> knonwCoreCntListA = Arrays.asList(knownCoreCntA); |
---|
140 | knownCoreCntMap.put("Atom_D510", knonwCoreCntListA); |
---|
141 | |
---|
142 | Integer [] knownCoreCntAF = {1}; |
---|
143 | List<Integer> knonwCoreCntListAF = Arrays.asList(knownCoreCntAF); |
---|
144 | knownCoreCntMap.put("AMD_Fusion", knonwCoreCntListAF); |
---|
145 | |
---|
146 | ResourceBundle powBundle = getPowBundle(); |
---|
147 | double measuredPower = 0; |
---|
148 | |
---|
149 | int coreCnt = Double.valueOf(query.split("\\.")[3]).intValue(); |
---|
150 | List<Integer> knonwCoreCntList = knownCoreCntMap.get(query.split("\\.")[1]); |
---|
151 | |
---|
152 | if(!knonwCoreCntList.contains(coreCnt)){ |
---|
153 | |
---|
154 | double coreBelow = 0; |
---|
155 | double coreAbove = 0; |
---|
156 | |
---|
157 | for(int i = 0; i < knonwCoreCntList.size(); i++){ |
---|
158 | if(coreCnt > knonwCoreCntList.get(i)){ |
---|
159 | coreBelow = knonwCoreCntList.get(i); |
---|
160 | coreAbove = knonwCoreCntList.get(i+1); |
---|
161 | } |
---|
162 | } |
---|
163 | String queryBelow = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + Double.valueOf(coreBelow).intValue(); |
---|
164 | String queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + Double.valueOf(coreAbove).intValue(); |
---|
165 | System.out.println(queryBelow); |
---|
166 | System.out.println(queryAbove); |
---|
167 | double measuredBelow = Double.valueOf(powBundle.getString(queryBelow)).doubleValue(); |
---|
168 | double measuredAbove = Double.valueOf(powBundle.getString(queryAbove)).doubleValue(); |
---|
169 | double a = (measuredAbove - measuredBelow)/(coreAbove/8 - coreBelow/8); |
---|
170 | double b = measuredAbove - a * coreAbove/8; |
---|
171 | measuredPower = a * coreCnt/8 + b; |
---|
172 | MISSED++; |
---|
173 | System.out.println("m:" + MISSED); |
---|
174 | } else { |
---|
175 | HIT++; |
---|
176 | System.out.println("h:" + HIT); |
---|
177 | measuredPower = Double.valueOf(powBundle.getString(query)).doubleValue(); |
---|
178 | } |
---|
179 | return measuredPower; |
---|
180 | } |
---|
181 | |
---|
182 | protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{ |
---|
183 | |
---|
184 | HashMap<String, List<Integer>> knownCoreCntMap = new HashMap<String, List<Integer>>(); |
---|
185 | Integer [] knownCoreCntI = {1, 8}; |
---|
186 | List<Integer> knonwCoreCntListI = Arrays.asList(knownCoreCntI); |
---|
187 | knownCoreCntMap.put("Intel_i7", knonwCoreCntListI); |
---|
188 | |
---|
189 | Integer [] knownCoreCntA = {1, 4}; |
---|
190 | List<Integer> knonwCoreCntListA = Arrays.asList(knownCoreCntA); |
---|
191 | knownCoreCntMap.put("Atom_D510", knonwCoreCntListA); |
---|
192 | |
---|
193 | Integer [] knownCoreCntAF = {1, 2}; |
---|
194 | List<Integer> knonwCoreCntListAF = Arrays.asList(knownCoreCntAF); |
---|
195 | knownCoreCntMap.put("AMD_Fusion", knonwCoreCntListAF); |
---|
196 | |
---|
197 | ResourceBundle powBundle = getPowBundle(); |
---|
198 | double measuredPower = 0; |
---|
199 | |
---|
200 | int coreCnt = Double.valueOf(query.split("\\.")[3]).intValue(); |
---|
201 | List<Integer> knonwCoreCntList = knownCoreCntMap.get(query.split("\\.")[1]); |
---|
202 | |
---|
203 | if(!knonwCoreCntList.contains(coreCnt)){ |
---|
204 | //double queryLoad = (double) coreCnt / 8; |
---|
205 | double queryLoad = getLoad(query); |
---|
206 | double loadBelow = 0; |
---|
207 | double loadAbove = 0; |
---|
208 | |
---|
209 | if(query.split("\\.")[1].equals("Intel_i7")){ |
---|
210 | loadBelow = 1; |
---|
211 | loadAbove = 8; |
---|
212 | } |
---|
213 | else if(query.split("\\.")[1].equals("Atom_D510")){ |
---|
214 | loadBelow = 1; |
---|
215 | loadAbove = 4; |
---|
216 | } |
---|
217 | else if(query.split("\\.")[1].equals("AMD_Fusion")){ |
---|
218 | loadBelow = 1; |
---|
219 | loadAbove = 2; |
---|
220 | } |
---|
221 | |
---|
222 | String queryBelow = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + 1; |
---|
223 | String queryAbove = null; |
---|
224 | if(query.split("\\.")[1].equals("Intel_i7")) |
---|
225 | queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + 8; |
---|
226 | else if(query.split("\\.")[1].equals("Atom_D510")) |
---|
227 | queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + 4; |
---|
228 | else if(query.split("\\.")[1].equals("AMD_Fusion")) |
---|
229 | queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + 2; |
---|
230 | |
---|
231 | System.out.println(queryBelow); |
---|
232 | System.out.println(queryAbove); |
---|
233 | loadAbove = getLoad(queryAbove); |
---|
234 | loadBelow = getLoad(queryBelow); |
---|
235 | double measuredBelow = Double.valueOf(powBundle.getString(queryBelow)).doubleValue(); |
---|
236 | double measuredAbove = Double.valueOf(powBundle.getString(queryAbove)).doubleValue(); |
---|
237 | double a = (measuredAbove - measuredBelow)/(loadAbove - loadBelow); |
---|
238 | double b = measuredAbove - a * loadAbove; |
---|
239 | measuredPower = a * queryLoad + b; |
---|
240 | MISSED++; |
---|
241 | System.out.println("m:" + MISSED); |
---|
242 | } else { |
---|
243 | HIT++; |
---|
244 | System.out.println("h:" + HIT); |
---|
245 | measuredPower = Double.valueOf(powBundle.getString(query)).doubleValue(); |
---|
246 | } |
---|
247 | return measuredPower; |
---|
248 | } |
---|
249 | |
---|
250 | private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ |
---|
251 | if(powBundle == null){ |
---|
252 | powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); |
---|
253 | } |
---|
254 | return powBundle; |
---|
255 | } |
---|
256 | |
---|
257 | protected double getLoad(String query) throws FileNotFoundException, IOException{ |
---|
258 | ResourceBundle loadBundle = getLoadBundle(); |
---|
259 | return Double.valueOf(loadBundle.getString(query)).doubleValue(); |
---|
260 | } |
---|
261 | |
---|
262 | private ResourceBundle getLoadBundle() throws FileNotFoundException, IOException{ |
---|
263 | if(loadBundle == null){ |
---|
264 | loadBundle = new PropertyResourceBundle(new FileInputStream(LOAD_DATA_FILE_NAME)); |
---|
265 | } |
---|
266 | return loadBundle; |
---|
267 | } |
---|
268 | |
---|
269 | |
---|
270 | } |
---|