package test.article2.recs.plugins.energy; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import schedframe.events.scheduling.EventReason; import schedframe.resources.computing.ComputingNode; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.Core; import schedframe.resources.computing.Processor; import schedframe.resources.computing.profiles.energy.EnergyEvent; import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.manager.tasks.JobRegistry; import test.article2.recs.utils.AppType; import test.article2.recs.utils.TaskToApp; import dcworms.schedframe.scheduling.ExecTask; import dcworms.schedframe.scheduling.Executable; import example.energy.BaseEnergyEstimationPlugin; public abstract class RecsNodeBaseEEP extends BaseEnergyEstimationPlugin{ private static String POWER_DATA_FILE_NAME = "src/test/article2/recs/data/power_data.properties"; private static int LEFT_ID = -1; private static int RIGHT_ID = +1; private static int BEHIND_ID = +9; private static int LEFT_BEHIND_ID = +8; private static int RIGHT_BEHIND_ID = +10; private static int OUT_START_ID = 0; private static int OUT_END_ID = 8; private static int START_ID = 0; private static int END_ID = 17; private ResourceBundle powBundle; private TaskToApp taskToApp = new TaskToApp(); private static double [] knownLoadLevels = {0.25, 0.5, 0.75, 1}; public double estimateAirThroughput(EnergyEvent event, JobRegistry jobRegistry, ComputingResource resource) { double airThroughput = 0; try { if(event.getReason() == EventReason.SIM_INIT) airThroughput = resource.getAirThroughputInterface().getAirFlow(StandardAirThroughputStateName.FAN_OFF); else airThroughput = resource.getAirThroughputInterface().getAirFlow(resource.getAirThroughputInterface().getAirThroughputState()); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } Integer resId = Integer.parseInt(resource.getName().split("_")[1]); if(resId >= OUT_START_ID && resId <= OUT_END_ID){ for(ComputingResource compResource: resource.getParent().getChildren()){ Integer id = Integer.parseInt(compResource.getName().split("_")[1]); if(id - resId == 9 || id - resId == -9){ try { airThroughput = airThroughput + compResource.getAirThroughputInterface().getAirFlow(compResource.getAirThroughputInterface().getAirThroughputState())/2; } catch (NoSuchFieldException e) { } } } } return airThroughput; //throw new RuntimeException("Not implemented."); } public double estimateTemperature(EnergyEvent event, JobRegistry jobRegistry, ComputingResource resource) { double tout = 0; double tin = 21.3; double Q = 0.0056085; double C = 1004; double delta1 = 1.780594389/2; double delta2 = 2.162043729/2; double ro = 1.168; double power1 = resource.getPowerInterface().getRecentPowerUsage().getValue(); double power2 = 0; Integer resId = Integer.parseInt(resource.getName().split("_")[1]); for(ComputingResource compResource: resource.getParent().getChildren()){ Integer id = Integer.parseInt(compResource.getName().split("_")[1]); if(id - resId == 9 || id - resId == -9){ power2 = compResource.getPowerInterface().getRecentPowerUsage().getValue(); } } tout = tin + delta1 * (power1/(Q * C * ro)) + delta2 * (power2/(Q * C * ro));; return tout; /*double temperature = 0; ComputingNode node = (ComputingNode) resource; for(Processor cpu: node.getProcessors()){ try{ temperature = temperature + cpu.getThermalInterface().getRecentTemperature().getValue(); } catch (Exception e){ } } return temperature/2;*/ //return 100; } protected String createQuery(ExecTask task) { Executable exec = (Executable)task; Map allocatedResources = exec.getUsedResources().getLast().getResourceUnits(); PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getAppLoad(task); return query; } private String getApplicationType(ExecTask task){ AppType appType = taskToApp.getAppType(task); return appType.toString(); } private String getNodeCategory(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof ComputingNode) return ((ComputingNode)pe.get(0)).getCategory(); if(pe.get(0) instanceof Processor) return ((Processor)pe.get(0)).getParent().getCategory(); Core core = (Core)pe.get(0); return core.getParent().getParent().getCategory(); } private int getFrequency(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof ComputingNode) return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); if(pe.get(0) instanceof Processor) return Double.valueOf(((Processor)pe.get(0)).getPowerInterface().getFrequency()).intValue(); Core core = (Core)pe.get(0); Processor proc = (Processor) core.getParent(); double freq = proc.getPowerInterface().getFrequency(); return Double.valueOf(freq).intValue(); } private double getAppLoad(ExecTask task){ double appLoad = taskToApp.getAppLoad(task); return appLoad; } protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{ ResourceBundle powBundle = getPowBundle(); double measuredPower = 0; try{ measuredPower = Double.valueOf(powBundle.getString(query)).doubleValue(); } catch(Exception e){ double queryLoad = Double.valueOf(query.split("\\.")[3] + "." + query.split("\\.")[4]).doubleValue(); double loadBelow = 0; double loadAbove = 0; for(int i = 0; i < knownLoadLevels.length; i++){ if(queryLoad > knownLoadLevels[i]){ loadBelow = knownLoadLevels[i]; loadAbove = knownLoadLevels[i+1]; } } String queryBelow = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + loadBelow; String queryAbove = query.split("\\.")[0] + "." + query.split("\\.")[1] + "." + query.split("\\.")[2] + "." + loadAbove; double measuredBelow = Double.valueOf(powBundle.getString(queryBelow)).doubleValue(); double measuredAbove = Double.valueOf(powBundle.getString(queryAbove)).doubleValue(); double a = (measuredAbove - measuredBelow)/(loadAbove - loadBelow); double b = measuredAbove - a * loadAbove; measuredPower = a * queryLoad + b; } return measuredPower; } private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ if(powBundle == null){ powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); } return powBundle; } }