Custom Schedulers in the Maude Backend

This section describes how to specify the scheduling of processes beyond the basic non-deterministic scheduler. Processes are scheduled per cog. There are two places where schedulers can be specified:

  1. At a class definition. All cogs created via an object of the class will use the specified scheduling function.
  2. As an annotation to the new cog statement. This overrides any scheduler specified at class level.

Class-specific schedulers are implemented on the Maude backend and are under development on the dynamic Java backend.

Language Elements

All identifiers described in the following are contained in the module ABS.Scheduler.

A scheduler is a user-defined ABS function that chooses one process from a list of processes. A scheduler will be called with a list of processes which are eligible for execution on a specific object (and possibly some part of the object's state, see below) and returns the process that should execute on that object next. The user cannot currently influence which object is chosen to run by the cog.

The Process Datatype

data Pid;
data Process = Process(Pid pid, String method, Time arrival,
    Duration cost, Duration procdeadline, Time start, Time finish, Bool crit,
    Int value);

method contains the name of the method the process is running, arrival the time when the call arrived at the object, cost the specified cost of the process (or 0 when no cost annotation given), procdeadline is the deadline (or InfDuration when no deadline given at the call site). start and finish are bookkeeping values, and crit and value are currently unused but will contain criticality information and a user-defined priority for the process.

Note that it is not possible to create a value of type Process from within ABS itself, since the datatype Pid has no constructor.

Defining A Scheduler

A scheduler takes a list of Process values and returns one of them:

def Process randomscheduler(List<Process> queue) =
  nth(queue, random(length(queue)));

This scheduler, defined in the ABS.Scheduler module, chooses a random process from the list. It can be used for Monte-Carlo-simulations.

def Process defaultscheduler(List<Process> queue) = head(queue);

This is the default scheduler which is used by any class without an annotation specifying a different scheduler.

The Scheduler Annotation

The class annotation Scheduler specifies that objects of a given class should use a non-default scheduler.

[Scheduler: randomscheduler(queue)]
class Test { ... }

queue is a "magic" parameter name that at each invocation of the scheduler function contains the process queue of an object, lifted into an ABS value of type List<Process> .

Scheduling functions can have other parameters as well. In this case, the scheduler will be invoked with values from the current object state. The annotation specifies which fields of the object to pass for which parameter of the scheduler:

def Process experimental_scheduler(List<Process> queue, Int state) = ...

[Scheduler: experimental_scheduler(queue, attribute)]
class Test {
  Int attribute = 0;
  ...
}

Schedulers specified at class level can be overriden when creating a new cog. Here a cog is created with an object of class Test but with the default scheduler:

  [Scheduler: defaultscheduler(queue)] new Test();

Future Work

  • Parameters to the Scheduler annotation are not currently type-checked.
  • User-defined priorities via the value process member are not yet implemented
  • A true crit flag should lead to process failure when the deadline is exceeded. This can be implemented once ABS has a failure model.