source: DCWoRMS/trunk/src/test/article/recs/plugins/scheduling/RecsExclusivenessEnOptDFSSP.java @ 734

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