CHAPTER 11 SCHEDULER
The scheduling functions provided by the RI78V4 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.
The RI78V4 employs the Event-driven system in which the scheduler is activated when an event (trigger) occurs.
Under the event-driven system of the RI78V4, the scheduler is activated upon occurrence of the events listed below and dispatch processing (task scheduling processing) is executed.
As task scheduling methods, the RI78V4 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 the RI78V4 scheduling.
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.
The same priority level can be defined for multiple tasks in the RI78V4. 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.
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 RI78V4'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.
In the RI78V4, the method of creating a ready queue is limited to "static creation by the Kernel Initialization Module".
Ready queues therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
- Static create
Static ready queue creation is realized by defining Task priority information in the system configuration file.
The RI78V4 executes ready queue creation processing based on data stored in information files, using the Kernel Initialization Module, and handles the created ready queues as management targets.
Static ready queue creation is realized by defining Task priority information in the system configuration file.
The RI78V4 executes ready queue creation processing based on data stored in information files, using the Kernel Initialization Module, and handles the created ready queues as management targets.
In the RI78V4, ready queues created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program.
The RI78V4 provides a function to change the queuing order of tasks from the processing program, explicitly switching the task execution order.
- rot_rdq, irot_rdq
These service calls re-queue the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order explicitly.
The following describes an example for coding this service call.
These service calls re-queue the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order explicitly.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/ #include <kernel_id.h> /*System information header file definition*/ void func_cychdr ( void ) { PRI tskpri = 8; /*Declares and initializes variable*/ /* ............ */ irot_rdq ( tskpri ); /*Rotate task precedence*/ /* ............ */ return; /*Terminate cyclic handler*/ } |
Note 1 This service call does not perform queuing of rotation requests. If no task is queued to the ready queue corresponding to the relevant priority, therefore, no processing is performed but it is not handled as an error.
Note 2 Round-robin scheduling can be implemented by issuing this service call via a cyclic handler in a constant cycle.
The RI78V4 provides a function to change the priority level of tasks from the processing program, explicitly switching the task execution order.
- chg_pri, ichg_pri
This service call changes the priority of the task specified by parameter tskid (current priority) to a value specified by parameter tskpri.
The following describes an example for coding this service call.
This service call changes the priority of the task specified by parameter tskid (current priority) to a value specified by parameter tskpri.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/ #include <kernel_id.h> /*System information header file definition*/ void func_task ( VP_INT exinf ) { ID tskid = ID_tskA; /*Declares and initializes variable*/ PRI tskpri = 9; /*Declares and initializes variable*/ /* ............ */ chg_pri ( tskid, tskpri ); /*Change task priority*/ /* ............ */ } |
Note If the target task is in the RUNNING or READY state after this service call is issued, this service call re-queues the task at the end of the ready queue corresponding to the priority specified by parameter tskpri, following priority change processing.
The RI78V4 provides a function to disable scheduler activation by referencing the system state from the processing program and explicitly prohibiting dispatch processing (task scheduling processing).
A task is moved to the dispatching disabled state by issuing the following service call from the processing program.
- dis_dsp
This service call changes the system status to the dispatching disabled state.
As a result, dispatch processing (task scheduling) is disabled from when this service call is issued until ena_dsp is issued.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when this service call is issued until ena_dsp is issued, the RI78V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until ena_dsp is issued, upon which the actual dispatch processing is performed in batch.
The following describes an example for coding this service call.
This service call changes the system status to the dispatching disabled state.
As a result, dispatch processing (task scheduling) is disabled from when this service call is issued until ena_dsp is issued.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when this service call is issued until ena_dsp is issued, the RI78V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until ena_dsp is issued, upon which the actual dispatch processing is performed in batch.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/ #include <kernel_id.h> /*System information header file definition*/ void func_task ( VP_INT exinf ) { /* ............ */ dis_dsp ( ); /*Disable dispatching*/ /* ............ */ /*Dispatching disabled state*/ ena_dsp ( ); /*Enable dispatching*/ /* ............ */ } |
Note 1 This service call does not perform queuing of disable requests. If the system is in the dispatching disabled state, therefore, no processing is performed but it is not handled as an error.
Note 2 The dispatching disabled state changed by issuing this service call must be cancelled before the task that issued this service call moves to the DORMANT state.
The dispatching disabled state is cancelled by issuing the following service call from the processing program.
- ena_dsp
This service call changes the system status to the dispatching enabled state.
As a result, dispatch processing (task scheduling) that has been disabled by issuing dis_dsp is enabled.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when dis_dsp is issued until this service call is issued, the RI78V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until this service call is issued, upon which the actual dispatch processing is performed in batch.
The following describes an example for coding this service call.
This service call changes the system status to the dispatching enabled state.
As a result, dispatch processing (task scheduling) that has been disabled by issuing dis_dsp is enabled.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when dis_dsp is issued until this service call is issued, the RI78V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until this service call is issued, upon which the actual dispatch processing is performed in batch.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/ #include <kernel_id.h> /*System information header file definition*/ void func_task ( VP_INT exinf ) { /* ............ */ dis_dsp ( ); /*Disable dispatching*/ /* ............ */ /*Dispatching disabled state*/ ena_dsp ( ); /*Enable dispatching*/ /* ............ */ } |
Note This service call does not queue enable requests. If the system is in the dispatching enabled state, therefore, no processing is performed but it is not handled as an error.
If a service call (ichg_pri, isig_sem, etc.) accompanying dispatch processing (task scheduling processing) is issued in order to quickly complete the processing in a non-task (cyclic handler, interrupt handler, etc.) during the interval until the processing in the non-task ends, the RI78V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until a return instruction is issued by the non-task, upon which the actual dispatch processing is performed in batch.
The following shows a processing flow when a service call that involves dispatch processing in a non-task is issued.
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 RI78V4 (task in the RUNNING or READY state) in the system.
In the RI78V4, the method of registering an idle routine is limited to "static registration by the Kernel Initialization Module".
Idle routines therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
- Static define
Static idle routine registration is realized by coding idle routines by using the prescribed function name idle_handler.
The RI78V4 executes idle routine registration processing based on relevant symbol information, using the Kernel Initialization Module, and handles the registered idle routines as management targets.
Static idle routine registration is realized by coding idle routines by using the prescribed function name idle_handler.
The RI78V4 executes idle routine registration processing based on relevant symbol information, using the Kernel Initialization Module, and handles the registered idle routines as management targets.
In the RI78V4, idle routines registered statically by the Kernel Initialization Module cannot be unregistered dynamically using a method such as issuing a service call from a processing program.
Moreover, the RI78V4 executes "original pre-processing" when passing control to the idle routine, as well as "original post-processing" when regaining control from the idle routine.
- Coding method
Code idle routines using C or assembly language in the format shown in "11.7.3 Basic form of idle routine".
Code idle routines using C or assembly language in the format shown in "11.7.3 Basic form of idle routine".
- Stack switching
The RI78V4 executes processing to switch to the system stack when passing control to the idle routine, and processing to switch to the stack for the switch destination processing program (system stack or task stack) when regaining control from the idle routine.
The user is therefore not required to code processing related to stack switching in idle routines.
The RI78V4 executes processing to switch to the system stack when passing control to the idle routine, and processing to switch to the stack for the switch destination processing program (system stack or task stack) when regaining control from the idle routine.
The user is therefore not required to code processing related to stack switching in idle routines.