Search in sources :

Example 11 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SimpleTaskScheduler method doSchedule.

private void doSchedule() {
    logger.finest("Executing doSchedule...");
    List<TaskInfo> choices = getSchedulableTasks();
    if (logger.isLoggable(Level.INFO))
        logger.info("COG " + cog.getID() + " scheduling choices: " + choices);
    if (choices.isEmpty()) {
        logger.info("Choices are empty!");
        runtime.doNextStep();
        return;
    }
    TaskInfo nextTask = schedule(choices);
    nextTask.hasBeenActivated = true;
    synchronized (this) {
        if (nextTask.isSuspended()) {
            suspendedTasks.remove(nextTask);
            nextTask.makeReady();
        } else {
            readyTasks.remove(nextTask);
        }
        activateTask(nextTask);
    }
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)

Example 12 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SimpleTaskScheduler method taskFinished.

protected void taskFinished() {
    logger.finest("Task finished getting monitor...");
    TaskInfo finishedTask = null;
    synchronized (this) {
        logger.finest("got monitor");
        finishedTask = activeTask;
        finishedTask.task.setFinished(true);
        activeTask = null;
        if (suspendedTasks.size() + readyTasks.size() > 0) {
            logger.finest("calling schedule...");
            schedule();
            logger.finest("schedule called");
        }
    }
    logger.finest("do next step");
    // we now have to wait for all tasks that waited for the future
    // of this task to give them the opportunity to add a schedule action
    // to the global scheduler, before we do this step
    runtime.doNextStep();
    logger.finest("next step done");
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)

Example 13 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SimpleTaskScheduler method unsuspendTasks.

private synchronized List<TaskInfo> unsuspendTasks() {
    List<TaskInfo> tasksWithSatisfiedGuards = new ArrayList<>(0);
    Iterator<TaskInfo> it = suspendedTasks.iterator();
    while (it.hasNext()) {
        TaskInfo task = it.next();
        if (task.guard.isTrue()) {
            if (task.guard.staysTrue()) {
                readyTasks.add(task);
                task.makeReady();
                it.remove();
            } else {
                tasksWithSatisfiedGuards.add(task);
            }
        }
    }
    return tasksWithSatisfiedGuards;
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) ArrayList(java.util.ArrayList)

Example 14 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SimpleTaskScheduler method await.

@Override
public void await(ABSGuard g) {
    SimpleSchedulerThread thread = null;
    TaskInfo newTask = null;
    TaskInfo currentTask = null;
    synchronized (this) {
        if (activeTask == null) {
            // while shutting down the activeTask might bee null
            return;
        }
        currentTask = activeTask;
        thread = currentTask.thread;
        currentTask.suspend(g);
        suspendedTasks.add(currentTask);
        activeTask = null;
        if (view != null)
            view.taskSuspended(currentTask.task.getView(), g);
        thread.setGuard(g);
        if (g.isTrue() || (suspendedTasks.size() + readyTasks.size()) > 1) {
            logger.fine("issuing a schedule");
            schedule();
        }
    }
    runtime.doNextStep();
    synchronized (this) {
        newTask = activeTask;
    }
    if (newTask != currentTask) {
        thread.await(g);
    }
    if (view != null)
        view.taskResumed(currentTask.task.getView(), g);
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)

Example 15 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class UserSchedulingStrategy method schedule.

@Override
public synchronized TaskInfo schedule(final TaskScheduler scheduler, final List<TaskInfo> schedulableTasks) {
    System.out.println(scheduler.getCOG().toString() + " Scheduling (" + schedulableTasks.size() + " processes in queue)...");
    // Remember TaskInfos based on their Pids to speed things up a little
    HashMap<Integer, TaskInfo> taskMap = new HashMap<>();
    // Convert List<TaskInfo> to ArrayList<ABSProcess>
    ArrayList<ABSProcess> processes = new ArrayList<>();
    for (TaskInfo taskInfo : schedulableTasks) {
        taskMap.put(taskInfo.task.getID(), taskInfo);
        // TODO set: pid, method, arrival, cost, deadline, start, finish, critical, value
        ABSProcess proc = new ABSProcess(// Or use taskInfo.id (long)??
        taskInfo.task.getID(), taskInfo.task.getCall().methodName(), taskInfo.task.getArrival(), taskInfo.task.getCost(), taskInfo.task.getDeadline(), taskInfo.task.getStart(), taskInfo.task.getFinish(), taskInfo.task.isCritical(), taskInfo.task.getValue());
        processes.add(proc);
    }
    logger.info(processes.toString());
    // Convert ArryList<ABSProcess> to ABS.StdLib.List of ABSProcess
    final Object queue = ListUtils.toABSList(processes);
    ABSProcess result = userschedule(queue);
    // Convert returned ABSValue (actually an ABSProcess) to TaskInfo
    int selectedPid = result.getPid();
    logger.info("scheduling Task " + selectedPid);
    return taskMap.get(selectedPid);
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ABSProcess(abs.backend.java.lib.types.ABSProcess)

Aggregations

TaskInfo (abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)15 ArrayList (java.util.ArrayList)7 TaskScheduler (abs.backend.java.scheduling.TaskScheduler)5 ScheduleAction (abs.backend.java.scheduling.ScheduleAction)4 ScheduleOptions (abs.backend.java.scheduling.ScheduleOptions)4 List (java.util.List)4 SchedulingStrategy (org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy)4 TotalScheduler (org.absmodels.abs.plugin.debug.scheduling.TotalScheduler)4 Test (org.junit.Test)4 ABSProcess (abs.backend.java.lib.types.ABSProcess)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2 DynamicException (abs.backend.java.codegeneration.dynamic.DynamicException)1 ABSClosure (abs.backend.java.lib.runtime.ABSClosure)1 ABSDynamicObject (abs.backend.java.lib.runtime.ABSDynamicObject)1 COG (abs.backend.java.lib.runtime.COG)1 ABSValue (abs.backend.java.lib.types.ABSValue)1 TaskStackFrameView (abs.backend.java.observing.TaskStackFrameView)1 TaskStackView (abs.backend.java.observing.TaskStackView)1 TaskView (abs.backend.java.observing.TaskView)1