Interrupts
• Interrupts signal asynchronous events
• I/O hardware interrupts
• Hardware timers
• Two flavors of interrupts
• Precise: CPU transfers control only on instruction boundaries
• Imprecise: CPU transfers control in the middle of instruction
execution
• What the heck does that mean?
• OS designers like precise interrupts, CPU designers like
imprecise interrupts
How to find interrupt handler?
• Hardware maps interrupt type to interrupt number
• OS sets up Interrupt Descriptor Table (IDT) at boot
• Also called interrupt vector
• IDT is in memory
• Each entry is an interrupt handler
• OS lets hardware know IDT base
• Hardware finds handler using interrupt number as
index into IDT
• handler = IDT[intr_number]
Timer
• The timer is critical for an operating system
• It is the fallback mechanism by which the OS reclaims control
over the machine
• Timer is set to generate an interrupt after a period of time
• Setting timer is a privileged instruction
• When timer expires, generates an interrupt
• Handled by kernel, which controls resumption context
• Basis for OS scheduler (more later…)
• Prevents infinite loops
• OS can always regain control from erroneous or malicious
programs that try to hog CPU
• Also used for time-based functions (e.g., sleep())
I/O Control
• I/O issues
• Initiating an I/O
• Completing an I/O
• Initiating an I/O
• Special instructions
• Memory-mapped I/O
• Device registers mapped into address space
• Writing to address sends data to I/O device
I/O Completion
• Interrupts are the basis for asynchronous I/O
• OS initiates I/O
• Device operates independently of rest of machine
• Device sends an interrupt signal to CPU when done
• OS maintains a vector table containing a list of
addresses of kernel routines to handle various events
• CPU looks up kernel address indexed by interrupt
number, context switches to routine
I/O Example
1. Ethernet receives packet, writes packet into memory
2. Ethernet signals an interrupt
3. CPU stops current operation, switches to kernel mode, saves
machine state (PC, mode, etc.) on kernel stack
4. CPU reads address from vector table indexed by interrupt
number, branches to address (Ethernet device driver)
5. Ethernet device driver processes packet (reads device registers
to find packet in memory)
6. Upon completion, restores saved state from stack
Interrupt Questions
• Interrupts halt the execution of a process and
transfer control (execution) to the operating system
• Can the OS be interrupted? (Consider why there might
be different IRQ levels)
• Interrupts are used by devices to have the OS do
stuff
• What is an alternative approach to using interrupts?
• What are the drawbacks of that approach?
Architecture Trends Impact
OS Design
• Processor
• Single core to multi-core
• OS must better handle concurrency
• Network
• Isolation to dial-up to LAN to WAN
• OS must devote more efforts to communications
• Disconnected to wired to wireless
• OS must manage connectivity more
• Isolated to shared to attacked
• OS must provide more security/protection
• Mobile/battery-operated
• OS must pay attention to energy consumption
May you live in Interesting
Times
• Multicores
• Smart phones
• Tapes
disks
flash memory
..
• 3G, 4G..
53 CS317 Operating System
• Cloud
• Wearable computers
• Virtual reality
• Motion capturing device