source: DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/CPUFreqScallingPhaseTimeEstimationPlugin.java @ 1299

Revision 1299, 2.4 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.timeestimation.coolemall;
2
3import java.util.Map;
4
5import org.joda.time.DateTime;
6
7import schedframe.events.scheduling.SchedulingEvent;
8import schedframe.resources.computing.ComputingResource;
9import schedframe.resources.computing.Core;
10import schedframe.resources.computing.Processor;
11import schedframe.resources.units.PEUnit;
12import schedframe.resources.units.ProcessingElements;
13import schedframe.resources.units.ResourceUnit;
14import schedframe.resources.units.ResourceUnitName;
15import schedframe.resources.units.StandardResourceUnitName;
16import schedframe.scheduling.tasks.phases.ResourceConsumption;
17import dcworms.schedframe.scheduling.ExecTask;
18import dcworms.schedframe.scheduling.Executable;
19import example.timeestimation.BaseTimeEstimationPlugin;
20
21public class CPUFreqScallingPhaseTimeEstimationPlugin extends BaseTimeEstimationPlugin{
22
23       
24        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
25                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
26                        double completionPercentage) {
27               
28                Executable exec = (Executable) task;
29                ResourceConsumption resConsumption = exec.getResourceConsumptionProfile().getCurrentResourceConsumption();
30                String taskFreqString = task.getCurrentResourceConsumption().getReferenceHardware().get("cpu_maxfreq");
31                double taskFreq = Double.valueOf(taskFreqString);
32               
33                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
34                double currentFrequency = 0;
35               
36                if(peUnit instanceof ProcessingElements){
37                        ProcessingElements pes = (ProcessingElements) peUnit;
38                        for (ComputingResource compResource : pes) {
39                                if(compResource instanceof Core) {
40                                        Core core = (Core) compResource;
41                                        currentFrequency = core.getProcessor().getPowerInterface().getPState().getFrequency();
42                                        break;
43                                } else if (compResource instanceof Processor) {
44                                        Processor processor = (Processor) compResource;
45                                        currentFrequency = processor.getPowerInterface().getPState().getFrequency();
46                                        break;
47                                }
48                        }
49                }
50                else
51                        currentFrequency = taskFreq;
52
53                double execTime = (1 - completionPercentage/100) * resConsumption.getDuration() * (taskFreq / currentFrequency);
54
55                // if the result is very close to 0, but less then one millisecond then round this result to 0.001
56                if (Double.compare(execTime, 0.001) < 0) {
57                        execTime = 0.001;
58                }
59
60                // time is measured in integer units, so get the nearest execTime int value.
61                execTime = Math.round(execTime);
62                return execTime;
63        }
64
65}
Note: See TracBrowser for help on using the repository browser.