[104] | 1 | package example.timeestimation; |
---|
| 2 | |
---|
| 3 | import gssim.schedframe.scheduling.ExecTaskInterface; |
---|
| 4 | |
---|
| 5 | import java.util.Map; |
---|
| 6 | import java.util.Properties; |
---|
| 7 | |
---|
| 8 | import schedframe.resources.units.ResourceUnit; |
---|
| 9 | import schedframe.scheduling.events.SchedulingEvent; |
---|
| 10 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
| 11 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
[241] | 12 | import test.rewolucja.energy.profile.PState; |
---|
| 13 | import test.rewolucja.energy.profile.PStateType; |
---|
[104] | 14 | import test.rewolucja.resources.ProcessingElements; |
---|
[241] | 15 | import test.rewolucja.resources.physical.implementation.Processor; |
---|
[104] | 16 | |
---|
| 17 | |
---|
| 18 | /** |
---|
| 19 | * |
---|
| 20 | * @author Marcin Krystek |
---|
| 21 | * |
---|
| 22 | */ |
---|
| 23 | public class ExecTimeEstimationPlugin implements schedframe.scheduling.plugin.estimation.ExecTimeEstimationPlugin{ |
---|
| 24 | |
---|
| 25 | /* |
---|
| 26 | * This method should return an estimation of time required to execute the task. |
---|
| 27 | * Requested calculation should be done based on the resources allocated for the task, |
---|
| 28 | * task description and task remaining length (in instructions). |
---|
| 29 | * |
---|
| 30 | * Example implementation calculate the estimation based on cpu processing power. |
---|
| 31 | * There is also a simple assumption, that cpu processing power is a linear function |
---|
| 32 | * of number of allocated cpus and their speed. |
---|
| 33 | */ |
---|
| 34 | public double execTimeEstimation(SchedulingEvent event, |
---|
| 35 | Map<ResourceParameterName, ResourceUnit> allocatedResources, |
---|
| 36 | ExecTaskInterface task, double completionPercentage) { |
---|
| 37 | |
---|
| 38 | // collect all information necessary to do the calculation |
---|
| 39 | ProcessingElements pes = (ProcessingElements) allocatedResources.get(ResourceParameterName.PROCESSINGELEMENTS); |
---|
| 40 | |
---|
[184] | 41 | // obtain single pe speed |
---|
[104] | 42 | int speed = pes.getSpeed(); |
---|
[241] | 43 | |
---|
[184] | 44 | // number of used pe |
---|
| 45 | int cnt = pes.getUsedAmount(); |
---|
| 46 | |
---|
[104] | 47 | double remainingLength = task.getLength() * (1- completionPercentage); |
---|
| 48 | // do the calculation |
---|
[250] | 49 | |
---|
| 50 | |
---|
| 51 | int type = Integer.parseInt( task.getJobId()) % 4; |
---|
| 52 | |
---|
| 53 | double factor = 1; |
---|
| 54 | if( type == 0 && ((Processor)pes.get(0)).getComputingNode().getCategory().getName().equals("A")) |
---|
| 55 | { |
---|
[269] | 56 | factor = 0.5; |
---|
[250] | 57 | } |
---|
| 58 | |
---|
| 59 | double execTime = (remainingLength / (cnt * (double)speed * factor / 1000)); |
---|
| 60 | |
---|
[104] | 61 | |
---|
| 62 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
| 63 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 64 | execTime = 0.001; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // time is measured in integer units, so get the nearest execTime int value. |
---|
| 68 | execTime = Math.ceil(execTime); |
---|
[250] | 69 | |
---|
[104] | 70 | return execTime; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | public SchedulingPluginConfiguration getConfiguration() { |
---|
| 74 | // This plugin in not expected to have any specific configuration. |
---|
| 75 | return null; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | public String getName() { |
---|
| 79 | return "ExampleTimeEstimationPlugin"; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | public void init(Properties properties) { |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | } |
---|