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; |
---|
12 | import test.rewolucja.resources.ProcessingElements; |
---|
13 | |
---|
14 | |
---|
15 | /** |
---|
16 | * |
---|
17 | * @author Marcin Krystek |
---|
18 | * |
---|
19 | */ |
---|
20 | public class ExecTimeEstimationPlugin implements schedframe.scheduling.plugin.estimation.ExecTimeEstimationPlugin{ |
---|
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 remaining length (in instructions). |
---|
26 | * |
---|
27 | * Example implementation calculate the estimation based on cpu processing power. |
---|
28 | * There is also a simple assumption, that cpu processing power is a linear function |
---|
29 | * of number of allocated cpus and their speed. |
---|
30 | */ |
---|
31 | public double execTimeEstimation(SchedulingEvent event, |
---|
32 | Map<ResourceParameterName, ResourceUnit> allocatedResources, |
---|
33 | ExecTaskInterface task, double completionPercentage) { |
---|
34 | |
---|
35 | // collect all information necessary to do the calculation |
---|
36 | ProcessingElements pes = (ProcessingElements) allocatedResources.get(ResourceParameterName.PROCESSINGELEMENTS); |
---|
37 | |
---|
38 | // obtain single pe speed |
---|
39 | int speed = pes.getSpeed(); |
---|
40 | |
---|
41 | // number of used pe |
---|
42 | int cnt = pes.getUsedAmount(); |
---|
43 | |
---|
44 | double remainingLength = task.getLength() * (1- completionPercentage); |
---|
45 | // do the calculation |
---|
46 | double execTime = (remainingLength / (cnt * speed)); |
---|
47 | |
---|
48 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
49 | if (Double.compare(execTime, 0.001) < 0) { |
---|
50 | execTime = 0.001; |
---|
51 | } |
---|
52 | |
---|
53 | // time is measured in integer units, so get the nearest execTime int value. |
---|
54 | execTime = Math.ceil(execTime); |
---|
55 | return execTime; |
---|
56 | } |
---|
57 | |
---|
58 | public SchedulingPluginConfiguration getConfiguration() { |
---|
59 | // This plugin in not expected to have any specific configuration. |
---|
60 | return null; |
---|
61 | } |
---|
62 | |
---|
63 | public String getName() { |
---|
64 | return "ExampleTimeEstimationPlugin"; |
---|
65 | } |
---|
66 | |
---|
67 | public void init(Properties properties) { |
---|
68 | } |
---|
69 | |
---|
70 | } |
---|