T-Kernel Specification (1.B0.02)
T-Kernel Specification (1.B0.02)
T-Kernel Specification (1.B0.02)
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
10 CHAPTER 2. CONCEPTS UNDERLYING THE T-KERNEL SPECIFICATION<br />
tasks is determined as follows based on the priority of each task. If there are multiple tasks that can be<br />
run, the one with the highest precedence goes to RUN state and the others go to READY state.<br />
In determining precedence among tasks, of those tasks having different priority levels, that with the<br />
highest priority has the highest precedence. Among tasks having the same priority, the one first going<br />
to a run state (RUN state or READY state) has the highest precedence. It is possible, however, to use<br />
a system call to change the precedence among tasks having the same priority.<br />
When the task with the highest precedence changes from one task to another, a dispatch occurs immediately<br />
and the task in RUN state is switched over. If no dispatch occurs, however, the switching of the<br />
task in RUN state is held off until dispatch occurs.<br />
Additional Note<br />
According to the scheduling rules adopted in the T-<strong>Kernel</strong> specification, so long as there is a highprecedence<br />
task in a run state, a task with lower precedence will simply not run. That is, unless the<br />
highest-precedence goes to WAIT state or for other reason cannot run, other tasks are not run. This is a<br />
fundamental difference from TSS (Time Sharing System) scheduling in which multiple tasks are treated<br />
equally. It is possible, however, to issue a system call changing the precedence among tasks having the<br />
same priority. An application can use such a system call to realize round-robin scheduling, which is a<br />
typical kind of TSS scheduling.<br />
precedence<br />
priority<br />
Hight 〈Priority 1〉<br />
✻<br />
〈Priority 2〉<br />
✲ Task A ✲<br />
✲ Task B ✲ Task C ✲ Task D ✲<br />
❄<br />
Low 〈Priority 3〉<br />
✲<br />
Task E<br />
✲<br />
Figure 2.2: Precedence in Initial State<br />
Figure 2.2 and following illustrate how the task that first goes to a run state (RUN state or READY<br />
state) gains precedence among tasks having the same priority. Figure 2.2 shows the precedence among<br />
tasks after Task A of priority 1, Task E of priority 3, and Tasks B, C and D of priority 2 are started in<br />
that order. The task with the highest precedence, Task A, goes to RUN state.<br />
When Task A exits, Task B with the next-highest precedence goes to RUN state (Figure 2.3). When<br />
Task A is again started, Task B is preempted and reverts to READY state; but since Task B went to<br />
a run state earlier than Task C and Task D, it still has the highest precedence among tasks with the<br />
same priority. In other words, the task precedence reverts to that in Figure 2.2.<br />
Next, consider what happens when Task B goes to WAIT state in the conditions in Figure 2.3. Since<br />
task precedence is defined among tasks that can be run, the precedence among tasks becomes as shown<br />
in Figure 2.4. Thereafter when the Task B wait state is released, Task B went to run state after Task<br />
C and Task D, and thus assumes the lowest precedence among tasks of the same priority (Figure 2.5).<br />
Summarizing the above, immediately after a task that went from READY state to RUN state reverts<br />
to READY state, it has the highest precedence among tasks of the same priority; but after a task goes<br />
from RUN state to WAIT state and then the wait is released, its precedence is the lowest among tasks<br />
of the same priority.<br />
Copyright c○ 2002, 2003 by T-Engine Forum<br />
T-<strong>Kernel</strong> <strong>1.B0.02</strong>