source: DCWoRMS/branches/coolemall/src/test/ariel/FCFSCPUFreqScalingPlugin.java @ 1363

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