CS452 - Real-Time Programming - Spring 2008
Lecture 6 - Tasks
Questions & Comments
- Lab will be ready some time during the week-end for: Assignment 2 (aka
1)
Kernel of a Real-time Operating System
Diagram
What Does the Kernel Provide
Tasks
- Provide applications with modularity, which is a higher level at which
they can be organized
- Consist of
- instructions, common to all tasks
- global state, common to all tasks
- local state, different state in different tasks
- How tasks work together
- synchronization
- communication
- combined into one mechanism: message passing
Communication
Communication has two sides
- sharing information
- handshaking
We use Send/Receive/Reply (SRR) to do both.
- Send blocks
- Receive blocks: is synchronous with the call to send
- Reply doesn't block: is synchronous with the return from send
Diagram
Synchronization
- Between tasks
- Coordination of execution in co-operating tasks
- Uses SRR
- With internal events
- Real-time by synchronizing with a real-time clock: e.g. clock
server
- Ordering execution: e.g. name server, bounded buffer
- Uses SRR
- With external events
Tasks
Kernel maintains a task descriptor (TD) for each created task. That is, to
create a task the kernel must allocate a TD and initialize it. The TD normall
contains
- The task's stack pointer, which contains
- PC
- other registers
- local variables
all ready to be reloaded whenever the task next runs.
- Possibly the return value for when the task is next activated
- The task's parent
- The task's state
Possible states of the task
- Active: running or about to run
- Ready: can run if scheduled
- Blocked: waiting for something to happen
Diagram
Kernel Structure
The kernel is just a function like any other, but which runs forever.
kernel( ) {
initialize( );
FOREVER {
request = getNextRequest( );
handle( request );
}
}
There are two other ways of writing the kernel, which are both equivalent
to the one above.
kernel-start:
initialize( );
exit-kernel( );
kernel-entry:
request = determine-request( );
handle( request );
exit-kernel( );
And
kernel-start:
initialize( );
exit-kernel( );
create-entry:
handle( CREATE );
exit-kernel( );
xxxx-entry:
and so on;
The first one is the most common. It hides all the interesting stuff
inside
int getNextRequest( ) {
active = schedule( ); //active is a pointer to a TD
activate( active );
return determine-request( active ); //the active task doesn't change
}
What's inside activate( active )
?
How do you get the right PC into the interrupt vector? Two ways.
Return to: