source: DCWoRMS/branches/coolemall/src/experiments/simpat2012/recs/plugins/scheduling/RecsExclusivenessEnOptDFSSP.java @ 1498

Revision 1498, 8.1 KB checked in by wojtekp, 10 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package experiments.simpat2012.recs.plugins.scheduling;
2
3import experiments.simpat2012.recs.utils.RecsProcessorPowerInterface;
4import gridsim.dcworms.DCWormsTags;
5
6import java.io.FileInputStream;
7import java.io.FileNotFoundException;
8import java.io.IOException;
9import java.util.ArrayList;
10import java.util.Collections;
11import java.util.Comparator;
12import java.util.HashMap;
13import java.util.List;
14import java.util.Map;
15import java.util.MissingResourceException;
16import java.util.PropertyResourceBundle;
17import java.util.ResourceBundle;
18
19import schedframe.events.scheduling.SchedulingEvent;
20import schedframe.resources.ResourceStatus;
21import schedframe.resources.computing.Node;
22import schedframe.resources.computing.ComputingResource;
23import schedframe.resources.computing.Core;
24import schedframe.resources.computing.Processor;
25import schedframe.resources.units.ProcessingElements;
26import schedframe.resources.units.ResourceUnit;
27import schedframe.resources.units.ResourceUnitName;
28import schedframe.resources.units.StandardResourceUnitName;
29import schedframe.scheduling.manager.resources.ClusterResourceManager;
30import schedframe.scheduling.manager.resources.ResourceManager;
31import schedframe.scheduling.manager.tasks.JobRegistry;
32import schedframe.scheduling.plan.SchedulingPlanInterface;
33import schedframe.scheduling.plan.impl.SchedulingPlan;
34import schedframe.scheduling.plugin.ModuleList;
35import schedframe.scheduling.queue.TaskQueue;
36import schedframe.scheduling.queue.TaskQueueList;
37import schedframe.scheduling.tasks.TaskInterface;
38
39public class RecsExclusivenessEnOptDFSSP extends RecsSP {
40
41        private static String TIME_DATA_FILE_NAME = "src/experiments/simpat2012/recs/data/time_data.properties";
42        private static String POWER_DATA_FILE_NAME = "src/experiments/simpat2012/recs/data/power_data.properties";
43       
44        private ResourceBundle powBundle;
45        private ResourceBundle timeBundle;
46       
47       
48        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
49                        ResourceManager resManager, ModuleList modules) {
50
51                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
52                SchedulingPlan plan = new SchedulingPlan();
53                // our tasks are placed only in first queue (see
54                // BaseLocalSchedulingPlugin.placeJobsInQueues() method)
55                TaskQueue q = queues.get(0);
56                // choose the events types to serve.
57                // Different actions for different events are possible.
58                switch (event.getType()) {
59               
60                case START_TASK_EXECUTION:
61                case TASK_FINISHED:
62                        // check all tasks in queue
63                        for (int i = 0; i < q.size(); i++) {
64                                TaskInterface<?> task = q.get(i);
65                                initApplicationType(task);
66                               
67                                // if status of the tasks in READY
68                                if (task.getStatus() == DCWormsTags.READY) {
69
70                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
71                                        if (choosenResources  != null) {
72                                                addToSchedulingPlan(plan, task, choosenResources);
73                                        }
74                                }
75                        }
76                        adjustFrequency(resourceManager.getProcessors());
77                }
78                return plan;
79        }
80       
81
82        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
83                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
84
85                Map<ResourceUnitName, ResourceUnit> map;
86                List<Node> nodes = resourceManager.getNodes();
87                Collections.sort(nodes, new EnergyComparator(task));
88                //System.out.println("*****");
89                for (Node node : nodes) {
90                        //System.out.println(node.getCategory());
91                        int cpuRequest;
92                        try {
93                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
94                        } catch (NoSuchFieldException e) {
95                                cpuRequest = 0;
96                        }
97
98                        if (cpuRequest != 0) {
99
100                                /*Properties properties = new Properties();
101                                properties.setProperty("type", StandardResourceType.Core.getName());
102                                properties.setProperty("status", ResourceStatus.FREE.toString());
103                                 */
104                                List<Core> cores = node.getProcessors().get(0).getCores();
105                                if (cores.size() < cpuRequest/* || node.getProcessors().get(0).filterDescendants(properties).size() != cores.size()*/) {
106                                        continue;
107                                }
108
109                                int freeCores = 0;
110                                for(Core core: cores){
111                                        if(core.getStatus() == ResourceStatus.FREE)
112                                                freeCores++;
113                                }
114                               
115                                if(freeCores != cores.size())
116                                        continue;
117                               
118                                try {
119                                        if(!getExecutiveness(createExecutivenessQuery(task, node)))
120                                                continue;
121                                } catch (FileNotFoundException e) {
122                                        continue;
123                                } catch (IOException e) {
124                                        continue;
125                                } catch (MissingResourceException e){
126                                        continue;
127                                }
128                               
129                                List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();                         
130                                for (int i = 0; i < cores.size(); i++) {
131                                        if (cores.get(i).getStatus() == ResourceStatus.FREE) {
132                                                //choosenResources.add(cores.get(i));
133                                                cpuRequest--;
134                                        }
135                                }
136                                choosenResources.add(node);
137                                if (cpuRequest > 0) {
138                                        //continue;
139                                }
140                                map = new HashMap<ResourceUnitName, ResourceUnit>();
141                                ProcessingElements pe = new ProcessingElements();
142                                pe.addAll(choosenResources);
143                                map.put(StandardResourceUnitName.PE, pe);
144                                return map;
145
146                        }
147                }
148       
149                return null;
150        }
151       
152
153       
154        protected String createQuery(TaskInterface<?> task, Node node) {
155                String query;
156                query = getApplicationType(task) + "." + getNodeCategory(node) + "." + getFrequency(node) + "." + getCoreCnt(task);
157                return query;
158        }
159
160        protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{
161                ResourceBundle powBundle = getPowBundle();
162                return Double.valueOf(powBundle.getString(query)).doubleValue();
163        }
164       
165        private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{
166                if(powBundle == null){
167                         powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME));
168                }
169                return powBundle;
170        }
171       
172        protected double getMeasuredTime(String query) throws FileNotFoundException, IOException{
173                ResourceBundle timeBundle = getTimeBundle();
174                return Double.valueOf(timeBundle.getString(query)).doubleValue();
175        }
176
177        private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{
178                if(timeBundle == null){
179                        timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME));
180                }
181                return timeBundle;
182        }
183        class EnergyComparator implements Comparator<Node>{
184                private TaskInterface<?> task;
185               
186                public EnergyComparator(TaskInterface<?> task){
187                        this.task = task;
188                }
189               
190            public int compare(Node node1, Node node2){   
191                double node1EU = Double.MAX_VALUE;
192                double node2EU = Double.MAX_VALUE;
193                try {
194                                node1EU = getMeasuredTime(createQuery(task, node1)) * getMeasuredPower(createQuery(task, node1));
195                        } catch (FileNotFoundException e) {
196
197                        } catch (IOException e) {
198
199                        } catch (MissingResourceException e){
200                               
201                        }
202                try {
203                                node2EU = getMeasuredTime(createQuery(task, node2)) * getMeasuredPower(createQuery(task, node2));
204                        } catch (FileNotFoundException e) {
205
206                        } catch (IOException e) {
207
208                        } catch (MissingResourceException e){
209                               
210                        }
211                if(node1EU > node2EU)
212                        return 1;
213                else if (node1EU < node2EU)
214                        return -1;
215                else return 0;
216           
217            }
218        }
219        private void adjustFrequency(List<Processor> processors){
220
221                for(Processor cpu: processors){
222                        RecsProcessorPowerInterface rppi = (RecsProcessorPowerInterface) cpu.getPowerInterface();
223                        int freeCores = 0;
224
225                        for(Core core: cpu.getCores()){
226                                if(core.getStatus() == ResourceStatus.FREE)
227                                        freeCores++;
228                        }
229                        if(freeCores == cpu.getCores().size()){
230                                if(cpu.getNode().getCategory().compareTo("Intel_i7") == 0){
231                                        rppi.setPState(rppi.getSupportedPStates().get("P13").getName());       
232                                } else if(cpu.getNode().getCategory().compareTo("AMD_Fusion") == 0){
233                                        rppi.setPState(rppi.getSupportedPStates().get("P1").getName());
234                                } else if(cpu.getNode().getCategory().compareTo("Atom_D510") == 0){
235                                        rppi.setPState(rppi.getSupportedPStates().get("P7").getName());
236                                }
237                        }
238                        else {
239                                if(cpu.getNode().getCategory().compareTo("Intel_i7") == 0){
240                                        rppi.setPState(rppi.getSupportedPStates().get("P13").getName());       
241                                } else if(cpu.getNode().getCategory().compareTo("AMD_Fusion") == 0){
242                                        rppi.setPState(rppi.getSupportedPStates().get("P1").getName());
243                                } else if(cpu.getNode().getCategory().compareTo("Atom_D510") == 0){
244                                        rppi.setPState(rppi.getSupportedPStates().get("P7").getName());
245                                }       
246                        }
247
248                }
249        }
250
251}
Note: See TracBrowser for help on using the repository browser.