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
SETGATE(gate, istrap, sel, off, dpl)
in xv6/JOS
- does your kernel allow interrupts in kernel
- does your kernel allow user to invoke
int N
More on system calls
- suppose your OS has a
recv(fd, buf, len, flags)
syscall
- user space invokes it to receive a network packet
- what should the kernel do if there’s no data
- block
- return with “try-again”
- return right away; later up-call to user space when data arrive
- pros and cons
- what’s the cost of a syscall & how to reduce the cost
- don’t switch to kernel
- dedicated instructions
- x86_64:
syscall
/sysret
(Linux)
- arm:
svc
/eret
- riscv:
ecall
/*ret
- many other approaches: batching, downloading code