Why is the computer able to react right away?
Why not just poll for new input?
An interrupt is a signal to the CPU to stop what it's doing and take care of urgent business
Speed
Also important: Atomicity
Something needs to be done urgently
First, we take care of the most urgent parts
This is the top-half
Schedule less urgent action
Second, we take care of the less urgent parts
Take a look at /proc/interrupts
/proc/interrupts
Hardware interrupts
Software interrupts
Trap can refer to
any interrupt
any software interrupt
any synchronous software interrupt
any interrupt caused by "trap" instruction
May even refer to debugger breakpoints
Synchronous software interrupts are generally referred to as exceptions
"Exceptional" CPU conditions
exception: any type of interrupt
interrupt: hardware interrupt
abort: prefetch or data abort (page fault)
reset: reinit the processor state
Some instructions are exception-generating instructions
interrupts: hardware interrupts
exceptions: software interrupts
fault: return to save instruction
trap: return to next instruction
aborts: don't return to program
Tracing interrupts with bpftrace
bpftrace
Previously:
userspace context
kernelspace context
process context: kernel running attached to a process
current
struct task_struct
interrupt context: kernel running NOT attached to a process
Runs in interrupt context
No sleeping/blocking
Interrupts disabled
Starts immediately after the ISR
Interrupts enabled
Based on softirq, but can be deferred
Runs in process context
Can sleep
For more extensive processing
Look at ksoftirqd in ps
ksoftirqd
ps
A look at include/linux/interrupt.h
A simple example module
Use bpftrace to see the kernel stack and dive into the code