package test.fips.models.fpga; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import dcworms.schedframe.scheduling.ExecTask; 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.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 gridsim.dcworms.DCWormsTags; public class FCFSBF_RandomPlugin extends BaseLocalSchedulingPlugin { private Random rand; public FCFSBF_RandomPlugin() { rand = new Random(175); } public SchedulingPlanInterface schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, ResourceManager resManager, ModuleList modules) { ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; List cpus = resourceManager.getProcessors(); SchedulingPlan plan = new SchedulingPlan(); // choose the events types to serve. // Different actions for different events are possible. switch (event.getType()) { 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(cpus, task); if (choosenResources != null) { addToSchedulingPlan(plan, task, choosenResources); } } } break; } return plan; } private Map chooseResourcesForExecution( List cpus, TaskInterface task) { Map map = new HashMap(1); int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 0; } if (cpuRequest != 0) { List choosenResources = new ArrayList(cpuRequest); for (int i = 0; i < cpus.size() && cpuRequest > 0; i++) { if (cpus.get(i).getStatus() == ResourceStatus.FREE) { choosenResources.add(cpus.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, int cpuRequest){ List filteredNodes = new ArrayList(); for (Node node : nodes) { if (cpuRequest != 0) { List cpus = node.getProcessors(); if (cpus.size() < cpuRequest) { if(cpus.size() == 0){ if(node.getProcessors().size() < cpuRequest) continue; } } int freeCpus = 0; for(Processor cpu: cpus){ if(cpu.getStatus() == ResourceStatus.FREE) freeCpus++; } if(freeCpus < cpuRequest) continue; filteredNodes.add(node); } } return filteredNodes; } private Node chooseRandomNode(List nodes) { int nodeIdx = rand.nextInt(nodes.size()); return nodes.get(nodeIdx); } }