Everything

CHAPTER 16 SCHEDULING FUNCTION


This chapter describes the scheduler of the RI600PX.
16.1 Outline
The scheduling functions provided by the RI600PX consist of functions manage/decide the order in which tasks are executed by monitoring the transition states of dynamically changing tasks, so that the CPU use right is given to the optimum task.
16.2 Processing Unit and Precedence
An application program is executed in the following processing units.
- Task (including task exception handling routine)
- Interrupt handler
- Cyclic handler
- Alarm handler
- Access exception handler
The various processing units are processed in the following order of precedence.
1 ) Interrupt handlers, cyclic handlers, alarm handlers
2 ) Access exception handler
3 ) Scheduler
4 ) Tasks (including task exception handling routines)
The "scheduler" is the RI600PX's processing that schedules running task and dispatches to the task.
Since interrupt handler, cyclic handlers, alarm handlers and access exception handler have higher precedence than the scheduler, no tasks and no task exception handling routines are executed while these handlers are executing. ( Refer to "16.7 Task Scheduling in Non-Tasks").
The precedence of an interrupt handler becomes higher when the interrupt level is higher.
The precedence of a cyclic handler and alarm handler is the same as the interrupt handler which interrupt level is same as the base clock timer interrupt.
The order of precedence for tasks depends on the current priority of the tasks.
16.3 Task Drive Method
The RI600PX employs the Event-driven system in which the scheduler is activated when an event (trigger) occurs.
- Event-driven system
Under the event-driven system of the RI600PX, the scheduler is activated upon occurrence of the events listed below and dispatch processing (task scheduling processing) is executed.
- Issuance of service call that may cause task state transition
- Issuance of instruction for returning from non-task (cyclic handler, interrupt handler, etc.)
- Occurrence of base clock interrupt used when achieving TIME MANAGEMENT FUNCTIONS
16.4 Task Scheduling Method
As task scheduling methods, the RI600PX employs the Priority level method, which uses the priority level defined for each task, and the FCFS method, which uses the time elapsed from the point when a task becomes target to RI600PX scheduling.
- Priority level method
A task with the highest current priority is selected from among all the tasks that have entered an executable state (RUNNING state or READY state), and given the CPU use right.
- FCFS method
When two or more "task with the highest priority level" exist, the scheduling target task can not be decided only by the Priority level method. In this case, the RI600PX decides the scheduling target task by first come first served (FCFS) method. Concretely, the task that enters to executable state (READY state) earliest among them, and given the CPU use right.
16.4.1 Ready queue
The RI600PX uses a "ready queue" to implement task scheduling.
The ready queue is a hash table that uses priority as the key, and tasks that have entered an executable state (READY state or RUNNING state) are queued in FIFO order. Therefore, the scheduler realizes the RI600PX's scheduling method (priority level or FCFS) by executing task detection processing from the highest priority level of the ready queue upon activation, and upon detection of queued tasks, giving the CPU use right to the first task of the proper priority level.
The following shows the case where multiple tasks are queued to a ready queue.
Figure 16-1 Implementation of Scheduling Method (Priority Level Method or FCFS Method)
- Create ready queue
In the RI600PX, the method of creating a ready queue is limited to "static creation".
Ready queues therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static ready queue creation means defining of Maximum task priority (priority) in System Information (system) in the system configuration file.
16.5 Task Scheduling Lock Function
The RI600PX provides the scheduling lock function for manipulating the scheduler status explicitly from the processing program and disabling/enabling dispatch processing.
The following shows a processing flow when using the scheduling lock function.
Figure 16-2 Scheduling Lock Function
16.6 Idling
When there is no RUNNING or READY task, the RI600PX enters an endless loop and waits for interrupts.
16.7 Task Scheduling in Non-Tasks
If processing of non-tasks starts, any tasks will not be performed until non-task processing is completed, since the precedence of non-task (interrupt handler, cyclic handler, alarm handler and access exception handler) is higher than task as shown in "16.2 Processing Unit and Precedence".
The following shows a example when a service call accompanying dispatch processing is issued in non-tasks. In this example, when the interrupt handler issues iwup_tsk, the Task A whose priority is higher than the task B is released from the WAITING state, but processing of the interrupt handler is continued at this time, without performing the task A yet. When processing of the interrupt handler is completed, the scheduler is started, and as a result, the task A is performed.
Figure 16-3 Scheduling in Non-Tasks