1 | package example.load; |
---|
2 | |
---|
3 | import schedframe.resources.computing.Processor; |
---|
4 | import schedframe.resources.computing.profiles.energy.EnergyEvent; |
---|
5 | import schedframe.resources.devices.PhysicalResource; |
---|
6 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
7 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
8 | import schedframe.scheduling.tasks.phases.PhaseBehaviour; |
---|
9 | import dcworms.schedframe.scheduling.ExecTask; |
---|
10 | |
---|
11 | public class ProcessorLoadEstimationPlugin extends BaseLoadEstimationPlugin{ |
---|
12 | |
---|
13 | public double estimateUtlization(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
14 | Processor proc = (Processor) resource; |
---|
15 | double sumCoresLoad = 0; |
---|
16 | |
---|
17 | double nrOfThreadsOnCpu = proc.getCores().size(); |
---|
18 | |
---|
19 | if(proc.getResourceCharacteristic().getParameters().get("threads") != null){ |
---|
20 | nrOfThreadsOnCpu = nrOfThreadsOnCpu * Integer.valueOf(proc.getResourceCharacteristic().getParameters().get("threads").get(0).getContent()).intValue(); |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | JobRegistry jr = new JobRegistryImpl(proc.getFullName()); |
---|
25 | for(ExecTask task: jr.getRunningTasks()){ |
---|
26 | double cpuUsage = 1 / nrOfThreadsOnCpu; |
---|
27 | |
---|
28 | for(PhaseBehaviour pb: task.getExecutionProfile().getCurrentResourceConsumption().getBehaviourList()){ |
---|
29 | if(pb.getResouceName().equals("PM_CPU_Usage")){ |
---|
30 | cpuUsage = pb.getUtilization(); |
---|
31 | } |
---|
32 | } |
---|
33 | sumCoresLoad = sumCoresLoad + cpuUsage; |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | double processorLoad = 100 * sumCoresLoad; |
---|
39 | double calendarLoad = resource.getLoadInterface().getLoadCalendar().getCurrentLoad(); |
---|
40 | double totalLoad = processorLoad + calendarLoad; |
---|
41 | if (totalLoad > 100) |
---|
42 | return 100; |
---|
43 | else return totalLoad; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | } |
---|