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