Transcript Lecture11

Engineering Open House
• Need students to demo their
players on
– Friday 3-4
– Saturday 10-2.
Embedded Software
Architectures
• No Operating System
– Round robin: sequential polling for events
– Round robin w/ interrupts
– Function Queue Scheduling
• Real Time Operating System
Maestro in RR+INT
volatile bit fEndOfSlice, fSerial;
void isr(void) interrupt … {
process_tones();
if (!--sliceCount) {
changeTones();
sliceCount = SliceSize
fEndOfSlice = TRUE;
}
}
void serial(void) interrupt …{
timeCritical();
fSerial = TRUE;
}
What are the time critical
functions?
Flipping channels, change
tones at end of timeslice
What are the
housekeeping functions?
TNE count down and
stream processing (TNE,
Tones)
main () {
if (fSerial) {process_serial_data(); fSerial = FALSE;} Do these have hard time
if (fEndOfSlice) {
constraints too?
if (--TNE==0)
Yes, one time slice
process_next_event();
fEndOfSlice = FALSE;
(18ms)…good enough?
}
Not necessarily…serial is
}
undefined!
Task Diagram
Worst case analysis: character comes one cycle before TF0
Worst case latency: Sum of max of all task functions.
Advantage over RR: Critical Stuff happens in ISR
time slice start
time slice end
serial_isr
isr
serial
housekeeping
main
deadline
timer0 overflow occurs (TF0)
char arrives
Can we do better?
Function Queue
void isr(void) interrupt … {
process_tones();
if (!--sliceCount) {
changeTones();
sliceCount = SliceSize;
enq(process_time_slice);
}
}
void serial(void) interrupt …{
timeCritical();
enq(process_serial_data);
}
void main(void) {
while (1) if (f = deq()) { *f());
}
You get a scheduling opportunity
every time a task completes.
What is the advantage of
this? Programmer can set
priority for task functions.
Worst case latency for
priority n task function?
Sum of max execution
time for all task functions
of priority > n + max
current task
With only two tasks, it is
the same as RR+INT. And
it does not allow any nondeterministic tasks.
Task Diagram
Worst case analysis: Its actually different…serial has to get started
Worst case latency: Sum of max of all task functions
Advantage: Can support priorities, but still at mercy of slowest task.
time slice start
time slice end
serial_isr
isr
serial
housekeeping
main
deadline
timer0 overflow occurs (TF0)
char arrives
Can we do better?
Comparison Non OS Architectures
• See Chapter 5, table 5.1 Simon
Real Time Operating Systems
• What is the basic thing we want the OS to do to help
us improve worst case latency? Enable multithreading
• How? Define an OS time-slice (tick) at which highest
priority ‘runnable’ task is continued. Priority function
determines response behavior.
• Simplest Scheduling algorithm: each task gets at most
1 tick at a time to run. Round Robin Scheduling. Worst
case task latency = #tasks*tick. Worst case run time =
ticks/task * #tasks
• Some properties of such system: liveness, safety,
fairness, latency, overhead.
• Other niceties: Device Drivers, Synchronization, Data
Sharing (messages, queues, etc.), Memory
Management
Programmers View
void tone_isr(void) interrupt … {
Advantages:
process_tones();
if (!--sliceCount) {
•Deterministic response time
changeTones();
even w/ non deterministic
sliceCount = SliceSize
isr_send_signal(MUSIC);
tasks lengths.
}
• Incremental development
}
void serial_isr(void) interrupt …{
timeCritical();
Resources:
os_send_signal(SERIAL);
}
•Task switching overhead
void play(void) _task_ MUSIC {
•Memory overhead
os_create(SERIAL);
while (1) {os_wait();
•Use of system timer
process_next_event();}
•Degrades best case response
}
void serial(void) _task_ SERIAL {
time.
while (1) {os_wait();
process_serial_data();} // os_create(MUSIC)?
}
Tasks are threads
Task Diagram
os time
slice music time
os time
slice
os time
slice
slice start
serial_isr
music_isr
serial
music
OS
Char arrives
Music task is never
more than one OS
time slice away
os time
slice music time
slice end
Another Solution
• Multiprocessor: Dedicate one processor to
each (or a few) tasks.
• Still need synchronization and
communication.
• Our Orchestra network could be an example
of a multiprocessor system
Design Meeting
• What’s next?
– Streaming
Orchestra Functions
•
•
•
•
•
•
•
Time of day
Get data from net, send to player or to pilot
Send music to net
Get music from net
Play music
Task to play music from net
Task to create/delete other tasks (master)
Basic Architecture of an RT OS
• Task Table
– Process state, signal flag, time_out counter,
context
• System Interrupt Service Routine (timer)
• System Calls (Code, time)
Benefits
Embedded Software
• Software States v. Finite State Machines
• Hierarchical State
• Thread/Process Communication
– Critical Sections
– Synchronization
– Messaging and Signaling