Lecture: interrupts Q&A
recap
- user-kernel switch/communication: ring 0 ↔ ring 3
- how can kernel take back control
- how can user request help from kernel
- how can kernel notify user
- hardware support
- IDT register
%idtr
- task register for the stack switch
- exceptions, device interrupts
- instructions:
int
, iret
exception handling
- user-level exception handling
- question from last week: change div by zero to return 42 instead of crash
- how to handle vector 0
- skip the
idiv
instruction - how?
- emulate the result - what registers does
idiv
put result in?
- basic idea for virtual machines: trap-and-emulate
- how to map memory from a remote machine
fast system calls
- what’s the cost of a syscall
- IDT lookup
- stack switch
- state push/pop: error code (optional),
eip
, cs
, eflags
, esp
, ss
- how to reduce the cost
- dedicated instructions
- dedicated register for syscall entry: no IDT lookup
- save user ip & eflags in registers: no stack switch/push
- x86_64:
syscall
/sysret
(Linux)
- don’t switch to kernel
- many other approaches: batching, downloading code
- programming model
- consider
recv(fd, buf, len, flags)
: syscall for receiving a network packet
- what should the kernel do if there’s no data
- block
- return with “try-again”
- return right away; later upcall to user space when data arrive
- C10K problem: pros and cons