cs 423 operating system design far too much information
play

CS 423 Operating System Design: Far too much information about - PowerPoint PPT Presentation

CS 423 Operating System Design: Far too much information about interrupts Professor Adam Bates Fall 2018 CS423: Operating Systems Design Goals for Today Learning Objectives: Understand the role and types of of Interrupts


  1. CS 423 
 Operating System Design: 
 Far too much information about interrupts Professor Adam Bates Fall 2018 CS423: Operating Systems Design

  2. Goals for Today • Learning Objectives: • Understand the role and types of of Interrupts • Announcements: • C4 Week 2 Summaries due today! Week 3 is out . • MP0 is available on Compass! Due Jan 29 • HW0 is available on Compass! Due Jan 29 Reminder : Please put away devices at the start of class CS 423: Operating Systems Design 2

  3. What’s a ‘real’ CPU? What’s the STATE of a real CPU? Registers Code Data Stack Segment Segment Segment Offset Offset Program Counter Offset Stack Pointer OpCode Operand Current Instruction Data Operand Program instructions Heap Stack CS 423: Operating Systems Design 3

  4. The Context Switch Registers Load State (Context) Code Data Stack Segment Segment Segment Offset Program Counter Stack OpCode Operand Pointer Data Registers Operand Program instructions Heap Stack Code Data Stack Segment Segment Segment Offset Program Counter Save State Stack OpCode Operand Pointer (Context) Data Operand Program instructions Heap Stack CS 423: Operating Systems Design 4

  5. Process Control Block The state for processes that are not running on the CPU are maintained in the Process Control Block (PCB) data structure Updated during context switch An alternate PCB diagram CS 423: Operating Systems Design 5

  6. Where We Are: Last class, we discussed how context switches allow a single CPU to handle multiple tasks: What’s missing from this picture? “Virtual” “Virtual” “Virtual” … CPU CPU CPU Context Switching The Hardware + Scheduling (CPU) CS 423: Operating Systems Design 6

  7. Where We Are: Interrupts to drive scheduling decisions! Interrupt handlers are also tasks that share the CPU. Interrupt Interrupt Interrupt Handler Handler Handler “Virtual” “Virtual” “Virtual” … CPU CPU CPU Context Switching The Hardware + Scheduling (CPU) External Devices CS 423: Operating Systems Design 7

  8. CTX Switch: Interrupt Registers Registers Code Code Stack Stack Segment Segment Segment Segment Offset Offset Program Program Counter Counter Stack Stack Pointer Pointer Program instructions Stack Program instructions Stack Handler Save PC on thread stack - Save thread state in thread control block Jump to Interrupt handler (SP, registers, segment pointers, …) - Handle Interrupt - Choose next thread Thread Thread - Load thread state from control block - Pop PC from thread stack (return from handler) Control Control - Resume prior task Block Block CS 423: Operating Systems Design 8

  9. Can also CTX Switch from Yield Registers Registers Code Code Stack Stack Segment Segment Segment Segment Offset Offset Program Program Counter Counter Stack Stack Pointer Pointer Program instructions Stack Program instructions Stack yield() Save PC on thread stack - Save thread state in thread control block Jump to yield() function (SP, registers, segment pointers, …) - Choose next thread - Load thread state from control block Thread Thread - Pop PC from thread stack (return from handler) Control Control Block Block CS 423: Operating Systems Design 9

  10. How do we take interrupts safely?? • Interrupt vector • Where the processor looks for a handler • Limited number of entry points into kernel • Atomic transfer of control • Single instruction to change: • Program counter • Stack pointer • Memory protection • Kernel/user mode • Transparent restartable execution • User program does not know interrupt occurred CS423: Operating Systems Design 10

  11. Interrupt Vector Table Table set up by OS kernel; pointers to code to run on different events Processor Interrupt Register Vector h a n d l e Ti m e r I n t e r r u p t ( ) { . . . } h a n d l e D i v i d e B y Z e r o ( ) { . . . } h a n d l e S y s t e m C a l l ( ) { . . . } CS423: Operating Systems Design 11

  12. Interrupt Stack • Per-processor, located in kernel (not user) memory • Fan fact! Usually a process/thread has both a kernel and user stack • Why can’t the interrupt handler run on the stack of the interrupted user process? CS423: Operating Systems Design 12

  13. Interrupt Stack Running Ready to Run Waiting for I/O Syscall User Stack Proc2 Proc2 Proc2 Proc1 Proc1 Proc1 Main Main Main I/O Driver Top Half Syscall Kernel Stack Handler User CPU User CPU State State CS423: Operating Systems Design 13

  14. Hardware Interrupts ■ Hardware generated: ■ Different I/O devices are connected to different physical lines (pins) of an “Interrupt controller” ■ Device hardware signals the corresponding line ■ Interrupt controller signals the CPU (by signaling the Interrupt pin and passing an interrupt number) ■ CPU saves return address after next instruction and jumps to corresponding interrupt handler CS 423: Operating Systems Design 14

  15. Why Hardware INTs? CS 423: Operating Systems Design 15

  16. Why Hardware INTs? ■ Hardware devices may need asynchronous and immediate service. For example: ■ Timer interrupt: Timers and time-dependent activities need to be updated with the passage of time at precise intervals CS 423: Operating Systems Design 15

  17. Why Hardware INTs? ■ Hardware devices may need asynchronous and immediate service. For example: ■ Timer interrupt: Timers and time-dependent activities need to be updated with the passage of time at precise intervals ■ Network interrupt: The network card interrupts the CPU when data arrives from the network ■ I/O device interrupt: I/O devices (such as mouse and keyboard) issue hardware interrupts when they have input (e.g., a new character or mouse click) CS 423: Operating Systems Design 15

  18. Ex: Itanium 2 Pinout CS 423: Operating Systems Design 16

  19. Ex: Itanium 2 Pinout CS 423: Operating Systems Design 17

  20. Ex: Itanium 2 Pinout LINTx — lines/pins for hardware interrupts. In this case… LINT0 — line for unmaskable interrupts LINT1 — line for maskable interrupts CS 423: Operating Systems Design 18

  21. A Note on Multicore CS 423: Operating Systems Design 19

  22. A Note on Multicore ■ How are interrupts handled on multicore machines? CS 423: Operating Systems Design 19

  23. A Note on Multicore ■ How are interrupts handled on multicore machines? ■ On x86 systems each CPU gets its own local Advanced Programmable Interrupt Controller (APIC). They are wired in a way that allows routing device interrupts to any selected local APIC. ■ The OS can program the APICs to determine which interrupts get routed to which CPUs. ■ The default (unless OS states otherwise) is to route all interrupts to processor 0 CS 423: Operating Systems Design 19

  24. Instruction Cycle How does interrupt handling change the instruction cycle? Fetch next Execute START instruction Instruction HALT CS 423: Operating Systems Design 20

  25. Instruction Cycle w/ INTs How does interrupt handling change the instruction cycle? Fetch Stage Execute Stage Interrupt Stage interrupts disabled Check for Fetch next Execute START INT, init INT instruction Instruction handler HALT CS 423: Operating Systems Design 21

  26. Processing HW INT’s Hardware Software Device controller or other Save remainder of state hardware issues an interrupt. information. Processor finishes execution Process interrupt. of current instruction. P r o c e s s o r s i g n a l s R e s t o r e p r o c e s s s t a t e acknowledgment of interrupt. information. Processor pushes PSW and Restore old PSW and PC. PC onto control stack. Processor loads new PC value Program Status Word (PSW) contains based on interrupt. interrupt masks, privilege states, etc. CS 423: Operating Systems Design 22

  27. Other Interrupts ■ Software Interrupts: ■ Interrupts caused by the execution of a software instruction: ■ INT <interrupt_number> ■ Used by the system call interrupt() ■ Initiated by the running (user level) process ■ Cause current processing to be interrupted and transfers control to the corresponding interrupt handler in the kernel CS 423: Operating Systems Design 23

  28. Other Interrupts ■ Exceptions ■ Initiated by processor hardware itself ■ Example: divide by zero ■ Like a software interrupt, they cause a transfer of control to the kernel to handle the exception CS 423: Operating Systems Design 24

  29. They’re all interrupts • HW -> CPU -> Kernel: Classic HW Interrupt • User -> Kernel: SW Interrupt • CPU -> Kernel: Exception • Interrupt Handlers used in all 3 scenarios CS423: Operating Systems Design 25

  30. INTs, Priorities, & Blocking CS 423: Operating Systems Design 26

  31. INTs, Priorities, & Blocking ■ Interrupts (as the name suggests) have the highest priority (compared to user and kernel threads) and therefore run first ■ What are the implications on regular program execution? CS 423: Operating Systems Design 26

Recommend


More recommend