package test.ariel; import gridsim.dcworms.DCWormsTags; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import schedframe.events.scheduling.SchedulingEvent; import schedframe.events.scheduling.TaskFinishedEvent; import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent; import schedframe.resources.ResourceStatus; import schedframe.resources.computing.ComputingNode; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.Processor; import schedframe.resources.units.Memory; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.UsedResourcesList; 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.grid.ModuleList; import schedframe.scheduling.queue.TaskQueue; import schedframe.scheduling.queue.TaskQueueList; import schedframe.scheduling.tasks.TaskInterface; import schedframe.scheduling.tasks.WorkloadUnit; import dcworms.schedframe.scheduling.Executable; import example.localplugin.BaseLocalSchedulingPlugin; public class FCFSCPUFreqScalingPlugin extends BaseLocalSchedulingPlugin { int cnt; public SchedulingPlanInterface schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, ResourceManager resManager, ModuleList modules) { ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; SchedulingPlan plan = new SchedulingPlan(); // chose the events types to serve. // Different actions for different events are possible. switch (event.getType()) { case START_TASK_EXECUTION: //case TIMER: // our tasks are placed only in first queue (see // BaseLocalPlugin.placeJobsInQueues() method) TaskQueue q = queues.get(0); // check all tasks in queue for (int i = 0; i < q.size(); i++) { WorkloadUnit job = q.get(i); TaskInterface task = (TaskInterface) job; // if status of the tasks in READY if (task.getStatus() == DCWormsTags.READY) { Map choosenResources = chooseResourcesForExecution(resourceManager, task); if (choosenResources != null) { addToSchedulingPlan(plan, task, choosenResources); } for(Processor cpu: resourceManager.getProcessors()){ cpu.getPowerInterface().setPState("P"+cnt); } } } break; } cnt++; return plan; } private Map chooseResourcesForExecution( ClusterResourceManager resourceManager, TaskInterface task) { Map map = new HashMap(); List processors = resourceManager.getProcessors(); int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 1; } if (cpuRequest != 0) { List choosenProcessor = new ArrayList(); for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { if (processors.get(i).getStatus() == ResourceStatus.FREE) { choosenProcessor.add(processors.get(i)); cpuRequest--; } } ProcessingElements result = new ProcessingElements(); result.addAll(choosenProcessor); map.put(StandardResourceUnitName.PE, result); } return map; } }