Everything

CHAPTER 14 SCHEDULING FUNCTION


This chapter describes the scheduler of the RI600V4.
14.1 Outline
The scheduling functions provided by the RI600V4 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.
14.2 Processing Unit and Precedence
An application program is executed in the following processing units.
- Task
- Interrupt handler
- Cyclic handler
- Alarm handler
The various processing units are processed in the following order of precedence.
1 ) Interrupt handlers, cyclic handlers, alarm handlers
2 ) Scheduler
3 ) Tasks
The "scheduler" is the RI600V4's processing that schedules running task and dispatches to the task.
Since interrupt handler, cyclic handlers and alarm handlers have higher precedence than the scheduler, no tasks are executed while these handlers are executing. ( Refer to "14.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.
14.3 Task Drive Method
The RI600V4 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 RI600V4, 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
14.4 Task Scheduling Method
As task scheduling methods, the RI600V4 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 RI600V4 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 RI600V4 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.
14.4.1 Ready queue
The RI600V4 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 RI600V4'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 14-1 Implementation of Scheduling Method (Priority Level Method or FCFS Method)
- Create ready queue
In the RI600V4, 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.
14.5 Task Scheduling Lock Function
The RI600V4 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 14-2 Scheduling Lock Function
14.6 Idling
When there is no RUNNING or READY task, the RI600V4 enters an endless loop and waits for interrupts.
14.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 and alarm handler) is higher than task as shown in "14.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 14-3 Scheduling in Non-Tasks