[477] | 1 | package example.localplugin; |
---|
| 2 | |
---|
[493] | 3 | import gridsim.dcworms.DCWormsTags; |
---|
[477] | 4 | |
---|
| 5 | import java.util.ArrayList; |
---|
| 6 | import java.util.HashMap; |
---|
| 7 | import java.util.List; |
---|
| 8 | import java.util.Map; |
---|
| 9 | |
---|
| 10 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 11 | import schedframe.resources.ResourceStatus; |
---|
| 12 | import schedframe.resources.computing.ComputingResource; |
---|
| 13 | import schedframe.resources.computing.Processor; |
---|
| 14 | import schedframe.resources.units.ProcessingElements; |
---|
| 15 | import schedframe.resources.units.ResourceUnit; |
---|
| 16 | import schedframe.resources.units.ResourceUnitName; |
---|
| 17 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 18 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 19 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 20 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 21 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 22 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
| 23 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 24 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 25 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 26 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 27 | |
---|
[525] | 28 | public class FCFSBF_DFSClusterPlugin extends BaseLocalSchedulingPlugin { |
---|
[477] | 29 | |
---|
[481] | 30 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
[477] | 31 | ResourceManager resManager, ModuleList modules) { |
---|
| 32 | |
---|
| 33 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 34 | SchedulingPlan plan = new SchedulingPlan(); |
---|
| 35 | // our tasks are placed only in first queue (see |
---|
[531] | 36 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
[477] | 37 | TaskQueue q = queues.get(0); |
---|
[574] | 38 | // choose the events types to serve. |
---|
[477] | 39 | // Different actions for different events are possible. |
---|
| 40 | switch (event.getType()) { |
---|
| 41 | |
---|
| 42 | case START_TASK_EXECUTION: |
---|
| 43 | case TASK_FINISHED: |
---|
| 44 | // check all tasks in queue |
---|
| 45 | for (int i = 0; i < q.size(); i++) { |
---|
[513] | 46 | TaskInterface<?> task = q.get(i); |
---|
[477] | 47 | // if status of the tasks in READY |
---|
[481] | 48 | if (task.getStatus() == DCWormsTags.READY) { |
---|
[477] | 49 | |
---|
| 50 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task); |
---|
| 51 | if (choosenResources != null) { |
---|
| 52 | addToSchedulingPlan(plan, task, choosenResources); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | } |
---|
[512] | 56 | adjustFrequency(resourceManager.getProcessors()); |
---|
[477] | 57 | } |
---|
| 58 | return plan; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
| 62 | ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
| 63 | |
---|
| 64 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(); |
---|
| 65 | |
---|
| 66 | int cpuRequest; |
---|
| 67 | try { |
---|
| 68 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
| 69 | } catch (NoSuchFieldException e) { |
---|
[531] | 70 | cpuRequest = 0; |
---|
[477] | 71 | } |
---|
| 72 | |
---|
| 73 | if (cpuRequest != 0) { |
---|
| 74 | List<ComputingResource> choosenResources = null; |
---|
| 75 | List<Processor> processors = resourceManager.getProcessors(); |
---|
| 76 | if (processors.size() < cpuRequest) { |
---|
| 77 | // log.warn("Task requires more cpus than is availiable in this resource."); |
---|
| 78 | return null; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | choosenResources = new ArrayList<ComputingResource>(); |
---|
| 82 | |
---|
| 83 | for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { |
---|
| 84 | if (processors.get(i).getStatus() == ResourceStatus.FREE) { |
---|
| 85 | choosenResources.add(processors.get(i)); |
---|
| 86 | cpuRequest--; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | if (cpuRequest > 0) { |
---|
| 90 | // log.info("Task " + task.getJobId() + "_" + task.getId() + |
---|
| 91 | // " requires more cpus than is availiable in this moment."); |
---|
| 92 | return null; |
---|
| 93 | } |
---|
| 94 | |
---|
[569] | 95 | ProcessingElements pe = new ProcessingElements(); |
---|
| 96 | pe.addAll(choosenResources); |
---|
| 97 | map.put(StandardResourceUnitName.PE, pe); |
---|
[477] | 98 | } |
---|
| 99 | return map; |
---|
| 100 | } |
---|
[512] | 101 | |
---|
| 102 | private void adjustFrequency(List<Processor> processors){ |
---|
[477] | 103 | |
---|
[512] | 104 | for(Processor cpu: processors){ |
---|
| 105 | if(cpu.getStatus() == ResourceStatus.FREE) { |
---|
| 106 | if(cpu.getPowerInterface().getSupportedPStates().containsKey("P3")) |
---|
| 107 | cpu.getPowerInterface().setPState("P3"); |
---|
[477] | 108 | } |
---|
[512] | 109 | else{ |
---|
| 110 | if(cpu.getPowerInterface().getSupportedPStates().containsKey("P0")) |
---|
| 111 | cpu.getPowerInterface().setPState("P0"); |
---|
[477] | 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | } |
---|