package example.timeestimation; import gssim.schedframe.scheduling.ExecTaskInterface; import java.util.List; import java.util.Map; import java.util.Properties; import schedframe.resources.units.ResourceUnit; import schedframe.scheduling.TaskInterface; import schedframe.scheduling.events.SchedulingEvent; import schedframe.scheduling.plugin.SchedulingPluginConfiguration; import schedframe.scheduling.utils.ResourceParameterName; import test.rewolucja.resources.ProcessingElements; import test.rewolucja.resources.physical.implementation.CPU; /** * * @author Marcin Krystek * */ public class ExecTimeEstimationPlugin implements schedframe.scheduling.plugin.estimation.ExecTimeEstimationPlugin{ /* * 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, ExecTaskInterface task, double completionPercentage) { // collect all information necessary to do the calculation ProcessingElements pes = (ProcessingElements) allocatedResources.get(ResourceParameterName.PROCESSINGELEMENTS); int speed = pes.getSpeed(); int cnt = pes.getAmount(); // number of used processors 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 SchedulingPluginConfiguration getConfiguration() { // This plugin in not expected to have any specific configuration. return null; } public String getName() { return "ExampleTimeEstimationPlugin"; } public void init(Properties properties) { /* * This method should be called by AbstractAllocationPolicy or any class that extends * AbstractAllocationPolicy. Default implementation does not invoke it. */ } }