CS61C L14 Interrupts © UC Regents 1 CS61C - Machine Structures Lecture 14 - Operating System Support and Prioritized Interrupts October (Friday the) 13(th),

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Input and Output CS 215 Lecture #20.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
CS61C L26 Interrupt Review © UC Regents 1 CS61C - Machine Structures Lecture 26 - Review of Interrupts December 6, 2000 David Patterson
Cs 61C L13 I/O.1 Patterson Spring 99 ©UCB CS61C Operating System Support and Prioritized, Re-Entrant Interrupts Lecture 13 March 3, 1999 Dave Patterson.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
CS61C L25 I/O (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #25: I/O Andy Carle.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Interrupts STOP!!! Do this!!!. CMPE12cGabriel Hugh Elkaim 2 Interrupts Have device tell OS/CPU it is ready Requires hardware to support. OS/CPU can then.
OS Spring’03 Introduction Operating Systems Spring 2003.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
COMP3221 lec40-exception-review.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 40: Review of Exception
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Introduction to Embedded Systems
System Calls 1.
COMP201 Computer Systems Exceptions and Interrupts.
CS 61C L7.1.1 VM I (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture VM I Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Input and Output Computer Organization and Assembly Language: Module 9.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
CS 61C L6.2.2 Interrupts (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Interrupts Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
I/O Computer Organization II 1 Interconnecting Components Need interconnections between – CPU, memory, I/O controllers Bus: shared communication channel.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
MicroComputer Engineering OperatingSystem slide 1 the Operating System (OS)
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
MIPS I/O and Interrupt.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 1: Review of Computer Organization
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Copyright © 2007 by Curt Hill Interrupts How the system responds.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Operating Systems CMPSC 473
Microprocessor Systems Design I
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
Operating Systems Chapter 5: Input/Output Management
Architectural Support for OS
Chapter 5: I/O Systems.
Interrupts and Exception Handling
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
MIPS I/O and Interrupt.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Interrupts and exceptions
Interrupts and Exception Handling
Presentation transcript:

CS61C L14 Interrupts © UC Regents 1 CS61C - Machine Structures Lecture 14 - Operating System Support and Prioritized Interrupts October (Friday the) 13(th), 2000 David Patterson

CS61C L14 Interrupts © UC Regents 2 Review °I/O gives computers their 5 senses °I/O speed range is million to one °Processor speed means must synchronize with I/O devices before use °Polling works, but expensive processor repeatedly queries devices °Interrupts works, more complex devices causes an exception, causing OS to run and deal with the device °I/O control leads to Operating Systems

CS61C L14 Interrupts © UC Regents 3 Outline °Instruction Set Support for OS °Handling a Single Interrupt °Prioritized Interrupts °Re-entrant Interrupt Routine

CS61C L14 Interrupts © UC Regents 4 Polling vs. Interrupt Analogy °Imagine yourself on a long road trip with your 10-year-old younger brother… (You: I/O device, brother: CPU) °Polling: “Are we there yet? Are we there yet? Are we there yet? ….” CPU not doing anything useful °Interrupt: Stuff him a color gameboy, “interrupt” him when arrive at destination CPU does useful work while I/O busy

CS61C L14 Interrupts © UC Regents 5 OS: I/O Requirements °The OS must be able to prevent: The user program from communicating with the I/O device directly °If user programs could perform I/O directly: No protection to the shared I/O resources °3 types of communication are required: The OS must be able to give commands to the I/O devices The I/O device notify OS when the I/O device has completed an operation or an error Data transfers between memory and I/O device

CS61C L14 Interrupts © UC Regents 6 Review of Coprocessor 0 Registers °Coprocessor 0 Registers: name number usage BadVAddr $8 Addr of bad instr Status $12 Interrupt enable Cause $13 Exception type EPC $14 Instruction address °Different registers from integer registers, just as Floating Point has another set of registers independent from integer registers Floating Point called “Coprocessor 1”, has own set of registers and data transfer instructions

CS61C L14 Interrupts © UC Regents 7 Instruction Set Support for OS (1/2) °How to turn off interrupts during interrupt routine? °Bit in Status Register determines whether or not interrupts enabled: Interrupt Enable bit (IE) (0  off, 1  on) Status Register(described later) IE

CS61C L14 Interrupts © UC Regents 8 Instruction Set Support for OS (2/2) °How to prevent user program from turning off interrupts (forever)? Bit in Status Register determines whether in user mode or OS (kernel) mode: Kernel/User bit (KU) (0  kernel, 1  user) Status RegisterAssume Unused IEKU On exception/interrupt disable interrupts (IE=0) and go into kernel mode (KU=0)

CS61C L14 Interrupts © UC Regents 9 Kernel/User Mode °Generally restrict device access to OS °HOW? °Add a “mode bit” to the machine: K/U °Only allow SW in “kernel mode” to access device registers °If user programs could access device directly? could destroy each others data,... might break the devices, …

CS61C L14 Interrupts © UC Regents 10 Crossing the System Boundary °System loads user program into memory and ‘gives’ it use of the processor °Switch back SYSCALL -request service -I/O TRAP (overflow) Interrupt Proc Mem I/O Bus cmd reg. data reg. System User

CS61C L14 Interrupts © UC Regents 11 Syscall °How does user invoke the OS? syscall instruction: invoke the kernel (Go to 0x , change to kernel mode) By software convention, $v0 has system service requested: OS performs request

CS61C L14 Interrupts © UC Regents 12 SPIM OS Services via Syscall °Note: most OS services deal with I/O print_int1 $a0 = integer print_float2 $f12 = float print_double3 $f12 = double print_string4 $a0 = string read_int5integer (in $v0 ) read_float6float (in $f0 ) read_double7double (in $f0 ) read_string8 $a0 = buffer, $a1 = length sbrk9 $a0 = amountaddress(in $v0 ) exit10 ServiceCodeArgsResult (put in $v0 )

CS61C L14 Interrupts © UC Regents 13 Example: User invokes OS (SPIM) °Print “the answer = 42” °First print “the answer =”:.data str:.asciiz"the answer = ".text li $v0,4# 4=code for print_str la$a0,str# address of string syscall# print the string °Now print 42 li$v0,1# 1=code for print_int li$a0,42# integer to print syscall# print int

CS61C L14 Interrupts © UC Regents 14 Administrivia °Midterm will be Wed Oct P.M. 1 Pimintel Midterm conflicts? Talk to TA about taking early midterm ("beta tester") 2 sides of paper with handwritten notes; no calculators Sample midterm will be online soon (Monday?) Old midterms will be online soon °Rest of homework assignments are online: 6, 7, 8

CS61C L14 Interrupts © UC Regents 15 Handling a Single Interrupt (1/3) °An interrupt has occurred, then what? Automatically, the hardware copies PC into EPC ($14 on cop0) and puts correct code into Cause Reg ($13 on cop0) Automatically, PC is set to 0x , process enters kernel mode, and interrupt handler code begins execution Interrupt Handler code: Checks Cause Register (bits 5 to 2 of $13 in cop0) and jumps to portion of interrupt handler which handles the current exception

CS61C L14 Interrupts © UC Regents 16 Handling a Single Interrupt (2/3) °Sample Interrupt Handler Code.text 0x mfc0 $k0,$13 # $13 is Cause Reg sll $k0,$k0,26 # isolate srl $k0,$k0,28 # Cause bits °Notes: Don’t need to save $k0 or $k1 -MIPS software convention to provide temp registers for operating system routines -Application software cannot use them Can only work on CPU, not on cop0

CS61C L14 Interrupts © UC Regents 17 Handling a Single Interrupt (3/3) When the interrupt is handled, copy the value from EPC to the PC. Call instruction rfe (return from exception), which will return process to user mode and reset state to the way it was before the interrupt °What about multiple interrupts?

CS61C L14 Interrupts © UC Regents 18 Multiple Interrupts °Problem: What if we’re handling an Overflow interrupt and an I/O interrupt (printer ready, for example) comes in? °Options: drop any conflicting interrupts: unrealistic, they may be important simultaneously handle multiple interrupts: unrealistic, may not be able to synchronize them (such as with multiple I/O interrupts) queue them for later handling: sounds good

CS61C L14 Interrupts © UC Regents 19 Prioritized Interrupts (1/3) °Question: Suppose we’re dealing with a computer running a nuclear facility. What if we’re handling an Overflow interrupt and a Nuclear Meltdown Imminent interrupt comes in? °Answer: We need to categorize and prioritize interrupts so we can handle them in order of urgency: emergency vs. luxury.

CS61C L14 Interrupts © UC Regents 20 Prioritized Interrupts (2/3) °OS convention to simplify software: Process cannot be preempted by interrupt at same or lower "level" Return to interrupted code as soon as no more interrupts at a higher level When an interrupt is handled, take the highest priority interrupt on the queue -may be partially handled, may not, so we may need to save state of interrupts(!)

CS61C L14 Interrupts © UC Regents 21 Prioritized Interrupts (3/3) °To implement, we need an Exception Stack: portion of address space allocated for stack of “Exception Frames” each frame represents one interrupt: contains priority level as well as enough info to restart handling it if necessary

CS61C L14 Interrupts © UC Regents 22 Modified Interrupt Handler (1/3) °Problem: When an interrupt comes in, EPC and Cause get overwritten immediately by hardware. Lost EPC means loss of user program. °Solution: Modify interrupt handler. When first interrupt comes in: disable interrupts (in Status Register) save EPC, Cause, Status and Priority Level on Exception Stack re-enable interrupts continue handling current interrupt

CS61C L14 Interrupts © UC Regents 23 Modified Interrupt Handler (2/3) °When next (or any later) interrupt comes in: interrupt the first one disable interrupts (in Status Register) save EPC, Cause, Status and Priority Level (and maybe more) on Exception Stack determine whether new one preempts old one -if no, re-enable interrupts and continue with old one -if yes, may have to save state for the old one, then re-enable interrupts, then handle new one

CS61C L14 Interrupts © UC Regents 24 Modified Interrupt Handler (3/3) °Notes: Disabling interrupts is dangerous So we disable them for as short a time as possible: long enough to save vital info onto Exception Stack °This new scheme allows us to handle many interrupts effectively.

CS61C L14 Interrupts © UC Regents 25 Interrupt Levels in MIPS? °What are they? °It depends what the MIPS chip is inside of: differ by app Casio PalmPC, Sony Playstation, HP LaserJet printer ° MIPS architecture enables priorities for different I/O events

CS61C L14 Interrupts © UC Regents 26 Interrupt Levels in MIPS Architecture °Conventionally, from highest level to lowest level exception/interrupt levels: Bus error Illegal Instruction/Address trap High priority I/O Interrupt (fast response) Low priority I/O Interrupt (slow response) (later in course, will talk about other events with other levels)

CS61C L14 Interrupts © UC Regents 27 Improving Data Transfer Performance °Thus far: OS give commands to I/O, I/O device notify OS when the I/O device completed operation or an error °What about data transfer to I/O device? Processor busy doing loads/stores between memory and I/O Data Register °Ideal: specify the block of memory to be transferred, be notified on completion? Direct Memory Access (DMA) : a simple computer transfers a block of data to/from memory and I/O, interrupting upon done

CS61C L14 Interrupts © UC Regents 28 Example: code in DMA controller °DMA code from Disk Device to Memory.data Count:.word 4096 Start:.space 4096 °DMA “computer” in parallel with CPU.text Initial:lw $s0, Count# No. chars la $s1, char Wait:lw $s2, DiskControl andi $s2,$s2,1 # select Ready beq $s2,$0,Wait # spinwait lb $t0, DiskData # get byte sb $t0, 0($s1) # transfer addiu $s0,$s0,-1 # Count-- addiu $s1,$s1,1 # Start++ bne $s0,$0,Wait # next char

CS61C L14 Interrupts © UC Regents 29 Details not covered °MIPS has a field to record all pending interrupts so that none are lost while interrupts are off; in Cause register °The Interrupt Priority Level that the CPU is running at is set in memory °MIPS has a field in that can mask interrupts of different priorities to implement priority levels; in Status register °MIPS has limited nesting of saving KU,IE bits to recall in case higher priority interrupts; in Status Register

CS61C L14 Interrupts © UC Regents 30 Interrupts while serving interrupts? °Suppose there was an interrupt while the interrupt enable or mask bit is off: what should you do? (cannot ignore) °Cause register has field--Pending Interrupts (PI)-- 5 bits wide (bits15:11) for each of the 5 HW interrupt levels Bit becomes 1 when an interrupt at its level has occurred but not yet serviced Interrupt routine checks pending interrupts ANDed with interrupt mask to decide what to service Cause Register ExcCodePI

CS61C L14 Interrupts © UC Regents 31 support for OS: User => System mode Bit in Status Register determines whether in user mode or OS (kernel) mode: Kernel/User bit (KU) (0  kernel, 1  user) Status Register(described later) IEKU On exception/interrupt disable interrupts (IE=0) and go into kernel mode (KU=0) °How remember old KU, IE bits? Hardware copies Current KU and IE bits (0-1) into Previous KU and IE bits (2-3) Status Register (described later) IEKUIEKU 00

CS61C L14 Interrupts © UC Regents 32 support for OS: System => user mode °OS saves user registers, performs its task and restores user registers. can JR back to value saved in EPC how to get back to user mode? °use Return from Exception ( rfe ) Status Register (described later) IE KUKU KUKU

CS61C L14 Interrupts © UC Regents 33 Prioritizing Interrupts °How implement interrupt levels? °Allow selective interruption via Interrupt Mask(IM) in Status Register: 5 for HW interrupts Interrupt only if IE==1 AND Mask bit == 1 (bits 15:11 of SR) for that interrupt level Set Mask Bits above your level to 1 °To support interrupts of interrupts, have 3 deep stack in Status for IE,K/U bits: Current (1:0), Previous (3:2), Old (5:4) IEKU Status Register IEKUIEKU IM CPO 00

CS61C L14 Interrupts © UC Regents 34 Revised Interrupt Routine 2/2 °Jump to appropriate interrupt routine °On Return, disable interrupts using Current IE bit of Status Register °Then restore saved registers, previous KU,IE bits of Status (via rfe ) and return to instruction determined by old EPC rfe IEKUIEKUIEKU IM Status Reg After IEKU Status Reg Before IEKUIEKU IM CurrentPre.Old

CS61C L14 Interrupts © UC Regents 35 Re-entrant Interrupt Routine? °How allow interrupt of interrupts and safely save registers? °Stack? Resources consumed by each exception, so cannot tolerate arbitrary deep nesting of exceptions/interrupts °With priority level system only interrupted by higher priority interrupt, so cannot be recursive  Only need one save area (“exception frame”) per priority level

CS61C L14 Interrupts © UC Regents 36 Things to Remember °Kernel Mode v. User Mode: OS can provide security and fairness °Syscall: provides a way for a programmer to avoid having to know details of each I/O device °To be acceptable, interrupt handler must: service all interrupts (no drops) service by priority make all users believe that no interrupt has occurred