source: DCWoRMS/branches/coolemall/src/experiments/e2dc2015/models/i5/FCFSBF_RandomPluginFansMngStatic.java @ 1593

Revision 1593, 9.0 KB checked in by wojtekp, 8 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package experiments.e2dc2015.models.i5;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7import java.util.Random;
8
9import schedframe.events.scheduling.SchedulingEvent;
10import schedframe.resources.ResourceStatus;
11import schedframe.resources.StandardResourceType;
12import schedframe.resources.computing.ComputingResource;
13import schedframe.resources.computing.Core;
14import schedframe.resources.computing.Node;
15import schedframe.resources.computing.Processor;
16import schedframe.resources.computing.profiles.energy.ResourceEvent;
17import schedframe.resources.computing.profiles.energy.ResourceEventType;
18import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName;
19import schedframe.resources.devices.Device;
20import schedframe.resources.devices.Fan;
21import schedframe.resources.units.ProcessingElements;
22import schedframe.resources.units.ResourceUnit;
23import schedframe.resources.units.ResourceUnitName;
24import schedframe.resources.units.StandardResourceUnitName;
25import schedframe.scheduling.manager.resources.ClusterResourceManager;
26import schedframe.scheduling.manager.resources.ResourceManager;
27import schedframe.scheduling.manager.tasks.JobRegistry;
28import schedframe.scheduling.plan.SchedulingPlanInterface;
29import schedframe.scheduling.plan.impl.SchedulingPlan;
30import schedframe.scheduling.plugin.ModuleList;
31import schedframe.scheduling.queue.TaskQueue;
32import schedframe.scheduling.queue.TaskQueueList;
33import schedframe.scheduling.tasks.TaskInterface;
34import simulator.DataCenterWorkloadSimulator;
35import eduni.simjava.Sim_system;
36import example.localplugin.BaseLocalSchedulingPlugin;
37import experiments.e2dc2015.EnvironmentConditions;
38import gridsim.dcworms.DCWormsTags;
39
40public class FCFSBF_RandomPluginFansMngStatic extends BaseLocalSchedulingPlugin {
41
42
43        private Random rand;
44       
45        public FCFSBF_RandomPluginFansMngStatic() {
46                rand = new Random(5);
47        }
48
49        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
50                        ResourceManager resManager, ModuleList modules) {
51
52
53                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
54                List<Node> nodes = resourceManager.getNodes();
55                SchedulingPlan plan = new SchedulingPlan();
56
57                // choose the events types to serve.
58                // Different actions for different events are possible.
59                switch (event.getType()) {
60               
61               
62                case TIMER:
63
64                        System.out.println("##" + Sim_system.clock());
65                        DataCenterWorkloadSimulator.getEventManager().sendToResources(StandardResourceType.Processor, 0.0, new ResourceEvent(ResourceEventType.TIMER, null));
66                        //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(EnvironmentConditions.SYSTEM_UDPATE_INTERVAL, DCWormsTags.TIMER, "Test");
67                        break;
68                       
69                case START_TASK_EXECUTION:
70                case TASK_FINISHED:
71
72                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
73                        TaskQueue q = queues.get(0);
74                        // check all tasks in queue
75
76                        for (int i = 0; i < q.size(); i++) {
77                                TaskInterface<?> task = q.get(i);
78                                // if status of the tasks in READY
79                                if (task.getStatus() == DCWormsTags.READY) {
80                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(nodes, task);
81                                        if (choosenResources != null) {
82                                                addToSchedulingPlan(plan, task, choosenResources);
83                                        }
84                                }
85                        }
86
87                        break;
88                case RESOURCE_TEMPERATURE_LIMIT_EXCEEDED:
89                        manageFans(resourceManager.getResourceByName(event.getSource()));
90                        break;
91
92                }       
93
94                return plan;
95        }
96       
97        private void manageFans(ComputingResource cr ){
98                //System.out.println("tuning fans");
99                double temp = cr.getThermalInterface().getRecentTemperature().getValue();
100                double prevTemp;
101                if(cr.getThermalInterface().getTemperatureHistory().size() == 1)
102                        prevTemp = temp;
103                else {
104                        prevTemp = cr.getThermalInterface().getTemperatureHistory().get(cr.getThermalInterface().getTemperatureHistory().size() - 2).getValue();
105                }
106
107                //System.out.println(Sim_system.clock() + " === " + prevTemp+  ";  " + temp);
108                boolean getingHotter = prevTemp < temp;
109                boolean getingColder = prevTemp > temp;
110                Node n = (Node) cr.getParent();
111                List<ComputingResource> neighbours = n.getParent().getChildren();
112                for(Device d: n.getParent().getResourceCharacteristic().getDevices()){
113                        //System.out.println(d.getName() + "; " + n.getName());
114                        int fanId = Integer.valueOf(d.getName().split("_")[1]).intValue();
115                        int nodeId = Integer.valueOf(n.getName().split("_")[1]).intValue();
116                        if(nodeId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && nodeId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN /*|| Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1]) - EnvironmentConditions.NODES_IN_A_ROW*/){
117                                Fan f = (Fan) d;
118                                int speed;
119                                try{
120                                        speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue();
121                                } catch(Exception e){
122                                        speed = 0;
123                                }
124                                for(ComputingResource neighbour: neighbours){
125                                        int neighbourId = Integer.valueOf(neighbour.getName().split("_")[1]).intValue();
126                                        if(neighbourId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && neighbourId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN){
127                                                double neighbourTemp = neighbour.getChildren().get(0).getThermalInterface().getRecentTemperature().getValue();
128                                                if(neighbourTemp > temp){
129                                                        return;
130                                                }
131                                        }
132                                }
133                                //System.out.println("getingHotter: "+ (prevTemp < temp));
134                                if(getingHotter){
135                                        if(temp > EnvironmentConditions._30_2_70 - EnvironmentConditions.tempShift && temp < EnvironmentConditions._70_2_100- EnvironmentConditions.tempShift ){
136                                                if(speed < 70){
137                                                        //System.out.println("+++++++++ low 2 medium");
138                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));
139                                                }
140                                        } else if (temp > EnvironmentConditions._70_2_100- EnvironmentConditions.tempShift ) {
141                                                if(speed < 100){
142                                                        //System.out.println("++++++++high 2 high");
143                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100"));
144                                                }
145                                        }                                       
146                                } else if (getingColder){
147                                        if(temp > EnvironmentConditions._70_2_30 && temp < EnvironmentConditions._100_2_70){
148                                                if(speed == 100){
149                                                        //System.out.println("-------- max 2 high");
150                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));
151                                                }
152                                        } else if (temp < EnvironmentConditions._70_2_30) {
153                                                if(speed >= 70){
154                                                        //System.out.println("-------- medium 2 low");
155                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30"));   
156                                                }
157                                        }
158                                }
159                        }
160                }
161        }
162        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
163                        List<Node> nodes, TaskInterface<?> task) {
164
165                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
166
167                int cpuRequest;
168                try {
169                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
170                } catch (NoSuchFieldException e) {
171                        cpuRequest = 0;
172                }
173
174                List<Node> filteredNodes = filterNodes(nodes, task);
175                if(filteredNodes.size()==0)
176                        return null;
177                Node node = chooseRandomNode(filteredNodes);
178                while(node.getFreeCores().size() < cpuRequest){
179                        node = chooseRandomNode(nodes);
180                }
181               
182                if (cpuRequest != 0) {
183
184                        if (node.getFreeCores().size() < cpuRequest) {
185                                return null;
186                        }
187
188                        List<Processor>  processors = node.getProcessors();
189                        List<Core> cores = node.getCores();
190                        List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);                               
191                        for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
192                                if (cores.get(i).getStatus() == ResourceStatus.FREE) {
193                                        choosenResources.add(cores.get(i));
194                                        cpuRequest--;
195                                }
196                        }
197                        if (cpuRequest > 0) {
198                                return null;
199                        }
200
201                        ProcessingElements pe = new ProcessingElements();
202                        pe.addAll(choosenResources);
203                        map.put(StandardResourceUnitName.PE, pe);
204                        return map;
205                }
206
207                return null;
208        }
209
210       
211        private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task){
212                List<Node> filteredNodes = new ArrayList<Node>();
213                int cpuRequest;
214                try {
215                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
216                } catch (NoSuchFieldException e) {
217                        cpuRequest = 0;
218                }
219                for (Node node : nodes) {
220
221                        if (cpuRequest != 0) {
222
223                                List<Core> cores = node.getCores();
224                                if (cores.size() < cpuRequest) {
225                                        if(cores.size() == 0){
226                                                if(node.getProcessors().size() < cpuRequest)
227                                                        continue;
228                                        }
229                                }
230
231                                int freeCores = 0;
232                                for(Core core: cores){
233                                        if(core.getStatus() == ResourceStatus.FREE)
234                                                freeCores++;
235                                }
236                               
237                                if(freeCores < cpuRequest)
238                                        continue;
239                               
240                                filteredNodes.add(node);
241                        }
242                }
243               
244                return filteredNodes;
245        }
246       
247
248        private Node chooseRandomNode(List<Node> nodes) {
249                int nodeIdx = rand.nextInt(nodes.size());
250                return nodes.get(nodeIdx);
251        }
252
253
254}
255
Note: See TracBrowser for help on using the repository browser.