CHAPTER 13 SCHEDULER
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.
The RI850V4 employs the Event-driven system in which the scheduler is activated when an event (trigger) occurs.
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.
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.
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 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.
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 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.
- 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".
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".
The RI850V4 provides the scheduling lock function for manipulating the scheduler status explicitly from the processing program and disabling/enabling dispatch processing.
The scheduling lock function can be implemented by issuing the following service call from the processing program.
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.
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.
#include <kernel.h> /*Standard header file definition*/ void idlrtn (void) { /* ......... */ return; /*Terminate 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.
- 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.
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.
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.
- 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.
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.
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.
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.
The default idle routine issues the HALT instruction.
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.