[506] | 1 | package test.ariel; |
---|
| 2 | |
---|
| 3 | import java.util.ArrayList; |
---|
| 4 | import java.util.HashMap; |
---|
| 5 | import java.util.List; |
---|
| 6 | import java.util.Map; |
---|
| 7 | |
---|
| 8 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 9 | import schedframe.resources.ResourceStatus; |
---|
| 10 | import schedframe.resources.computing.Processor; |
---|
| 11 | import schedframe.resources.units.ProcessingElements; |
---|
| 12 | import schedframe.resources.units.ResourceUnit; |
---|
| 13 | import schedframe.resources.units.ResourceUnitName; |
---|
| 14 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 15 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 16 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 17 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 18 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 19 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
[1399] | 20 | import schedframe.scheduling.plugin.ModuleList; |
---|
[506] | 21 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 22 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 23 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 24 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
| 25 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
[1363] | 26 | import gridsim.dcworms.DCWormsTags; |
---|
[506] | 27 | |
---|
| 28 | public class FCFSCPUFreqScalingPlugin extends BaseLocalSchedulingPlugin { |
---|
| 29 | |
---|
| 30 | int cnt; |
---|
| 31 | |
---|
| 32 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
| 33 | ResourceManager resManager, ModuleList modules) { |
---|
| 34 | |
---|
| 35 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 36 | SchedulingPlan plan = new SchedulingPlan(); |
---|
| 37 | // chose the events types to serve. |
---|
| 38 | // Different actions for different events are possible. |
---|
| 39 | switch (event.getType()) { |
---|
| 40 | case START_TASK_EXECUTION: |
---|
| 41 | |
---|
| 42 | //case TIMER: |
---|
| 43 | // our tasks are placed only in first queue (see |
---|
| 44 | // BaseLocalPlugin.placeJobsInQueues() method) |
---|
| 45 | TaskQueue q = queues.get(0); |
---|
| 46 | |
---|
| 47 | // check all tasks in queue |
---|
| 48 | for (int i = 0; i < q.size(); i++) { |
---|
| 49 | WorkloadUnit job = q.get(i); |
---|
| 50 | TaskInterface<?> task = (TaskInterface<?>) job; |
---|
| 51 | // if status of the tasks in READY |
---|
| 52 | if (task.getStatus() == DCWormsTags.READY) { |
---|
| 53 | |
---|
| 54 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task); |
---|
| 55 | if (choosenResources != null) { |
---|
| 56 | addToSchedulingPlan(plan, task, choosenResources); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | for(Processor cpu: resourceManager.getProcessors()){ |
---|
| 60 | cpu.getPowerInterface().setPState("P"+cnt); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | break; |
---|
| 65 | } |
---|
| 66 | cnt++; |
---|
| 67 | return plan; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
| 71 | ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
| 72 | |
---|
| 73 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(); |
---|
| 74 | List<Processor> processors = resourceManager.getProcessors(); |
---|
| 75 | int cpuRequest; |
---|
| 76 | try { |
---|
| 77 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
| 78 | } catch (NoSuchFieldException e) { |
---|
| 79 | cpuRequest = 1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (cpuRequest != 0) { |
---|
| 83 | |
---|
| 84 | List<Processor> choosenProcessor = new ArrayList<Processor>(); |
---|
| 85 | for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { |
---|
| 86 | if (processors.get(i).getStatus() == ResourceStatus.FREE) { |
---|
| 87 | choosenProcessor.add(processors.get(i)); |
---|
| 88 | cpuRequest--; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | ProcessingElements result = new ProcessingElements(); |
---|
| 93 | result.addAll(choosenProcessor); |
---|
| 94 | map.put(StandardResourceUnitName.PE, result); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | return map; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | } |
---|