CS452 - Real-Time Programming - Fall 2009
Lecture 8 - Create( ), Scheduling
Reminder
Creating a Task
In creating a task you have to do two things
- Get and initialize resources needed by the task
- Make the task look as if it had just entered the kernel
Things you need to do
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
- SPSR
- link register
- parent tid
- return value
- dummy
- different return value for the active task, which goes in its
TD
- state
- install in the ready queues
Must also create the initial stack
The Create Function
You also need a int Create( int priority, void (*code) ( ) )
function to call from user tasks.
Although it's no more than a wrapper there are a few problems to solve.
- Passing arguments
- On entry the arguments are somewhere, usually r0 & r1
- You have to put them where the kernel can find them.
- gcc's function extry code immediately puts them on the stack.
- In assembly you can find them using the frame pointer.
- Jumping into the kernel
- Getting the return value from the kernel and returning it.
- You find it where the kernel put it
- gcc's function exit code expects it to be indexed off the frame
pointer
- from where it does into r0
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: