1 | package example.timeestimation.coolemall; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import org.joda.time.DateTime; |
---|
6 | |
---|
7 | import schedframe.events.scheduling.SchedulingEvent; |
---|
8 | import schedframe.resources.computing.ComputingResource; |
---|
9 | import schedframe.resources.computing.Core; |
---|
10 | import schedframe.resources.computing.Processor; |
---|
11 | import schedframe.resources.units.PEUnit; |
---|
12 | import schedframe.resources.units.ProcessingElements; |
---|
13 | import schedframe.resources.units.ResourceUnit; |
---|
14 | import schedframe.resources.units.ResourceUnitName; |
---|
15 | import schedframe.resources.units.StandardResourceUnitName; |
---|
16 | import schedframe.scheduling.tasks.phases.ResourceConsumption; |
---|
17 | import dcworms.schedframe.scheduling.ExecTask; |
---|
18 | import dcworms.schedframe.scheduling.Executable; |
---|
19 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
20 | |
---|
21 | public 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 | } |
---|