CS61C - Machine Structures Lecture 14 - Input/Output

Slides:



Advertisements
Similar presentations
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief Johny Moningka
Advertisements

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.
EE30332 Ch8 DP – 1 Ch 8 Interfacing Processors and Peripherals Buses °Fundamental tool for designing and building computer systems divide the problem into.
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Lecture 36: IO Basics Instructor: Dan Garcia
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
CS 430 – Computer Architecture 1 CS 430 – Computer Architecture Input/Output: Polling and Interrupts William J. Taffe using the slides of David Patterson.
1: Operating Systems Overview
CS61C L18 Introduction to CPU Design (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
CS61C L13 I/O © UC Regents 1 CS61C - Machine Structures Lecture 13 - Input/Output: Polling and Interrupts October 11, 2000 David Patterson
CS 61C L39 I/O (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
CS61C L37 I/O (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
Cs 61C L12 I/O.1 Patterson Spring 99 ©UCB CS61C Input/Output Lecture 12 February 26, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html.
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).
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
LOGO OPERATING SYSTEM Dalia AL-Dabbagh
Operating System Review September 10, 2012Introduction to Computer Security ©2004 Matt Bishop Slide #1-1.
Input and Output Computer Organization and Assembly Language: Module 9.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
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.
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.
MIPS I/O and Interrupt.
CS2100 Computer Organisation Input/Output – Own reading only (AY2015/6) Semester 1 Adapted from David Patternson’s lecture slides:
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Lecture 37: IO Basics Instructor: Dan Garcia
Adapted from Computer Organization and Design, Patterson & Hennessy ECE232: Hardware Organization and Design Part 17: Input/Output Chapter 6
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.
Processor Memory Processor-memory bus I/O Device Bus Adapter I/O Device I/O Device Bus Adapter I/O Device I/O Device Expansion bus I/O Bus.
بسم الله الرحمن الرحيم 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.
Chapter 8 Input/Output An Hong 2015 Fall School of Computer Science and Technology Lecture on Introduction to.
Input / Output Chapter 9.
Chapter 8 I/O.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
Processes and threads.
Operating Systems CMPSC 473
Computer System Structures
MIPS I/O and Interrupt.
Operating Systems (CS 340 D)
Computer Architecture
Inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 35 – Input / Output Lecturer SOE Dan Garcia
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Chapter 8 I/O.
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
MIPS I/O and Interrupt.
Computer Architecture
MIPS I/O and Interrupt.
Chapter 8 I/O.
Komponen Dasar Sistem Komputer
Processor Fundamentals
Operating Systems Chapter 5: Input/Output Management
Operating Systems.
Chapter 8 I/O.
Guest Lecturer TA: Shreyas Chand
Interrupts and Exception Handling
Welcome to Architectures of Digital Systems
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.
Chapter 8 I/O.
Lectures 9-1: I/O Interfacing
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
COMP3221: Microprocessors and Embedded Systems
Chapter 13: I/O Systems.
Interrupts and Exception Handling
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

CS61C - Machine Structures Lecture 14 - Input/Output July 12, 2000 Brenda Liu http://www-inst.eecs.berkeley.edu/~cs61c/ Greet class

Outline I/O Background Polling Interrupts

Anatomy: 5 components of any Computer Keyboard, Mouse Computer Processor (active) Memory (passive) (where programs, data live when running) Devices Disk (where programs, data live when not running) Input Control (“brain”) Output That is, any computer, no matter how primitive or advance, can be divided into five parts: 1. The input devices bring the data from the outside world into the computer. 2. These data are kept in the computer’s memory until ... 3. The datapath request and process them. 4. The operation of the datapath is controlled by the computer’s controller. All the work done by the computer will NOT do us any good unless we can get the data back to the outside world. 5. Getting the data back to the outside world is the job of the output devices. The most COMMON way to connect these 5 components together is to use a network of busses. Datapath (“brawn”) Display, Printer

Motivation for Input/Output I/O is how humans interact with computers Computer without I/O like a car without wheels; great technology, but won’t get you anywhere

I/O Device Examples and Speeds I/O Speed: bytes transferred per second (from mouse to display: million-to-1) Device Behavior Partner Data Rate (Kbytes/sec) Keyboard Input Human 0.01 Mouse Input Human 0.02 Line Printer Output Human 1.00 Floppy disk Storage Machine 50.00 Laser Printer Output Human 100.00 Magnetic Disk Storage Machine 10,000.00 Network-LAN I or O Machine 10,000.00 Graphics Display Output Human 30,000.00 Here are some examples of the various I/O devices you are probably familiar with. Notice that most I/O devices that has human as their partner usually has relatively low peak data rates because human in general are slow relatively to the computer system. The exceptions are the laser printer and the graphic displays. Laser printer requires a high data rate because it takes a lot of bits to describe high resolution image you like to print by the laser writer. The graphic display requires a high data rate because as I will show you later in today’s lecture, all the color objects we see in the real world and taken for granted is very hard to replicate on a graphic display. Let’s take a closer look at one of the most popular storage device, magnetic disks. +2 = 28 min. (Y:08)

Instruction Set Architecture for I/O Some machines have special input and output instructions Alternative model (used by MIPS): Input: ~ reads a sequence of bytes Output: ~ writes a sequence of bytes Memory also a sequence of bytes, so use loads for input, stores for output Called “Memory Mapped Input/Output” A portion of the address space dedicated to communication paths to Input or Output devices (no memory there)

Processor-I/O Speed Mismatch 500 MHz microprocessor can execute 500 million load or store instructions per second, or 2,000,000 KB/s data rate I/O devices from 0.01 KB/s to 30,000 KB/s Input: device may not be ready to send data as fast as the processor loads it Also, might be waiting for human to act Output: device may not be ready to accept data as fast as processor stores it What to do?

Processor Checks Status before Acting Path to device generally has 2 registers: 1 register says it’s OK to read/write (I/O ready), often called Control Register 1 register that contains data, often called Data Register Processor reads from Control Register in loop, waiting for device to set Ready bit in Control reg to say its OK (0  1) Processor then loads from (input) or writes to (output) data register Load from device/Store into Data Register resets Ready bit (1  0) of Control Register

SPIM I/O Simulation SPIM simulates 1 I/O device: memory- mapped terminal (keyboard + display) Read from keyboard (receiver); 2 device regs Writes to terminal (transmitter); 2 device regs (IE) Receiver Control 0xffff0000 Ready (I.E.) Unused (00...00) Received Byte Receiver Data 0xffff0004 Unused (00...00) Transmitted Byte Transmitter Control 0xffff0008 Transmitter Data 0xffff000c Ready (I.E.) Unused (00...00) Unused

Control register rightmost bit (0): Ready SPIM I/O Control register rightmost bit (0): Ready Receiver: Ready==1 means character in Data Register not yet been read; 1  0 when data is read from Data Reg Transmitter: Ready==1 means transmitter is ready to accept a new character; 0  Transmitter still busy writing last char I.E. bit discussed later Data register rightmost byte has data Receiver: last char from keyboard; rest = 0 Transmitter: when write rightmost byte, writes char to display

I/O Example Input: Read from keyboard into $v0 lui $t0, 0xffff #ffff0000 Waitloop: lw $t1, 0($t0) #control andi $t1,$t1,0x0001 beq $t1,$zero, Waitloop lw $v0, 4($t0) #data Output: Write to display from $a0 lui $t0, 0xffff #ffff0000 Waitloop: lw $t1, 8($t0) #control andi $t1,$t1,0x0001 beq $t1,$zero, Waitloop sw $a0, 12($t0) #data Processor waiting for I/O called “Polling”

Midterm will be next Monday 11-1pm Administrivia (1/2) Midterm will be next Monday 11-1pm Review: Sunday 7/16 2-5 306 Soda Conflict? E-mail brendal@eecs ASAP Material up to and including yesterday’s lecture Sample midterm hand out tomorrow Proj1 grading done Run ‘glookup’ to see how you did This is the 1st slide of the “Course Structure and Course Philosophy” section of the lecture. Need to emphasis that for exams, our goal is the test your knowledge. It is not our goal to test how well your perform under time pressure.

Project 3 immediate printing: Administrivia (2/2) Project 3 immediate printing: If the immediate is a signed number, print it out in decimal (addi, slti, etc) If the immediate is an unsigned number (but not an address), print it out in hex without padding (andi, ori, etc) If the immediate is an address, print it out in hex and pad 0's in front of it to make a total of 8 hex digits (beq, j, etc) Reading assignment: None, study for midterm This is the 1st slide of the “Course Structure and Course Philosophy” section of the lecture. Need to emphasis that for exams, our goal is the test your knowledge. It is not our goal to test how well your perform under time pressure.

Cost of Polling? Assume for a processor with a 500-MHz clock it takes 400 clock cycles for a polling operation (call polling routine, accessing the device, and returning). Determine % of processor time for polling Mouse: polled 30 times/sec so as not to miss user movement Floppy disk: transfers data in 2-byte units and has a data rate of 50 KB/second. No data transfer can be missed. Hard disk: transfers data in 16-byte chunks and can transfer at 8 MB/second. Again, no transfer can be missed.

% Processor time to poll mouse, floppy Mouse Polling Clocks/sec = 30 * 400 = 12000 clocks/sec % Processor for polling: 12*103/500*106 = 0.002%  Polling mouse little impact on processor Times Polling Floppy/sec = 50 KB/s /2B = 25K polls/sec Floppy Polling Clocks/sec = 25K * 400 = 10,000,000 clocks/sec 10*106/500*106 = 2%  OK if not too many I/O devices

% Processor time to hard disk Times Polling Disk/sec = 8 MB/s /16B = 500K polls/sec Disk Polling Clocks/sec = 500K * 400 = 200,000,000 clocks/sec % Processor for polling: 200*106/500*106 = 40%  Unacceptable

What is the alternative to polling? Wasteful to have processor spend most of its time “spin-waiting” for I/O to be ready Wish we could have an unplanned procedure call that would be invoked only when I/O device is ready Solution: use exception mechanism to help I/O. Interrupt program when I/O ready, return when done with data transfer

An I/O interrupt is like an overflow exceptions except: An I/O interrupt is “asynchronous” More information needs to be conveyed An I/O interrupt is asynchronous with respect to instruction execution: I/O interrupt is not associated with any instruction, but it can happen in the middle of any given instruction I/O interrupt does not prevent any instruction from completion How does an I/O interrupt different from the exception you already learned? Well, an I/O interrupt is asynchronous with respect to the instruction execution while exception such as overflow or page fault are always associated with a certain instruction. Also for exception, the only information needs to be conveyed is the fact that an exceptional condition has occurred but for interrupt, there is more information to be conveyed. Let me elaborate on each of these two points. Unlike exception, which is always associated with an instruction, interrupt is not associated with any instruction. The user program is just doing its things when an I/O interrupt occurs. So I/O interrupt does not prevent any instruction from completing so you can pick your own convenient point to take the interrupt. As far as conveying more information is concerned, the interrupt detection hardware must somehow let the OS know who is causing the interrupt. Furthermore, interrupt requests needs to be prioritized. The hardware that can do all these looks like this. +2 = 64 min. (Y:44)

Definitions for Clarification Exception: signal marking that something “out of the ordinary” has happened and needs to be handled Interrupt: asynchronous exception Trap: synchronous exception Note: These are different from the book’s definitions.

Interrupt Driven Data Transfer Memory add sub and or user program (1) I/O interrupt (2) save PC (5) (3) interrupt service addr (4) That is, whenever an I/O device needs attention from the processor, it interrupts the processor from what it is currently doing. This is how an I/O interrupt looks in the overall scheme of things. The processor is minding its business when one of the I/O device wants its attention and causes an I/O interrupt. The processor then save the current PC, branch to the address where the interrupt service routine resides, and start executing the interrupt service routine. When it finishes executing the interrupt service routine, it branches back to the point of the original program where we stop and continue. The advantage of this approach is efficiency. The user program’s progress is halted only during actual transfer. The disadvantage is that it require special hardware in the I/O device to generate the interrupt. And on the processor side, we need special hardware to detect the interrupt and then to save the proper states so we can resume after the interrupt. +2 = 62 min. (Y:42) read store ... jr interrupt service routine

Instruction Set Support for I/O Interrupt Save the PC for return But where? Where go when interrupt occurs? MIPS defines location: 0x80000080 Determine cause of interrupt? MIPS has Cause Register, 4-bit field (bits 5 to 2) gives cause of exception

Instruction Set Support for I/O Interrupt Portion of MIPS architecture for interrupts called “coprocessor 0” Coprocessor 0 Instructions Data transfer: lwc0, swc0 Move: mfc0, mtc0 Coprocessor 0 Registers: name number usage BadVAddr $8 Address of Int Status……. $12 Interrupt enable Cause $13 Exception type EPC $14 Return address

SPIM I/O Simulation: Interrupt Driven I/O I.E. stands for Interrupt Enable Set Interrupt Enable bit to 1 have interrupt occur whenever Ready bit is set Received Byte Transmitted Byte (IE) Receiver Control 0xffff0000 Transmitter Control 0xffff0008 Transmitter Data 0xffff000c Receiver Data 0xffff0004 Ready (I.E.) Unused (00...00) Unused

Benefit of Interrupt-Driven I/O 500 clock cycle overhead for each transfer, including interrupt. Find the % of processor consumed if the hard disk is only active 5% of the time. Interrupt rate = polling rate Disk Interrupts/sec = 8 MB/s /16B = 500K interrupts/sec Disk Polling Clocks/sec = 500K * 500 = 250,000,000 clocks/sec % Processor for during transfer: 250*106/500*106= 50% Disk active 5%  5% * 50%  2.5% busy

Questions Raised about Interrupts Which I/O device caused exception? Needs to convey the identity of the device generating the interrupt Can avoid interrupts during the interrupt routine? What if more important interrupt occurs while servicing this interrupt? Allow interrupt routine to be entered again? Who keeps track of status of all the devices, handle errors, know where to put/supply the I/O data?

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

4 Functions OS must provide OS guarantees that user’s program accesses only the portions of I/O device to which user has rights (e.g., file access) OS provides abstractions for accessing devices by supplying routines that handle low-level device operations OS handles the exceptions generated by I/O devices (and arithmetic exceptions generated by a program) OS tries to provide equitable access to the shared I/O resources, as well as schedule accesses in order to enhance system performance

Things to Remember 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