package test.article.recs.plugins.timeestimation; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import java.util.MissingResourceException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import schedframe.events.scheduling.SchedulingEvent; import schedframe.resources.computing.Core; import schedframe.resources.computing.Processor; 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 test.article.recs.utils.AppType; import test.article.recs.utils.TaskToApp; import dcworms.schedframe.scheduling.ExecTask; import example.timeestimation.BaseTimeEstimationPlugin; public class RecsTimeEstimationPlugin extends BaseTimeEstimationPlugin{ private static String TIME_DATA_FILE_NAME = "src/test/article/recs/data/time_data.properties"; private static int TIME_FACTOR = 20; private ResourceBundle timeBundle; private TaskToApp taskToApp = new TaskToApp(); public double execTimeEstimation(SchedulingEvent event, ExecTask task, Map allocatedResources, double completionPercentage) { double execTime; PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); String query = createQuery(task, peUnit); try { execTime = TIME_FACTOR * (1 - completionPercentage/100) * getMeasuredTime(query); if (Double.compare(execTime, 0.001) < 0) { execTime = 0.001; } execTime = Math.round(execTime); } catch (FileNotFoundException e) { execTime = defaultEstimation(task, peUnit, completionPercentage); } catch (IOException e) { execTime = defaultEstimation(task, peUnit, completionPercentage); } catch(MissingResourceException e){ execTime = defaultEstimation(task, peUnit, completionPercentage); } return execTime; } private String createQuery(ExecTask task, PEUnit peUnit) { String query; query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(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; Core core = (Core)pe.get(0); return core.getParent().getParent().getCategory(); } private int getFrequency(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; Core core = (Core)pe.get(0); Processor proc = (Processor) core.getParent(); double freq; try{ freq = proc.getPowerInterface().getFrequency(); } catch(Exception e){ freq = 800; } return Double.valueOf(freq).intValue(); } private int getCoreCnt(ExecTask task){ double cpuReq; try { cpuReq = task.getCpuCntRequest(); } catch (NoSuchFieldException e) { cpuReq = 1; } return Double.valueOf(cpuReq).intValue(); } private double getMeasuredTime(String query) throws FileNotFoundException, IOException{ ResourceBundle timeBundle = getTimeBundle(); return Double.valueOf(timeBundle.getString(query)).doubleValue(); } private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{ if(timeBundle == null){ timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME)); } return timeBundle; } private double defaultEstimation(ExecTask task, PEUnit peUnit, double completionPercentage){ int speed = peUnit.getSpeed(); int cnt = peUnit.getUsedAmount(); double remainingLength = task.getLength() * (1 - completionPercentage/100); double execTime = (remainingLength / (cnt * speed)); if (Double.compare(execTime, 0.001) < 0) { execTime = 0.001; } execTime = Math.round(execTime); return execTime; } }