[1605] | 1 | package test.stencils.plugins; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | import java.util.Map; |
---|
| 5 | |
---|
| 6 | import org.joda.time.DateTime; |
---|
| 7 | |
---|
| 8 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 9 | import schedframe.resources.computing.ComputingResource; |
---|
| 10 | import schedframe.resources.computing.Core; |
---|
| 11 | import schedframe.resources.computing.Processor; |
---|
| 12 | import schedframe.resources.units.PEUnit; |
---|
| 13 | import schedframe.resources.units.ProcessingElements; |
---|
| 14 | import schedframe.resources.units.ResourceUnit; |
---|
| 15 | import schedframe.resources.units.ResourceUnitName; |
---|
| 16 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 17 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 18 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
| 19 | |
---|
| 20 | public class StencilTimeEstimationPlugin extends BaseTimeEstimationPlugin{ |
---|
| 21 | |
---|
| 22 | /* |
---|
| 23 | * This method should return an estimation of time required to execute the task. |
---|
| 24 | * Requested calculation should be done based on the resources allocated for the task, |
---|
| 25 | * task description and task completion percentage. |
---|
| 26 | * |
---|
| 27 | * Example implementation calculate the estimation based on processing power. |
---|
| 28 | * There is also a simple assumption, that processing power is a linear function |
---|
| 29 | * of number of allocated units and their speed. |
---|
| 30 | */ |
---|
| 31 | public double execTimeEstimation(SchedulingEvent event, ExecTask task, |
---|
| 32 | Map<ResourceUnitName, ResourceUnit> allocatedResources, |
---|
| 33 | double completionPercentage) { |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | //String taskFreqString = task.getExecutionProfile().getCurrentResourceConsumption().getReferenceHardware().get("cpu_maxfreq"); |
---|
| 37 | //double taskFreq = Double.valueOf(taskFreqString); |
---|
| 38 | |
---|
| 39 | double speed = 0; |
---|
| 40 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
| 41 | try { |
---|
| 42 | ProcessingElements pes = (ProcessingElements) peUnit; |
---|
| 43 | for (ComputingResource compResource : pes) { |
---|
| 44 | //System.out.println(new DateTime() + "; " + task.getId() + ";" + compResource.getFullName()); |
---|
| 45 | if(compResource instanceof Core) { |
---|
| 46 | Core core = (Core) compResource; |
---|
| 47 | speed = core.getProcessor().getPowerInterface().getPState().getFrequency(); |
---|
| 48 | break; |
---|
| 49 | } else if (compResource instanceof Processor) { |
---|
| 50 | Processor processor = (Processor) compResource; |
---|
| 51 | speed = processor.getPowerInterface().getPState().getFrequency(); |
---|
| 52 | break; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | } catch (Exception e){ |
---|
| 56 | speed = peUnit.getSpeed(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | //speed = taskFreq; |
---|
| 60 | int cnt = peUnit.getUsedAmount(); |
---|
| 61 | |
---|
| 62 | double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentExecutionPhase().getLenght() / (speed * cnt); |
---|
| 63 | |
---|
| 64 | //double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration() * (taskFreq / currentFrequency); |
---|
| 65 | //double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration(); |
---|
| 66 | |
---|
| 67 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
| 68 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 69 | execTime = 0.001; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | // time is measured in integer units, so get the nearest execTime int value. |
---|
| 73 | execTime = Math.round(execTime); |
---|
| 74 | return execTime; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|