package example.timeestimation; import gssim.schedframe.scheduling.ExecTask; import java.util.Map; import schedframe.Parameters; import schedframe.PluginConfiguration; import schedframe.events.scheduling.SchedulingEvent; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; /** * * @author Marcin Krystek * */ public class DefaultTimeEstimationPlugin implements schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin{ /* * This method should return an estimation of time required to execute the task. * Requested calculation should be done based on the resources allocated for the task, * task description and task remaining length (in instructions). * * Example implementation calculate the estimation based on cpu processing power. * There is also a simple assumption, that cpu processing power is a linear function * of number of allocated cpus and their speed. */ public double execTimeEstimation(SchedulingEvent event, Map allocatedResources, ExecTask task, double completionPercentage) { // collect all information necessary to do the calculation PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); // obtain single pe speed int speed = peUnit.getSpeed(); // number of used pe int cnt = peUnit.getUsedAmount(); double remainingLength = task.getLength() * (1- completionPercentage); // do the calculation double execTime = (remainingLength / (cnt * speed)); // if the result is very close to 0, but less then one millisecond then round this result to 0.001 if (Double.compare(execTime, 0.001) < 0) { execTime = 0.001; } // time is measured in integer units, so get the nearest execTime int value. execTime = Math.ceil(execTime); return execTime; } public PluginConfiguration getConfiguration() { return null; } public String getName() { return "ExampleTimeEstimationPlugin"; } public void init(Parameters parameters) { } }