source: DCWoRMS/trunk/src/test/ariel/FCFSCPUFreqScalingPlugin.java @ 506

Revision 506, 3.7 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.ariel;
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.events.scheduling.TaskFinishedEvent;
12import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent;
13import schedframe.resources.ResourceStatus;
14import schedframe.resources.computing.ComputingNode;
15import schedframe.resources.computing.ComputingResource;
16import schedframe.resources.computing.Processor;
17import schedframe.resources.units.Memory;
18import schedframe.resources.units.ProcessingElements;
19import schedframe.resources.units.ResourceUnit;
20import schedframe.resources.units.ResourceUnitName;
21import schedframe.resources.units.StandardResourceUnitName;
22import schedframe.scheduling.UsedResourcesList;
23import schedframe.scheduling.manager.resources.ClusterResourceManager;
24import schedframe.scheduling.manager.resources.ResourceManager;
25import schedframe.scheduling.manager.tasks.JobRegistry;
26import schedframe.scheduling.plan.SchedulingPlanInterface;
27import schedframe.scheduling.plan.impl.SchedulingPlan;
28import schedframe.scheduling.plugin.grid.ModuleList;
29import schedframe.scheduling.queue.TaskQueue;
30import schedframe.scheduling.queue.TaskQueueList;
31import schedframe.scheduling.tasks.TaskInterface;
32import schedframe.scheduling.tasks.WorkloadUnit;
33import dcworms.schedframe.scheduling.Executable;
34import example.localplugin.BaseLocalSchedulingPlugin;
35
36public 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}
Note: See TracBrowser for help on using the repository browser.