Advanced Operating Systems - Lecture 37: Interrupt handlers. This lecture will cover the following: interrupt handlers; interrupts and exceptions; linux interrupt handling; top halfs, bottom halfs and tasklets; timings and timer devices; linux kernel timers and interval timers;...
Trang 1CS703 Advanced Operating Systems
By Mr Farhan Zaidi
Trang 237
Trang 3 Interrupt handlers
Interrupts and exceptions
Linux interrupt handling
Top halfs, bottom halfs and tasklets
Timings and timer devices
Linux kernel timers and interval timers
Trang 4 Interrupt handlers are best hidden
Interrupt procedure does its task
Trang 5 Varying terminology but for Intel:
Interrupt (device generated)
Maskable: device-generated, associated with IRQs (interrupt
request lines); may be temporarily disabled (still pending)
Nonmaskable: some critical hardware failures
Exceptions (Processor-detected)
Faults – correctable (restartable); e.g page fault
Traps – no reexecution needed; e.g breakpoint
Aborts – severe error; process usually terminated (by
signal)
Programmed exceptions (software interrupts)
int (system call), int3 (breakpoint)
into (overflow), bounds (address check)
Trang 6 Hardware support for getting CPUs attention
Often transfers from user to kernel mode
Asynchronous: device or timer generated
Synchronous: immediate result of last instruction
Intel terminology and hardware
Irqs, vectors, IDT, gates, PIC, APIC
Trang 7 More complex than exceptions
Requires registry, deferred processing, etc
Some issues:
IRQs are often shared; all handlers (ISRs) are executed so they must query device
Three types of actions:
Critical: Top-half (interrupts disabled – briefly!)
Non-critical: Top-half (interrupts enabled)
Non-critical deferrable: Do it “later” (interrupts enabled)
Trang 8Memory Bus
INTR
vector 0
15
IRQs
IDT
0
255
handler
idtr
Mask points
Trang 9 Accurate timing crucial for many aspects of OS
Device-related timeouts
File timestamps (created, accessed, written)
Time-of-day (gettimeofday()
High-precision timers (code profiling, etc.)
Scheduling, cpu usage, etc
Intel timer hardware
RTC: Real Time Clock
PIT: Programmable Interrupt Timer
TSC: TimeStamp Counter (cycle counter)
Local APIC Timer: per-cpu alarms
Timer implementations
Kernel timers (dynamic timers)
User “interval” timers (alarm(), setitimer())
Trang 10 Dynamic timers may be dynamically created and destroyed No limit is
placed on the number of currently active dynamic timers
A dynamic timer is stored in the following timer_list structure:
struct timer_list
{
struct list_head list;
unsigned long expires;
unsigned long data;
void (*function)(unsigned long);
};
Trang 11 Each timer contains a field that indicates how far in the future the timer should expire This field is initially calculated by adding the right number
of ticks to the current value of jiffies
The field does not change Every time the kernel checks a timer, it
compares the expiration field to the value of jiffies at the current
moment, and the timer expires when jiffies is greater or equal to the
stored value
Trang 12 setitimer(): 3 distinct user mode interval timers
can set for one-time or periodic alarm
sends signals on timer expiry
three timers:
ITIMER_REAL: elapsed time (SIGALRM)
ITIMER_VIRT: user (SIGVTALRM)
ITIMER_PROF: user + kernel (SIGPROF)
implementations:
VIRT, PROF – updates by PIT or APIC
REAL – requires kernel timer
may need to deliver to blocked process
current->real_timer
shared by alarm() API so can’t use both