CS452 - Real-Time Programming - Spring 2009
Lecture 9 - Tasks, Scheduling
Practical Detail
- More to read on the web site
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
normally contains
- The task id
- The task's stack pointer, which points to a private stack containing
- PC
- other registers
- local variables
all ready to be reloaded whenever the task next runs.
- The return value for when the task is next activated
- The task's parent
- The task's state
- Priority Queue information
Possible states of the task
- Active: running or about to run
- Ready: can run if scheduled
- Blocked: waiting for something to happen
- Defunct: will never run again
Diagram
Creating a Task
Get an unused TD and memory for its stack
- memory could be associated with TD during initialization
- actually a form of constant time memory allocation
- unless you implement Destroy
Mostly filling in fields in the TD.
- task id
- stack pointer
- parent id
- return value
- dummy
- different return value for the active task, which goes in its
TD
- state
Must also create the initial stack
Must link into the correct priority queue.
Scheduling
When to schedule
Whenever we leave the kernel. When do we enter the kernel?
- Tasks run to completion
- Event-driven pre-emption
- internal events, like Pass( ), or Send( ), which occur when a task
gets to a particular point in its code
- external events
- Time-slicing
- re-schedule only when the slice-timer times out
- on internal events
- two problems
- slices are too big => bad response
- slices are too small => kernel runs too much = bad
response
Who to Schedule
- active task decides = co-processes
- round robin
- everybody gets the same chance
- but usually long running time = unimportant
- priorities
- fixed at compile time
- fixed when task is created
- re-fixed every time task is scheduled
- Do you have a good algorithm
- hybrid
- round robin queues for each priority
- determined by type of kernel entry
- Send wakes Receiver
- interrupt wakes interrupt destination
What God has Decided
Hybrid
What you decide
- How many priorities
- Which task should have which priority
- How to implement the queues
- one queue per priority
- fast insertion, but needs back pointer
- slow activation, but use a highest priority pointer
- one sorted queue
- slow insertion, but can be speeded up
- fast activation
Return to: