Interrupts
Interrupts
Interrupts
Exceptions
COMS W6998
Spring 2010
Overview
Main
Memory
system bus
I/O
device
I/O
device
I/O
device
I/O
device
Motivation
Fetch instruction at IP
add
IP
st
Save context
mul
ld
sub
Lookup ISR
bne
add
jmp
Get INTR ID
Interrupt?
no
yes
IRET
Interrupts
Forcibly
Many
Types of Interrupts
Asynchronous
Processor-detected exceptions:
Faults correctable; offending instruction is retried
Traps often for debugging; instruction is not retried
Aborts major error (hardware failure)
Programmed exceptions:
Requests for kernel intervention (software intr/syscalls)
Faults
Traps
A
Error Exceptions
force_sig(sig_number, current);
That will probably kill the process, but thats not the
concern of the exception handler
One important exception: page fault
An exception can (infrequently) happen in the kernel
Intel-Reserved ID-Numbers
Interrupt Hardware
Legacy PC Design
(for single-proc
systems)
Ethernet
IRQs
Slave
PIC
(8259)
SCSI Disk
Master
PIC
(8259)
INTR
x86
CPU
Real-Time Clock
Keyboard Controller
Programmable Interval-Timer
Interrupt #
CPU
1
LOCAL
APIC
LOCAL
APIC
I/O
APIC
Interrupt routing
Hardware to Software
Memory Bus
IRQs
idtr
PIC
INTR
CPU
IDT
vector
N
handler
Mask points
255
Interrupt Masking
Two
IRQs
idtr
PIC
INTR
CPU
IDT
vector
N
handler
Mask points
255
Dispatching Interrupts
Overview
Nested Interrupts
What
Maximizing Parallelism
You
Nested Execution
tasklet
softirq
workqueue
kernel thread
Bottom
half
Typically queue the request and set a flag for deferred processing in a bottom half
softirqs
tasklets (built on top of softirqs)
work queues
kernel threads
All
can be interrupted
Top half
tasklet
softirq
workqueue
kernel thread
Bottom
half
Interrupt Stack
When
used?
These
Softirqs
Rescheduling Softirqs
A
Tasklets
to get right
One has to be careful about sleeping
They run at higher priority than other tasks in
the systems
Can produce uncontrolled latency if coded
badly
Ongoing discussion about eliminating tasklets
Will likely slowly fade over time
Work Queues
Kernel Threads
Always
2.6.30
Comparing Approaches
ISR
SoftIRQ
Tasklet
WorkQueue
KThread
Briefly
No
No
No
No
Yes
Yes
No
No
No
Yes
Yes*
Yes*
No
No
N/A
Yes
Yes
Yes
Maybe
No
No
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
No
No
No
Yes
Yes
No
No
No
No
No
ret_from_exception()
ret_from_intr()
ret_from_sys_call()
ret_from_fork()
/proc/interrupts
$ cat /proc/interrupts
CPU0
0: 865119901
1:
4
2:
0
8:
1
12:
20
14:
6532494
15:
34
16:
0
19:
0
23:
0
32:
40
33:
40
48: 273306628
NMI:
0
ERR:
0
IO-APIC-edge
IO-APIC-edge
XT-PIC
IO-APIC-edge
IO-APIC-edge
IO-APIC-edge
IO-APIC-edge
IO-APIC-level
IO-APIC-level
IO-APIC-level
IO-APIC-level
IO-APIC-level
IO-APIC-level
timer
keyboard
cascade
rtc
PS/2 Mouse
ide0
ide1
usb-uhci
usb-uhci
ehci-hcd
ioc0
ioc1
eth0
More in /proc/pci:
$ cat /proc/pci
PCI devices found:
Bus 0, device
0, function 0:
Host bridge: PCI device 8086:2550 (Intel Corp.) (rev 3).
Prefetchable 32 bit memory at 0xe8000000 [0xebffffff].
Bus 0, device 29, function 1:
USB Controller: Intel Corp. 82801DB USB (Hub #2) (rev 2).
IRQ 19.
I/O at 0xd400 [0xd41f].
Bus 0, device 31, function 1:
IDE interface: Intel Corp. 82801DB ICH4 IDE (rev 2).
IRQ 16.
I/O at 0xf000 [0xf00f].
Non-prefetchable 32 bit memory at 0x80000000 [0x800003ff].
Bus 3, device
1, function 0:
Ethernet controller: Broadcom NetXtreme BCM5703X Gigabit Eth (rev 2).
IRQ 48.
Master Capable. Latency=64. Min Gnt=64.
Non-prefetchable 64 bit memory at 0xf7000000 [0xf700ffff].
Portability
Which
Summary
Backup Foils
holds the values for registers SS and ESP that will get
loaded by the CPU upon entering kernel-mode
Segment Limit
16 15
TR
GDTR
GDT
TSS
IDT Initialization
Linux lingo:
Interrupt Processing
IRQn_interrupt:
pushl $n-256 // negative to distinguish syscalls
jmp common_interrupt
Common code:
common_interrupt:
SAVE_ALL // save a few more registers than hardware
call do_IRQ
jmp $ret_from_intr
do_IRQ() is C code that handles all interrupts
do_IRQ():
handle_IRQ_event():
Hardware Handling
On entry:
Which vector?
Get corresponding descriptor in IDT
Find specified descriptor in GDT (for handler)
Check privilege levels (CPL, DPL)
Interrupt Handling