Spring 2017 :: CSE 506
Interrupts & System Calls
Nima Honarmand
Interrupts & System Calls Nima Honarmand Spring 2017 :: CSE - - PowerPoint PPT Presentation
Spring 2017 :: CSE 506 Interrupts & System Calls Nima Honarmand Spring 2017 :: CSE 506 What is an Interrupt? Loosely defined: an irregular control-flow from one context of execution and back Usually, user to kernel and back, can
Spring 2017 :: CSE 506
Nima Honarmand
Spring 2017 :: CSE 506
network card interrupts
fault or a device-by-zero fault
Spring 2017 :: CSE 506
1. Save current execution context
state
2. Transfer control to a well-defined location in the kernel code
3. Handle the interrupt 4. Return to the previous context after handling the interrupt
→ It seems all three forms of interrupts can use the same general mechanism
Spring 2017 :: CSE 506
Spring 2017 :: CSE 506
kernel’s stack
in the cr2 register
iret instruction)
Spring 2017 :: CSE 506
it use as the interrupt handler’s stack?
Spring 2017 :: CSE 506
a number indicating its type
exception or trap” unless otherwise specified
Descriptor Table
Spring 2017 :: CSE 506
255 … 31 … … 47 Pre-defined by x86 Software Configurable Device IRQs
48 = JOS System Call 128 = Linux System Call
Spring 2017 :: CSE 506
Intel
JOS respectively
Spring 2017 :: CSE 506
raise an interrupt
fault manually)
Protection (#GP) fault
Spring 2017 :: CSE 506
memory, called Interrupt Descriptor Table, or IDT
255 … 31 … … 47 idtr
Spring 2017 :: CSE 506
linear address
interrupt (using int instruction)
bit
Spring 2017 :: CSE 506
255 … 31 … … 47 idtr
Code Segment: Kernel Code Segment Offset: &page_fault_handler //linear addr Ring: 0 // kernel Present: 1 Gate Type: Exception
14 (page fault)
Spring 2017 :: CSE 506
255 … 31 … … 47 idtr
Code Segment: Kernel Code Segment Offset: &breakpoint_handler //linear addr Ring: 3 // user Present: 1 Gate Type: Exception
3 (breakpoint)
Spring 2017 :: CSE 506
(legacy) features that are rarely used
confusing
Spring 2017 :: CSE 506
what privilege
system
it use as the interrupt handler’s stack?
Spring 2017 :: CSE 506
segment
specified layout
Spring 2017 :: CSE 506
stacks for each process
processor?
Spring 2017 :: CSE 506
Spring 2017 :: CSE 506
Spring 2017 :: CSE 506
User Kernel Stack Stack
if (x) { printf(“Boo”); ... printf(va_args…){ ... Disk_handler (){ ... } RSP RIP RSP RIP
Disk Interrupt!
Spring 2017 :: CSE 506
another interrupt comes in?
interrupts just push the next frame on the stack
Spring 2017 :: CSE 506
User Kernel Stack Stack
if (x) { printf(“Boo”); ... printf(va_args…){ ... disk_handler (){ lock_kernel(); ... unlock_kernel(); ... RSP RIP net_handler (){ lock_kernel(); …
Network Interrupt!
Will Hang Forever! Already Locked!!!
Spring 2017 :: CSE 506
and synchronized
interrupt
Spring 2017 :: CSE 506
postpone the actual work by adding a “work item” to some “work queue”
enabling interrupts, by traversing the work queue
Spring 2017 :: CSE 506
Spring 2017 :: CSE 506
exception gate
interrupts (i.e., clears IF on entry)
Spring 2017 :: CSE 506
be reentrant?
trying to handle another interrupt/exception/trap
Spring 2017 :: CSE 506
Spring 2017 :: CSE 506
eax register
convention
Spring 2017 :: CSE 506
Around Pentium 4 era:
Spring 2017 :: CSE 506
special CPU register?
be worth the transistor budget to implement this
performance?
Spring 2017 :: CSE 506
registers) to store:
Spring 2017 :: CSE 506
system calls
systenter/sysexit
saving to deal with
Spring 2017 :: CSE 506
into the address space of processes
even further
call and the code to access that data into the process address space