Documente Academic
Documente Profesional
Documente Cultură
-RTOS-
BLOCKED/
WAITING
READY
List of TCBs
28.06.06 RTOS - R.Serna Oliver - TU Kaiserslautern 25
Scheduler
●
Scheduler
– Implement a scheduling policy
●
select next task to be executed
●
maintain queues (order by?)
●
maintain priorities (static? dynamic?)
– Time triggered
●
Kernel executes periodically
– Event triggered
●
Kernel executes only when “something” happens
●
Needs of communication and synchronization
●
Communication mechanisms
●
Synchronization mechanisms
●
Tasks need to synchronize
– “meeting points”
●
i.e. wait for an intermediate result
●
i.e. wait for the end of another task
/* OS starts executing */
os_start();
} /* end */
Waiting
Ready
T2
T1 T2
T1
0 5 10 15 20 25 30 35 40 45 50
Running
PC =
Stack =
Mem =
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T2
T1
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T1
Running
PC = ~task2()
T2 Stack = stack2
Mem = mem2
Execution of T2 is preempted
Waiting by a higher priority task
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T2
TCB of T2 is updated with PC,
Running stack, memory and CPU registers.
PC = ~task1() PC, stack, memory and
T1 Stack = stack1
Mem = mem1
CPU registers are updated
from the TCB of T1
28.06.06 RTOS - R.Serna Oliver - TU Kaiserslautern 44
Example (VIII)
T1 reaches again the end of
Blocked the loop and finishes its execution
T1
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T1 executes again
(after moving from Waiting to Ready)
Waiting
T2
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
T2 T1
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
28.06.06
PC = ??
Stack = ??
Mem = ?? ?
RTOS - R.Serna Oliver - TU Kaiserslautern 47
Example (XI)
A special task IDLE is scheduled
Blocked with the lowest priority in order to
get the CPU when no other task
is ready to execute
Waiting
T2 T1
T2 Task IDLE
Ready
T1
void idle(void *param) {
0 5 10 15 20 25 30 35 40 45 50
Idle
while (1) { NULL }
Running
}
PC = ??
Stack = ?? Priority = Lowest
Mem = ?? Always Ready to execute
28.06.06 RTOS - R.Serna Oliver - TU Kaiserslautern 48
Example (XII)
The Idle task executes until
Blocked any other task is available in the
Ready queue
Waiting
Idle
T2 T1
T2
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
Running
PC = ~idle() Again PC, stack and memory are
Idle Stack = stack_idle replaced like with any other task
Mem = mem_idle
Waiting
Idle
...
T2
...
Ready
T1
0 5 10 15 20 25 30 35 40 45 50
...
Running
PC = ...
... Stack = ...
Mem = ...
Thank you!