package experiments.e2dc2015.models.i5; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import schedframe.events.scheduling.SchedulingEvent; import schedframe.resources.ResourceStatus; import schedframe.resources.StandardResourceType; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.Core; import schedframe.resources.computing.Node; import schedframe.resources.computing.Processor; import schedframe.resources.computing.profiles.energy.ResourceEvent; import schedframe.resources.computing.profiles.energy.ResourceEventType; import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName; import schedframe.resources.devices.Device; import schedframe.resources.devices.Fan; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.manager.resources.ClusterResourceManager; import schedframe.scheduling.manager.resources.ResourceManager; import schedframe.scheduling.manager.tasks.JobRegistry; import schedframe.scheduling.plan.SchedulingPlanInterface; import schedframe.scheduling.plan.impl.SchedulingPlan; import schedframe.scheduling.plugin.ModuleList; import schedframe.scheduling.queue.TaskQueue; import schedframe.scheduling.queue.TaskQueueList; import schedframe.scheduling.tasks.TaskInterface; import simulator.DataCenterWorkloadSimulator; import eduni.simjava.Sim_system; import example.localplugin.BaseLocalSchedulingPlugin; import experiments.e2dc2015.EnvironmentConditions; import gridsim.dcworms.DCWormsTags; public class FCFSBF_RandomPluginFansMngStatic extends BaseLocalSchedulingPlugin { private Random rand; public FCFSBF_RandomPluginFansMngStatic() { rand = new Random(5); } public SchedulingPlanInterface schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, ResourceManager resManager, ModuleList modules) { ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; List nodes = resourceManager.getNodes(); SchedulingPlan plan = new SchedulingPlan(); // choose the events types to serve. // Different actions for different events are possible. switch (event.getType()) { case TIMER: System.out.println("##" + Sim_system.clock()); DataCenterWorkloadSimulator.getEventManager().sendToResources(StandardResourceType.Processor, 0.0, new ResourceEvent(ResourceEventType.TIMER, null)); //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(EnvironmentConditions.SYSTEM_UDPATE_INTERVAL, DCWormsTags.TIMER, "Test"); break; case START_TASK_EXECUTION: case TASK_FINISHED: // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method) TaskQueue q = queues.get(0); // check all tasks in queue for (int i = 0; i < q.size(); i++) { TaskInterface task = q.get(i); // if status of the tasks in READY if (task.getStatus() == DCWormsTags.READY) { Map choosenResources = chooseResourcesForExecution(nodes, task); if (choosenResources != null) { addToSchedulingPlan(plan, task, choosenResources); } } } break; case RESOURCE_TEMPERATURE_LIMIT_EXCEEDED: manageFans(resourceManager.getResourceByName(event.getSource())); break; } return plan; } private void manageFans(ComputingResource cr ){ //System.out.println("tuning fans"); double temp = cr.getThermalInterface().getRecentTemperature().getValue(); double prevTemp; if(cr.getThermalInterface().getTemperatureHistory().size() == 1) prevTemp = temp; else { prevTemp = cr.getThermalInterface().getTemperatureHistory().get(cr.getThermalInterface().getTemperatureHistory().size() - 2).getValue(); } //System.out.println(Sim_system.clock() + " === " + prevTemp+ "; " + temp); boolean getingHotter = prevTemp < temp; boolean getingColder = prevTemp > temp; Node n = (Node) cr.getParent(); List neighbours = n.getParent().getChildren(); for(Device d: n.getParent().getResourceCharacteristic().getDevices()){ //System.out.println(d.getName() + "; " + n.getName()); int fanId = Integer.valueOf(d.getName().split("_")[1]).intValue(); int nodeId = Integer.valueOf(n.getName().split("_")[1]).intValue(); 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*/){ Fan f = (Fan) d; int speed; try{ speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue(); } catch(Exception e){ speed = 0; } for(ComputingResource neighbour: neighbours){ int neighbourId = Integer.valueOf(neighbour.getName().split("_")[1]).intValue(); if(neighbourId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && neighbourId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN){ double neighbourTemp = neighbour.getChildren().get(0).getThermalInterface().getRecentTemperature().getValue(); if(neighbourTemp > temp){ return; } } } //System.out.println("getingHotter: "+ (prevTemp < temp)); if(getingHotter){ if(temp > EnvironmentConditions._30_2_70 - EnvironmentConditions.tempShift && temp < EnvironmentConditions._70_2_100- EnvironmentConditions.tempShift ){ if(speed < 70){ //System.out.println("+++++++++ low 2 medium"); f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70")); } } else if (temp > EnvironmentConditions._70_2_100- EnvironmentConditions.tempShift ) { if(speed < 100){ //System.out.println("++++++++high 2 high"); f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100")); } } } else if (getingColder){ if(temp > EnvironmentConditions._70_2_30 && temp < EnvironmentConditions._100_2_70){ if(speed == 100){ //System.out.println("-------- max 2 high"); f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70")); } } else if (temp < EnvironmentConditions._70_2_30) { if(speed >= 70){ //System.out.println("-------- medium 2 low"); f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30")); } } } } } } private Map chooseResourcesForExecution( List nodes, TaskInterface task) { Map map = new HashMap(1); int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 0; } List filteredNodes = filterNodes(nodes, task); if(filteredNodes.size()==0) return null; Node node = chooseRandomNode(filteredNodes); while(node.getFreeCores().size() < cpuRequest){ node = chooseRandomNode(nodes); } if (cpuRequest != 0) { if (node.getFreeCores().size() < cpuRequest) { return null; } List processors = node.getProcessors(); List cores = node.getCores(); List choosenResources = new ArrayList(cpuRequest); for (int i = 0; i < cores.size() && cpuRequest > 0; i++) { if (cores.get(i).getStatus() == ResourceStatus.FREE) { choosenResources.add(cores.get(i)); cpuRequest--; } } if (cpuRequest > 0) { return null; } ProcessingElements pe = new ProcessingElements(); pe.addAll(choosenResources); map.put(StandardResourceUnitName.PE, pe); return map; } return null; } private List filterNodes(List nodes, TaskInterface task){ List filteredNodes = new ArrayList(); int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 0; } for (Node node : nodes) { if (cpuRequest != 0) { List cores = node.getCores(); if (cores.size() < cpuRequest) { if(cores.size() == 0){ if(node.getProcessors().size() < cpuRequest) continue; } } int freeCores = 0; for(Core core: cores){ if(core.getStatus() == ResourceStatus.FREE) freeCores++; } if(freeCores < cpuRequest) continue; filteredNodes.add(node); } } return filteredNodes; } private Node chooseRandomNode(List nodes) { int nodeIdx = rand.nextInt(nodes.size()); return nodes.get(nodeIdx); } }