5 - Real-Time Kernel: Assignment 4 - Lift With Message Passing
5 - Real-Time Kernel: Assignment 4 - Lift With Message Passing
• The external requirements are kept, meaning that the lift shall
move as before, passengers shall travel from one randomly se-
lected floor to another, also randomly selected floor, and passen-
gers shall wait for the lift, as well as wait inside the lift until they
reach their destinations.
• The main contents in the data type used for the lift is kept. The
main difference is that the semaphore and the condition variable
are now not needed, and are therefore removed.
Tasks
Task execution
A running task uses a stack. The stack is used as a temporary storage
area during execution, but also as a storage area for saved informa-
tion when the task is not executing. When the task executes, the stack
stores information, such as information needed during function calls,
e.g. local variables, parameters, parameter addresses, and return
address information.
The stack is also used during a task switch, when a task that shall
suspend its execution saves information on its stack, and where this
information is re-used when the task resumes its execution again, at a
later time instant.
It assumed here, and also in in [RT], that a stack grows towards
lower memory addresses.
When a task is running, the program counter in the CPU of course
changes, as execution proceeds. For the purpose of this lecture, and
also with reference to Chapter 10 in [RT], a simple model of a CPU
will be used. The model contains a program counter register, here
denoted PC, a set of processor registers, here denoted Reg, and a
stack pointer register, here denoted SP. A running task, using the
CPU modeled in this way, and referring to its stack in memory via
the stack pointer register, is shown in Figure ??.
the task’s stack using the stack pointer field in the TCB, is shown in
Figure ??.
Task lists
TCBs can be stored in lists. These lists are referred to as lists of tasks.
There can e.g. be a list of tasks which are ready to run, and a list of
tasks which are waiting for specified time intervals.
Implementation
The task control block is implemented in tcb.h, as
For comparison purposes, one can study the data structure in Linux
where information associated with a task is stored. This data struc-
ture is denoted process descriptor. Source code defining a process
descriptor in Linux can be found in the Linux source code2 . 2
http://lxr.linux.no/linux+v3.6.6/
include/linux/sched.h#L1234
Handling of TCBs in Simple_OS, and functionality for representing
lists of tasks as lists of task identities, are described in Section 15.2.2
in [RT].
In Simple_OS, there is one list of TCBs. Each created task has its
TCB in this list. The list is defined in tcb_storage.c, as
/* size of ready-list */
#define READY_LIST_SIZE TCB_LIST_SIZE
Task creation
with initialisation of a TCB, and then finding a free place in the TCB
list, described in Section ??.
Then, the stack is prepared, resulting in a stack layout as in Figure
??, and the stack pointer in the TCB is set to refer to the top of the
prepared stack, which establishes the connection between the TCB
and the task stack.
A task in Simple_OS is created by calling the function si_task_create.
The address of the function which shall be made into a task is given
as argument to si_task_create. The address of the first element of the
stack, and the task priority, are also given as arguments to si_task_create.
In this way, the si_task_create function achieves information which is
necessary for the task creation.
A graphical illustration of a newly created, but not yet started,
task, is shown in Figure ??.
Task start
{
/* a pointer to a TCB */
task_control_block *tcb_ref;