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.

Slides:



Advertisements
Similar presentations
Categories of I/O Devices
Advertisements

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.
Input and Output CS 215 Lecture #20.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
CS61C L26 Interrupt Review © UC Regents 1 CS61C - Machine Structures Lecture 26 - Review of Interrupts December 6, 2000 David Patterson
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.
1: Operating Systems Overview
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS61C L14 Interrupts © UC Regents 1 CS61C - Machine Structures Lecture 14 - Operating System Support and Prioritized Interrupts October (Friday the) 13(th),
Computer System Organization S H Srinivasan
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
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
Appendix A: MIPS Assembly Language. Instruction Format R-type I-type J-type.
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.
Chapter 2: Computer-System Structures
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.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
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.
System Calls 1.
COMP201 Computer Systems Exceptions and Interrupts.
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
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.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
I/O Computer Organization II 1 Interconnecting Components Need interconnections between – CPU, memory, I/O controllers Bus: shared communication channel.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
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.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
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.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Operating Systems CMPSC 473
Microprocessor Systems Design I
MIPS I/O and Interrupt.
CS703 - Advanced Operating Systems
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
Operating Systems Chapter 5: Input/Output Management
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.
COMS 361 Computer Organization
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.
Interrupts and exceptions
Interrupts and Exception Handling
Presentation transcript:

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 (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html

cs 61C L13 I/O.2 Patterson Spring 99 ©UCB Review 1/2 °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 °Interrupts works, more complex °I/O control leads to Operating Systems

cs 61C L13 I/O.3 Patterson Spring 99 ©UCB Review 2/2: 4 Responsibilities leading to OS °The I/O system is shared by multiple programs using the processor °Low-level control of I/O device is complex because requires managing a set of concurrent events and because requirements for correct device control are often very detailed °I/O systems often use interrupts to communicate information about I/O operations °Would like I/O services for all user programs, under safe control

cs 61C L13 I/O.4 Patterson Spring 99 ©UCB Outline °Instruction Set support for OS °Administrivia, “What’s this stuff Good for” °Prioritizing Interrupts °Re-entrant Interrupt Routine °Direct Memory Access °Conclusion

cs 61C L13 I/O.5 Patterson Spring 99 ©UCB OS, I/O Communication 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 transferred between memory and I/O device

cs 61C L13 I/O.6 Patterson Spring 99 ©UCB Review Coprocessor Registers °Coprocessor 0 Registers: name number usage BadVAddr $8 Bad memory address Status $12 Interrupt enable Cause $13 Exception type EPC $14 Instruction address °Different registers from integer registers, just as Floating Point is another set of registers independent from integer registers Floating Point called “Coprocessor 1”, has own set of registers and data transfer instructions

cs 61C L13 I/O.7 Patterson Spring 99 ©UCB Instruction Set support for OS °How 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

cs 61C L13 I/O.8 Patterson Spring 99 ©UCB Instruction Set support for OS °How 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 Register(described later) IEKU On exception/interrupt disable interrupts (IE=0) and go into kernel mode (UK=0) °How remember old IE, U/K bits? Hardware copies Current IE and UK bits (0-1) into Previous IE UK bits (2-3) Status Register (described later) IEKUIEKU 00

cs 61C L13 I/O.9 Patterson Spring 99 ©UCB How communicate between OS and user? °OS to user No restrictions on OS; can modify registers or memory visible to user program To restore previous Kernel/User bits after interrupt, use Return from Exception ( rfe ) °User to OS syscall instruction: invoke the kernel (Go to 0x , change to kernel mode) By software convention, $v0 has system service requested: OS performs request

cs 61C L13 I/O.10 Patterson Spring 99 ©UCB SPIM OS Services via syscall ServiceCodeArgsResult (put in $v0 ) 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 °Note: most OS services deal with I/O

cs 61C L13 I/O.11 Patterson Spring 99 ©UCB Example: User invokes OS (SPIM) °Print “the answer = 5” °First print “the answer =”:.data str:.asciiz"the answer = ".text li $v0, 4# code for print_str la$a0, str# address of string syscall# print the string °Now print 5 li$v0, 1# code for print_int li$a0, 5# integer to print syscall# print it

cs 61C L13 I/O.12 Patterson Spring 99 ©UCB Relationship Memory Mapped I/O & Syscall? °“Warning: Programs that use these syscalls to read from the terminal should not use memory-mapped I/O.” (Ap. A, p. A-49) °Why? °OS is using memory mapped I/O to provide a high level I/O abstraction to user programs; cannot violate abstraction and have it work

cs 61C L13 I/O.13 Patterson Spring 99 ©UCB Administrivia °Readings: I/O 8.9 °3rd Project: Today 7PM (Th. 8AM deadline) °6th homework: Due 3/10 7PM Exercises 8.3, 8.29 (skip challenge), Ap A.3 °4th Project: Friday 3/12 7PM (thank TAs!) (deadline Saturday 3/13 8AM) °Upcoming events Midterm Review Sunday 3/14 2PM, 1 Pimentel Midterm on Wed. 3/17 5pm-8PM, 1 Pimentel 2nd online questionnaire when in lab 3/16-17

cs 61C L13 I/O.14 Patterson Spring 99 ©UCB “What’s This Stuff Good For?” Computers can't yet replace the human eye, but advanced technology is enabling the blind to join a world previously inaccessible to them. Kent Cullers, a prominent astrophysicist who is also blind, observes, "I interact as many other people do nowadays, through their machines. And the wonder of the technology is that I can do the job just as well as many other people can.” One Digital Day, 1998 ( Blind since birth, five-year- old Amy Stewart learns to read by computer, keeping up with the sighted kids in her first-grade class. The computer converts written lessons into Braille printouts.

cs 61C L13 I/O.15 Patterson Spring 99 ©UCB Basic Interrupt Routine °Save several registers and $ra in memory for use in interrupt routine °Get EPC and select exception code field from Cause Register °Jump and link via jump table to appropriate routine based on ExpCode field in Cause (I/O interrupt, System call, Arithmetic Overflow) Single interrupt address (0x )  jump table °Return to code to restore registers, previous IE, UK bits ( rfe ) and return to instruction determined by old EPC

cs 61C L13 I/O.16 Patterson Spring 99 ©UCB Prioritizing Interrupts °Some interrupts have higher priority Alternative to blocking all interrupts? °Categorize interrupts and exceptions into levels, and 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:0 of SR) for that interrupt level 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

