source: xssim/branches/tpiontek/src/example/timeestimation/ExecTimeEstimationPlugin.java @ 241

Revision 241, 2.4 KB checked in by piontek, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.timeestimation;
2
3import gssim.schedframe.scheduling.ExecTaskInterface;
4
5import java.util.Map;
6import java.util.Properties;
7
8import schedframe.resources.units.ResourceUnit;
9import schedframe.scheduling.events.SchedulingEvent;
10import schedframe.scheduling.plugin.SchedulingPluginConfiguration;
11import schedframe.scheduling.utils.ResourceParameterName;
12import test.rewolucja.energy.profile.PState;
13import test.rewolucja.energy.profile.PStateType;
14import test.rewolucja.resources.ProcessingElements;
15import test.rewolucja.resources.physical.implementation.Processor;
16
17
18/**
19 *
20 * @author Marcin Krystek
21 *
22 */
23public 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                // obtain single pe speed
42                int speed = pes.getSpeed();
43               
44                // number of used pe 
45                int cnt = pes.getUsedAmount();
46
47                double remainingLength =  task.getLength() * (1- completionPercentage);
48                // do the calculation
49                double execTime = (remainingLength / (cnt * speed/1000));
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
73}
Note: See TracBrowser for help on using the repository browser.