Everything

CHAPTER 13 SCHEDULER


This chapter describes the scheduler of the RI850V4.
13.1 Outline
The scheduling functions provided by the RI850V4 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.
13.1.1 Drive Method
The RI850V4 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 RI850V4, the scheduler is activated upon occurrence of the events listed below and dispatch processing (task scheduling processing) is executed.
- Issue of service call that may cause task state transition
- Issue of instruction for returning from non-task (cyclic handler, interrupt handler, etc.)
- Occurrence of clock interrupt used when achieving TIME MANAGEMENT FUNCTIONS
- vsta_sch issue
13.1.2 Scheduling Method
As task scheduling methods, the RI850V4 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 subject to RI850V4 scheduling.
- Priority level method
A task with the highest priority level 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
The same priority level can be defined for multiple tasks in the RI850V4. Therefore, multiple tasks with the highest priority level, which is used as the criterion for task selection under the Priority level method, may exist simultaneously.
To remedy this, dispatch processing (task scheduling processing) is executed on a first come first served (FCFS) basis, and the task for which the longest interval of time has elapsed since it entered an executable state (READY state) is selected as the task to which the CPU use right is granted.
13.1.3 Ready queue
The RI850V4 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 RI850V4'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 13-1 Implementation of Scheduling Method (Priority Level Method or FCFS Method)
- Create ready queue
In the RI850V4, 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 priority using static API "MAX_PRI" in the system configuration file.
For details about the basic information "MAX_PRI", refer to "17.4.2 Basic information".
13.1.4 Scheduling Lock Function
The RI850V4 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 13-2 Scheduling Lock Function
The scheduling lock function can be implemented by issuing the following service call from the processing program.
13.2 User-Own Coding Module
To support various execution environments, the hardware-dependent processing (idle routine) that is required for the RI850V4 to execute processing is extracted from the scheduling facility as a user-own coding module.
This enhances portability to various execution environments and facilitates customization as well.
13.2.1 Idle Routine
The idle routine is a routine dedicated to idle processing that is extracted as a user-own coding module to utilize the standby function provided by the CPU (to achieve the low-power consumption system), and is called from the scheduler when there no longer remains a task subject to scheduling by the RI850V4 (task in the RUNNING or READY state) in the system.
The RI850V4 manages the states in which each idle routine may enter and idle routines themselves, by using management objects (idle routine control blocks) corresponding to idle routines one-to-one.
- Basic form of idle routine
Code idle routines by using the void type function that has no arguments.
The following shows the basic form of idle routine in C.
 #include    <kernel.h>              /*Standard header file definition*/
 
 void idlrtn (void)
 {
     /* ......... */
 
     return;                         /*Terminate idle routine*/
 }

- Internal processing of idle routine
The RI850V4 executes "original pre-processing" when passing control to the idle routine, as well as "original post-processing" when regaining control from the idle routine.
Therefore, note the following points when coding idle routines.
- Coding method
Code idle routines using C or assembly language.
When coding in C, they can be coded in the same manner as ordinary functions coded.
When coding in assembly language, code them according to the calling rules prescribed in the compiler used.
- Stack switching
The RI850V4 switches to the system stack specified in Basic information when passing control to an idle routine. Coding regarding stack switching is therefore not required in idle routines.
- Service call issue
The RI850V4 prohibits issue of service calls in idle routines.
- Acceptance of EI level maskable interrupts
When passing control to the idle routine, the RI850V4 enables acceptance of EI level maskable interrupts by manipulating the PMn bits in the priority mask register (PMR) and the ID bit in the program status word (PSW).
The PMn bits to be manipulated correspond to the interrupt priority range defined as the Maximum interrupt priority: maxintpri during configuration.
Note In most cases, control returns from the idle routine (moves to another processing program) if the wait time has passed or an EI level maskable interrupt occurs, do not issue the DI instruction in the idle routine.
13.2.2 Define Idle Routine
The RI850V4 supports the static registration of idle routines only. They cannot be registered dynamically by issuing a service call from the processing program.
Static idle routine registration means defining of idle routines using static API "VATT_IDL" in the system configuration file.
For details about the static API "VATT_IDL", refer to "17.5.13 Idle routine information".
Note If Idle routine information is not defined, the default idle routine (function name: _kernel_default_idlrtn) is registered during configuration.
The default idle routine issues the HALT instruction.
13.3 Scheduling in Non-Tasks
If a service call (isig_sem, iset_flg, etc.) accompanying dispatch processing (task scheduling processing) is issued in order to quickly complete the processing in the non-task (cyclic handler, interrupt handler, etc.) during the interval until the processing in the non-task ends, the RI850V4 executes only processing such as queue manipulation and the actual dispatch processing is delayed until a return instruction is issued, upon which the actual dispatch processing is performed in batch.
The following shows a processing flow when a service call accompanying dispatch processing is issued in a non-task.
Figure 13-3 Scheduling in Non-Tasks