cs 61C L13 I/O.17 Patterson Spring 99 ©UCB Handling Prioritized Interrupts °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 Any piece of code is always run at same priority level

cs 61C L13 I/O.18 Patterson Spring 99 ©UCB 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 ° Hardware box designer associates I/O events with pins of MIPS chips according to needs of application MIPS architecture enables priorities

cs 61C L13 I/O.19 Patterson Spring 99 ©UCB Interrupt Levels in MIPS Architecture °Conventionally, from highest level to lowest level exception/interrupt levels: 1) Bus error 2) Illegal Instruction/Address trap 3) High priority I/O Interrupt (fast response) 4) Low priority I/O Interrupt (slow response) (later in course will add more levels)

cs 61C L13 I/O.20 Patterson Spring 99 ©UCB Interrupt Levels in MIPS Software °Conventionally, UNIX software system designed to have 4 to 6 Interrupt Priority Levels (IPL) that match the HW interrupt levels °Processor always executing at one IPL, stored in a memory location and Status Register set accordingly Processor at lowest IPL level, any interrupt accepted Processor at highest IPL level, all interrupt ignored Interrupt handlers and device drivers pick IPL to run at, faster response for some

cs 61C L13 I/O.21 Patterson Spring 99 ©UCB Interrupt levels °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:10) 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

cs 61C L13 I/O.22 Patterson Spring 99 ©UCB Revised Interrupt Routine 1/2 °Get EPC and Cause Register °Save EPC, CR, $ra and some registers in memory for use in interrupt routine °Jump and link via jump table to appropriate exception/interrupt routine °If I/O, Cause Register IP field ANDed to Status Register IM field to find unmasked interrupts (maybe several); pick highest °Change IM of Status Register to inhibit current level and lower priority interrupts °Change Current IE of Status Register to enable interrupts (higher priority)

cs 61C L13 I/O.23 Patterson Spring 99 ©UCB 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 IE/UK 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

cs 61C L13 I/O.24 Patterson Spring 99 ©UCB 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

cs 61C L13 I/O.25 Patterson Spring 99 ©UCB Improving Data Transfer Performance °Thus far: OS give commands to I/O, I/O device notifies 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 °Idea: 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

cs 61C L13 I/O.26 Patterson Spring 99 ©UCB Example: Direct Memory Access °DMA from Disk Device to Memory at Start, for 4096 bytes.data Count:.word 4096 Start:.space 4096.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 ° DMA “computer” in parallel with CPU

cs 61C L13 I/O.27 Patterson Spring 99 ©UCB History °Th 10:44PM, Rev 731, 6892 min °Sa 10:57PM, Rev 782, 7712 min °Su 6:16 AM, Rev 787, min 7765 °Sun 6:23 PM, Rev 789, 7782 min ° =890 minutes, or 15 hours °/ 26 slides = minutes/slide