There are three different kind of tasks with three levels of priorities. They are in
decreasing order of priorities:
- System,
- Periodic, and
- Round Robin.
The scheduling policy is given below.
- Ready (and schedulable ) higher priority tasks pre-empts running lower priority tasks.
- System tasks run to completion, or until they voluntarily give up the
CPU, or until they wait for an event.
- System tasks and RR tasks are first come first served.
- Periodic tasks do not execute more than its WCET (worst-case execution time).
- Periodic tasks do not overlap.
- Periodic and RR tasks' execution time are extended if they are interrupted or
pre-empted by the duration of pre-emption.
- RR tasks execute for two ticks.
- RR tasks move to the front of the queue if they are interrupted or preempted.
- RR tasks move to the back of the queue when they were able to execute for two RTOS ticks.
We endeavoured to implement these requirements as thoroughly as possible. Please, see Section
Scheduling for details of our implementation.
Requirement no. |
Status |
Tested |
1. |
✔ |
✔ |
2. |
✔ |
✔ |
3. |
✔ |
✔ |
4. |
✔ |
✔ |
5. |
✔ |
✔ |
6. |
✔ |
× |
7. |
✔ |
✔ |
8. |
✔ |
✔ |
9. |
✔ |
✔ |
Table 1: Implementation completion matrix for scheduling policy.
The accuracy of stretching or extending the WCET of a periodic task and the quantum
of an RR task is limited to only one RTOS tick. That is if a task is interrupted for
at least a millisecond but less than an RTOS tick (5 milliseconds) the task is extended
for a whole RTOS tick (5 milliseconds). Also, if a task is interrupted for less than
a millisecond in total the task is not stretched at all. Note that this stretching takes
place when the kernel is aware of the pre-emption. If an ISR pre-empts a task and
the kernel is not aware of this pre-emption then the task may not be stretched properly.
This has
some important consequences. A task can in reality has been executing for more than
WCET time but the scheduler may still think that it has been executing for an
RTOS tick only. This can happen when a task is interrupted by an ISR just before an RTOS tick takes
place and gets back the CPU just after tick. Again, a task may execute for only a fraction of WCET
or a quantum but the scheduler
may think that it already has executed for its share of time. This can happen if a task
is pre-empted by an ISR in the beginning of a tick and gets the CPU back just before an RTOS tick.
Therefore, an application engineer must keep record of pre-emption time of
cur_task in an
ISR that takes
place without the knowledge of the kernel and that returns the CPU to the interrupted task (not to
the kernel). Following listing might be one way to handle this.
ISR(an_ISR)
{
cur_task->preemption_begin_time = Now();
/* ISR logic goes here */
/* ISR logic ends above */
cur_task->interrupted_time += (Now() - cur_task->preemption_begin_time);
if (cur_task->interrupted_time / 5 > 0){
cur_task->remaining_ticks += (cur_task->interrupted_time / 5);
cur_task->interrupted_time = (cur_task->interrupted_time % 5);
}
}