package test.stencils.plugins; import java.util.Map; import org.joda.time.DateTime; import schedframe.events.scheduling.SchedulingEvent; import schedframe.resources.computing.ComputingResource; 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 dcworms.schedframe.scheduling.ExecTask; import example.timeestimation.BaseTimeEstimationPlugin; public class StencilTimeEstimationPlugin extends BaseTimeEstimationPlugin{ /* * 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 completion percentage. * * Example implementation calculate the estimation based on processing power. * There is also a simple assumption, that processing power is a linear function * of number of allocated units and their speed. */ public double execTimeEstimation(SchedulingEvent event, ExecTask task, Map allocatedResources, double completionPercentage) { //String taskFreqString = task.getExecutionProfile().getCurrentResourceConsumption().getReferenceHardware().get("cpu_maxfreq"); //double taskFreq = Double.valueOf(taskFreqString); double speed = 0; PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); try { ProcessingElements pes = (ProcessingElements) peUnit; for (ComputingResource compResource : pes) { //System.out.println(new DateTime() + "; " + task.getId() + ";" + compResource.getFullName()); if(compResource instanceof Core) { Core core = (Core) compResource; speed = core.getProcessor().getPowerInterface().getPState().getFrequency(); break; } else if (compResource instanceof Processor) { Processor processor = (Processor) compResource; speed = processor.getPowerInterface().getPState().getFrequency(); break; } } } catch (Exception e){ speed = peUnit.getSpeed(); } //speed = taskFreq; int cnt = peUnit.getUsedAmount(); double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentExecutionPhase().getLenght() / (speed * cnt); //double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration() * (taskFreq / currentFrequency); //double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration(); // 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.round(execTime); return execTime; } }