1 | package test.ariel; |
---|
2 | |
---|
3 | import gridsim.dcworms.DCWormsTags; |
---|
4 | |
---|
5 | import java.util.ArrayList; |
---|
6 | import java.util.HashMap; |
---|
7 | import java.util.List; |
---|
8 | import java.util.Map; |
---|
9 | |
---|
10 | import schedframe.events.scheduling.SchedulingEvent; |
---|
11 | import schedframe.events.scheduling.TaskFinishedEvent; |
---|
12 | import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent; |
---|
13 | import schedframe.resources.ResourceStatus; |
---|
14 | import schedframe.resources.computing.ComputingNode; |
---|
15 | import schedframe.resources.computing.ComputingResource; |
---|
16 | import schedframe.resources.computing.Processor; |
---|
17 | import schedframe.resources.units.Memory; |
---|
18 | import schedframe.resources.units.ProcessingElements; |
---|
19 | import schedframe.resources.units.ResourceUnit; |
---|
20 | import schedframe.resources.units.ResourceUnitName; |
---|
21 | import schedframe.resources.units.StandardResourceUnitName; |
---|
22 | import schedframe.scheduling.UsedResourcesList; |
---|
23 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
24 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
25 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
26 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
27 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
28 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
29 | import schedframe.scheduling.queue.TaskQueue; |
---|
30 | import schedframe.scheduling.queue.TaskQueueList; |
---|
31 | import schedframe.scheduling.tasks.TaskInterface; |
---|
32 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
33 | import dcworms.schedframe.scheduling.Executable; |
---|
34 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
35 | |
---|
36 | public class FCFSCPUFreqScalingPlugin extends BaseLocalSchedulingPlugin { |
---|
37 | |
---|
38 | int cnt; |
---|
39 | |
---|
40 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
41 | ResourceManager resManager, ModuleList modules) { |
---|
42 | |
---|
43 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
44 | SchedulingPlan plan = new SchedulingPlan(); |
---|
45 | // chose the events types to serve. |
---|
46 | // Different actions for different events are possible. |
---|
47 | switch (event.getType()) { |
---|
48 | case START_TASK_EXECUTION: |
---|
49 | |
---|
50 | //case TIMER: |
---|
51 | // our tasks are placed only in first queue (see |
---|
52 | // BaseLocalPlugin.placeJobsInQueues() method) |
---|
53 | TaskQueue q = queues.get(0); |
---|
54 | |
---|
55 | // check all tasks in queue |
---|
56 | for (int i = 0; i < q.size(); i++) { |
---|
57 | WorkloadUnit job = q.get(i); |
---|
58 | TaskInterface<?> task = (TaskInterface<?>) job; |
---|
59 | // if status of the tasks in READY |
---|
60 | if (task.getStatus() == DCWormsTags.READY) { |
---|
61 | |
---|
62 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task); |
---|
63 | if (choosenResources != null) { |
---|
64 | addToSchedulingPlan(plan, task, choosenResources); |
---|
65 | } |
---|
66 | |
---|
67 | for(Processor cpu: resourceManager.getProcessors()){ |
---|
68 | cpu.getPowerInterface().setPState("P"+cnt); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | break; |
---|
73 | } |
---|
74 | cnt++; |
---|
75 | return plan; |
---|
76 | } |
---|
77 | |
---|
78 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
79 | ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
80 | |
---|
81 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(); |
---|
82 | List<Processor> processors = resourceManager.getProcessors(); |
---|
83 | int cpuRequest; |
---|
84 | try { |
---|
85 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
86 | } catch (NoSuchFieldException e) { |
---|
87 | cpuRequest = 1; |
---|
88 | } |
---|
89 | |
---|
90 | if (cpuRequest != 0) { |
---|
91 | |
---|
92 | List<Processor> choosenProcessor = new ArrayList<Processor>(); |
---|
93 | for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { |
---|
94 | if (processors.get(i).getStatus() == ResourceStatus.FREE) { |
---|
95 | choosenProcessor.add(processors.get(i)); |
---|
96 | cpuRequest--; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | ProcessingElements result = new ProcessingElements(); |
---|
101 | result.addAll(choosenProcessor); |
---|
102 | map.put(StandardResourceUnitName.PE, result); |
---|
103 | } |
---|
104 | |
---|
105 | return map; |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | } |
---|