CS452 - Real-Time Programming - Fall 2008
Lecture 4 - ISRs
Questions & Comments
- Due dates for kernel
Interrupt Service Routines (ISRs)
We can use interrupts to get rid of polling
Interrupts are exceptions
- Mask interrupts
- Set link register
- Save CSR
- Transfer control
ISRs
Like function calls without arguments or return values.
- Save state of interrupted task
- Turn off source of interrupt
- Do the work
- Restore state of interrupted task
- Return to next instruction of interrupted task
Implementation of polling loop
- With interrupts disabled
- set up data structures for processor to find ISRs
- Enable interrupts
FOREVER { }
- This is called the idle task
- It could be
FOREVER { halt }
Worst case reponse time
ISR implementation of polling loop
- Interrupt occurs indicating that condition is true
- Wait for interrupts to be enabled
- Wait for current instruction to finish
- Processor finds ISR and starts executing it
- ISR
- saves enough state
- gets volatile data
- removes source of interrupt
- executes the action
- restores state
- exits, which re-enables interrupts
Worst case response time
- Sum of all overhead plus action times for all higher level
interrupts.
- Could be infinity. (Why?)
- Infinity doesn't matter. (Why?)
Improvements
- Multiple calls from the same interrupt you get for free
- Can open windows in long-running actions by enabling interrupts
- More state must be saved (Why?)
- Gets complex fast (Why?)
A process, having, for example, executed getch( )
, is blocked
waiting for input
- Interrupt occurs at the same time that the ready bit sets.
- Wait for interrupts to be enabled
- Wait for current instruction to finish.
- Processor finds start of ISR and starts executing.
- ISR
- saves enough state
- gets volatile data
- removes source of interrupt
- restores state
- exits
- Interrupted process continues running
- Time slice interrupt transfers control to OS
- OS
- notices that data is ready
- puts it into process
- marks process ready
- schedules
- exits
- When process is scheduled, maybe not the first time after the
interrupt, it
- returns from
getch( ),
- executes first instruction processing the data.
Worst case response time?
Interrupt vectors
Hardware method for processor to find ISRs
Method 1
- Interrupt source is uniquely identified at the processor
- NuBus: one wire per interrupt
- VMEbus: encoded as a decimal numbet {IRQ0, IRQ1, IRQ2, ... }
- Processor has one magic location per interrupt
- containing first instruction of ISR
- Hardware puts beginning of ISR into PC
- and disables interrupts at the same time.
Method 2 (Intel)
- One interrupt line on the processor
- asserted by interrupt control unit (ICU)
- Processor reads register(s) in ICU to find out which interrupt
occurred
- Data structure in main memory
- one record per interrupt source
contains beginning of ISR
- Hardware runs all these bus cycles, then
- puts beginning of ISR into PC
- disables interrupts
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
Return to: