1 | package example.timeestimation; |
---|
2 | |
---|
3 | import gssim.schedframe.scheduling.ExecTaskInterface; |
---|
4 | |
---|
5 | import java.util.List; |
---|
6 | import java.util.Map; |
---|
7 | import java.util.Properties; |
---|
8 | |
---|
9 | import schedframe.resources.units.ResourceUnit; |
---|
10 | import schedframe.scheduling.TaskInterface; |
---|
11 | import schedframe.scheduling.events.SchedulingEvent; |
---|
12 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
13 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
14 | import test.rewolucja.resources.ProcessingElements; |
---|
15 | import test.rewolucja.resources.physical.implementation.CPU; |
---|
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 | |
---|
41 | |
---|
42 | int speed = pes.getSpeed(); |
---|
43 | int cnt = pes.getAmount(); |
---|
44 | |
---|
45 | // number of used processors |
---|
46 | |
---|
47 | double remainingLength = task.getLength() * (1- completionPercentage); |
---|
48 | // do the calculation |
---|
49 | double execTime = (remainingLength / (cnt * speed)); |
---|
50 | |
---|
51 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
52 | if (Double.compare(execTime, 0.001) < 0) { |
---|
53 | execTime = 0.001; |
---|
54 | } |
---|
55 | |
---|
56 | // time is measured in integer units, so get the nearest execTime int value. |
---|
57 | execTime = Math.ceil(execTime); |
---|
58 | return execTime; |
---|
59 | } |
---|
60 | |
---|
61 | public SchedulingPluginConfiguration getConfiguration() { |
---|
62 | // This plugin in not expected to have any specific configuration. |
---|
63 | return null; |
---|
64 | } |
---|
65 | |
---|
66 | public String getName() { |
---|
67 | return "ExampleTimeEstimationPlugin"; |
---|
68 | } |
---|
69 | |
---|
70 | public void init(Properties properties) { |
---|
71 | /* |
---|
72 | * This method should be called by AbstractAllocationPolicy or any class that extends |
---|
73 | * AbstractAllocationPolicy. Default implementation does not invoke it. |
---|
74 | */ |
---|
75 | } |
---|
76 | |
---|
77 | } |
---|