1 | package experiments.e2dc2015.models.arm; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.List; |
---|
6 | import java.util.Map; |
---|
7 | import java.util.Random; |
---|
8 | |
---|
9 | import schedframe.events.scheduling.SchedulingEvent; |
---|
10 | import schedframe.resources.ResourceStatus; |
---|
11 | import schedframe.resources.StandardResourceType; |
---|
12 | import schedframe.resources.computing.ComputingResource; |
---|
13 | import schedframe.resources.computing.Core; |
---|
14 | import schedframe.resources.computing.Node; |
---|
15 | import schedframe.resources.computing.Processor; |
---|
16 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
17 | import schedframe.resources.computing.profiles.energy.ResourceEventType; |
---|
18 | import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName; |
---|
19 | import schedframe.resources.devices.Device; |
---|
20 | import schedframe.resources.devices.Fan; |
---|
21 | import schedframe.resources.units.ProcessingElements; |
---|
22 | import schedframe.resources.units.ResourceUnit; |
---|
23 | import schedframe.resources.units.ResourceUnitName; |
---|
24 | import schedframe.resources.units.StandardResourceUnitName; |
---|
25 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
26 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
27 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
28 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
29 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
30 | import schedframe.scheduling.plugin.ModuleList; |
---|
31 | import schedframe.scheduling.queue.TaskQueue; |
---|
32 | import schedframe.scheduling.queue.TaskQueueList; |
---|
33 | import schedframe.scheduling.tasks.TaskInterface; |
---|
34 | import simulator.DataCenterWorkloadSimulator; |
---|
35 | import eduni.simjava.Sim_system; |
---|
36 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
37 | import experiments.e2dc2015.EnvironmentConditions; |
---|
38 | import gridsim.dcworms.DCWormsTags; |
---|
39 | |
---|
40 | public class FCFSBF_RandomPluginFansMng extends BaseLocalSchedulingPlugin { |
---|
41 | |
---|
42 | |
---|
43 | private Random rand; |
---|
44 | |
---|
45 | public FCFSBF_RandomPluginFansMng() { |
---|
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(prevTemp+ "; " + temp); |
---|
108 | boolean getingHotter = prevTemp < temp; |
---|
109 | boolean getingColder = prevTemp > temp; |
---|
110 | Node n = (Node) cr.getParent(); |
---|
111 | for(Device d: n.getParent().getResourceCharacteristic().getDevices()){ |
---|
112 | //System.out.println(d.getName() + "; " + n.getName()); |
---|
113 | if(Integer.valueOf(d.getName().split("_")[1]) == Integer.valueOf(n.getName().split("_")[1]) || Integer.valueOf(d.getName().split("_")[1]) == Integer.valueOf(n.getName().split("_")[1]) - EnvironmentConditions.NODES_IN_A_ROW){ |
---|
114 | Fan f = (Fan) d; |
---|
115 | int speed; |
---|
116 | try{ |
---|
117 | speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue(); |
---|
118 | } catch(Exception e){ |
---|
119 | speed = 0; |
---|
120 | } |
---|
121 | //System.out.println("getingHotter: "+ (prevTemp < temp)); |
---|
122 | if(getingHotter){ |
---|
123 | if(temp > EnvironmentConditions.tempLevelLow2Medium && temp < EnvironmentConditions.tempLevelMedium2High){ |
---|
124 | if(speed < 60){ |
---|
125 | //System.out.println("+++++++++ low 2 medium"); |
---|
126 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60")); |
---|
127 | } |
---|
128 | } else if (temp > EnvironmentConditions.tempLevelMedium2High && temp < EnvironmentConditions.tempLevelHigh2Max) { |
---|
129 | if(speed < 80){ |
---|
130 | //System.out.println("++++++++medium 2 high"); |
---|
131 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80")); |
---|
132 | } |
---|
133 | } else if (temp > EnvironmentConditions.tempLevelHigh2Max) { |
---|
134 | if(speed < 100){ |
---|
135 | //System.out.println("++++++++high 2 max"); |
---|
136 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100")); |
---|
137 | } |
---|
138 | } |
---|
139 | } else if (getingColder){ |
---|
140 | if(temp > EnvironmentConditions.tempLevelHigh2Medium && temp < EnvironmentConditions.tempLevelMax2High){ |
---|
141 | if(speed == 100){ |
---|
142 | //System.out.println("-------- max 2 high"); |
---|
143 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80")); |
---|
144 | } |
---|
145 | } else if(temp > EnvironmentConditions.tempLevelMedium2Low && temp < EnvironmentConditions.tempLevelHigh2Medium){ |
---|
146 | if(speed >= 80){ |
---|
147 | //System.out.println("-------- high 2 medium"); |
---|
148 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60")); |
---|
149 | } |
---|
150 | } else if (temp < EnvironmentConditions.tempLevelMedium2Low) { |
---|
151 | if(speed >= 60){ |
---|
152 | //System.out.println("-------- medium 2 low"); |
---|
153 | f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30")); |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
161 | List<Node> nodes, TaskInterface<?> task) { |
---|
162 | |
---|
163 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1); |
---|
164 | |
---|
165 | int cpuRequest; |
---|
166 | try { |
---|
167 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
168 | } catch (NoSuchFieldException e) { |
---|
169 | cpuRequest = 0; |
---|
170 | } |
---|
171 | |
---|
172 | List<Node> filteredNodes = filterNodes(nodes, task); |
---|
173 | if(filteredNodes.size()==0) |
---|
174 | return null; |
---|
175 | Node node = chooseRandomNode(filteredNodes); |
---|
176 | while(node.getFreeCores().size() < cpuRequest){ |
---|
177 | node = chooseRandomNode(nodes); |
---|
178 | } |
---|
179 | |
---|
180 | if (cpuRequest != 0) { |
---|
181 | |
---|
182 | if (node.getFreeCores().size() < cpuRequest) { |
---|
183 | return null; |
---|
184 | } |
---|
185 | |
---|
186 | List<Processor> processors = node.getProcessors(); |
---|
187 | List<Core> cores = node.getCores(); |
---|
188 | List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest); |
---|
189 | for (int i = 0; i < cores.size() && cpuRequest > 0; i++) { |
---|
190 | if (cores.get(i).getStatus() == ResourceStatus.FREE) { |
---|
191 | choosenResources.add(cores.get(i)); |
---|
192 | cpuRequest--; |
---|
193 | } |
---|
194 | } |
---|
195 | if (cpuRequest > 0) { |
---|
196 | return null; |
---|
197 | } |
---|
198 | |
---|
199 | ProcessingElements pe = new ProcessingElements(); |
---|
200 | pe.addAll(choosenResources); |
---|
201 | map.put(StandardResourceUnitName.PE, pe); |
---|
202 | return map; |
---|
203 | } |
---|
204 | |
---|
205 | return null; |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task){ |
---|
210 | List<Node> filteredNodes = new ArrayList<Node>(); |
---|
211 | int cpuRequest; |
---|
212 | try { |
---|
213 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
214 | } catch (NoSuchFieldException e) { |
---|
215 | cpuRequest = 0; |
---|
216 | } |
---|
217 | for (Node node : nodes) { |
---|
218 | |
---|
219 | if (cpuRequest != 0) { |
---|
220 | |
---|
221 | List<Core> cores = node.getCores(); |
---|
222 | if (cores.size() < cpuRequest) { |
---|
223 | if(cores.size() == 0){ |
---|
224 | if(node.getProcessors().size() < cpuRequest) |
---|
225 | continue; |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | int freeCores = 0; |
---|
230 | for(Core core: cores){ |
---|
231 | if(core.getStatus() == ResourceStatus.FREE) |
---|
232 | freeCores++; |
---|
233 | } |
---|
234 | |
---|
235 | if(freeCores < cpuRequest) |
---|
236 | continue; |
---|
237 | |
---|
238 | filteredNodes.add(node); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | return filteredNodes; |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | private Node chooseRandomNode(List<Node> nodes) { |
---|
247 | int nodeIdx = rand.nextInt(nodes.size()); |
---|
248 | return nodes.get(nodeIdx); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | } |
---|
253 | |
---|