[656] | 1 | package test.article.recs.plugins.energy; |
---|
| 2 | |
---|
| 3 | import java.io.FileInputStream; |
---|
| 4 | import java.io.FileNotFoundException; |
---|
| 5 | import java.io.IOException; |
---|
| 6 | import java.util.Map; |
---|
| 7 | import java.util.PropertyResourceBundle; |
---|
| 8 | import java.util.ResourceBundle; |
---|
| 9 | |
---|
[734] | 10 | import schedframe.resources.computing.ComputingNode; |
---|
[656] | 11 | import schedframe.resources.computing.Core; |
---|
| 12 | import schedframe.resources.computing.Processor; |
---|
| 13 | import schedframe.resources.units.PEUnit; |
---|
| 14 | import schedframe.resources.units.ProcessingElements; |
---|
| 15 | import schedframe.resources.units.ResourceUnit; |
---|
| 16 | import schedframe.resources.units.ResourceUnitName; |
---|
| 17 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 18 | import test.article.recs.utils.AppType; |
---|
| 19 | import test.article.recs.utils.TaskToApp; |
---|
| 20 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 21 | import dcworms.schedframe.scheduling.Executable; |
---|
| 22 | import example.energy.BaseEnergyEstimationPlugin; |
---|
| 23 | |
---|
| 24 | public abstract class RecsNodeBaseEEP extends BaseEnergyEstimationPlugin{ |
---|
| 25 | |
---|
[660] | 26 | private static String POWER_DATA_FILE_NAME = "src/test/article/recs/data/power_data.properties"; |
---|
| 27 | |
---|
| 28 | private ResourceBundle powBundle; |
---|
| 29 | |
---|
[656] | 30 | private TaskToApp taskToApp = new TaskToApp(); |
---|
| 31 | |
---|
| 32 | protected String createQuery(ExecTask task) { |
---|
| 33 | Executable exec = (Executable)task; |
---|
| 34 | Map<ResourceUnitName, ResourceUnit> allocatedResources = exec.getUsedResources().getLast().getResourceUnits(); |
---|
| 35 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
| 36 | |
---|
| 37 | String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task); |
---|
| 38 | return query; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | private String getApplicationType(ExecTask task){ |
---|
| 42 | AppType appType = taskToApp.getAppType(task); |
---|
| 43 | return appType.toString(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | private String getNodeCategory(PEUnit peUnit){ |
---|
| 47 | |
---|
| 48 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
[734] | 49 | if(pe.get(0) instanceof ComputingNode) |
---|
| 50 | return ((ComputingNode)pe.get(0)).getCategory(); |
---|
[656] | 51 | Core core = (Core)pe.get(0); |
---|
| 52 | return core.getParent().getParent().getCategory(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | private int getFrequency(PEUnit peUnit){ |
---|
| 56 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
[734] | 57 | if(pe.get(0) instanceof ComputingNode) |
---|
| 58 | return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); |
---|
[656] | 59 | Core core = (Core)pe.get(0); |
---|
| 60 | Processor proc = (Processor) core.getParent(); |
---|
[662] | 61 | double freq = proc.getPowerInterface().getFrequency(); |
---|
[656] | 62 | return Double.valueOf(freq).intValue(); |
---|
| 63 | |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | private int getCoreCnt(ExecTask task){ |
---|
| 67 | double cpuReq; |
---|
| 68 | try { |
---|
| 69 | cpuReq = task.getCpuCntRequest(); |
---|
| 70 | } catch (NoSuchFieldException e) { |
---|
| 71 | cpuReq = 1; |
---|
| 72 | } |
---|
| 73 | return Double.valueOf(cpuReq).intValue(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{ |
---|
[660] | 77 | ResourceBundle powBundle = getPowBundle(); |
---|
| 78 | return Double.valueOf(powBundle.getString(query)).doubleValue(); |
---|
[656] | 79 | } |
---|
[660] | 80 | |
---|
| 81 | private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ |
---|
| 82 | if(powBundle == null){ |
---|
| 83 | powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); |
---|
| 84 | } |
---|
| 85 | return powBundle; |
---|
| 86 | } |
---|
[656] | 87 | } |
---|