source: DCWoRMS/trunk/src/example/localplugin/FCFSCPUFreqScalingClusterLocalPlugin.java @ 513

Revision 513, 4.1 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import gridsim.dcworms.DCWormsTags;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.List;
8import java.util.Map;
9
10import schedframe.events.scheduling.SchedulingEvent;
11import schedframe.resources.ResourceStatus;
12import schedframe.resources.computing.ComputingResource;
13import schedframe.resources.computing.Processor;
14import schedframe.resources.units.ProcessingElements;
15import schedframe.resources.units.ResourceUnit;
16import schedframe.resources.units.ResourceUnitName;
17import schedframe.resources.units.StandardResourceUnitName;
18import schedframe.scheduling.manager.resources.ClusterResourceManager;
19import schedframe.scheduling.manager.resources.ResourceManager;
20import schedframe.scheduling.manager.tasks.JobRegistry;
21import schedframe.scheduling.plan.SchedulingPlanInterface;
22import schedframe.scheduling.plan.impl.SchedulingPlan;
23import schedframe.scheduling.plugin.grid.ModuleList;
24import schedframe.scheduling.queue.TaskQueue;
25import schedframe.scheduling.queue.TaskQueueList;
26import schedframe.scheduling.tasks.TaskInterface;
27import schedframe.scheduling.tasks.WorkloadUnit;
28
29public class FCFSCPUFreqScalingClusterLocalPlugin extends BaseLocalSchedulingPlugin {
30
31        List<Processor> allocatedCPUs;
32        public FCFSCPUFreqScalingClusterLocalPlugin () {
33                allocatedCPUs = new ArrayList<Processor>();
34        }
35
36        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
37                        ResourceManager resManager, ModuleList modules) {
38
39                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
40                SchedulingPlan plan = new SchedulingPlan();
41                // our tasks are placed only in first queue (see
42                // BaseLocalPlugin.placeJobsInQueues() method)
43                TaskQueue q = queues.get(0);
44                // chose the events types to serve.
45                // Different actions for different events are possible.
46                switch (event.getType()) {
47               
48                case START_TASK_EXECUTION:
49                case TASK_FINISHED:
50                        // check all tasks in queue
51                        for (int i = 0; i < q.size(); i++) {
52                                TaskInterface<?> task = q.get(i);
53                                // if status of the tasks in READY
54                                if (task.getStatus() == DCWormsTags.READY) {
55
56                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
57                                        if (choosenResources  != null) {
58                                                addToSchedulingPlan(plan, task, choosenResources);
59                                        }
60                                }
61                        }
62                        adjustFrequency(resourceManager.getProcessors());
63                }
64                return plan;
65        }
66       
67        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
68                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
69
70                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>();
71
72                int cpuRequest;
73                try {
74                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
75                } catch (NoSuchFieldException e) {
76                        cpuRequest = 1;
77                }
78
79                if (cpuRequest != 0) {
80                        List<ComputingResource> choosenResources = null;
81                        List<Processor> processors = resourceManager.getProcessors();
82                        processors.removeAll(allocatedCPUs);
83                        if (processors.size() < cpuRequest) {
84                                // log.warn("Task requires more cpus than is availiable in this resource.");
85                                return null;
86                        }
87
88                        choosenResources = new ArrayList<ComputingResource>();
89
90                        for (int i = 0; i < processors.size() && cpuRequest > 0; i++) {
91                                if (processors.get(i).getStatus() == ResourceStatus.FREE) {
92                                        choosenResources.add(processors.get(i));
93                                        cpuRequest--;
94                                }
95                        }
96                        if (cpuRequest > 0) {
97                                // log.info("Task " + task.getJobId() + "_" + task.getId() +
98                                // " requires more cpus than is availiable in this moment.");
99                                return null;
100                        }
101
102                        ProcessingElements result = new ProcessingElements();
103                        result.addAll(choosenResources);
104                        map.put(StandardResourceUnitName.PE, result);
105                }
106                return map;
107        }
108       
109        private void adjustFrequency(List<Processor> processors){
110
111                for(Processor cpu: processors){
112                        if(cpu.getStatus() == ResourceStatus.FREE) {
113                                if(cpu.getPowerInterface().getSupportedPStates().containsKey("P3"))
114                                        cpu.getPowerInterface().setPState("P3");
115                        }
116                        else{
117                                if(cpu.getPowerInterface().getSupportedPStates().containsKey("P0"))
118                                        cpu.getPowerInterface().setPState("P0");
119                        }
120
121                }
122
123        }
124
125
126}
Note: See TracBrowser for help on using the repository browser.