CS61C L25 I/O (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #25: I/O 2005-08-03 Andy Carle.

Slides:



Advertisements
Similar presentations
Input and Output CS 215 Lecture #20.
Advertisements

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
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Lecture 36: IO Basics Instructor: Dan Garcia
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.
CS61C L36 Input / Output (1) Garcia, Spring 2007 © UCB Robson disk $  Intel has a NAND flash-based disk cache which can speed up access for laptops and.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 34 – Input / Output “Arduino is an open-source electronics prototyping.
CS 430 – Computer Architecture 1 CS 430 – Computer Architecture Input/Output: Polling and Interrupts William J. Taffe using the slides of David Patterson.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
CS61C L24 Input/Output, Networks I (1) Garcia, Fall 2005 © UCB Lecturer PSOE, new dad Dan Garcia inst.eecs.berkeley.edu/~cs61c.
OS Spring’03 Introduction Operating Systems Spring 2003.
CS61C L14 Interrupts © UC Regents 1 CS61C - Machine Structures Lecture 14 - Operating System Support and Prioritized Interrupts October (Friday the) 13(th),
CS61C L26 Virtual Memory II (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #26.
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.
COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II
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.
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.
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.
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.
Input and Output Computer Organization and Assembly Language: Module 9.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
CS 61C L6.2.2 Interrupts (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Interrupts Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
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.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
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.
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
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
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.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
بسم الله الرحمن الرحيم MEMORY AND I/O.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
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.
CS 110 Computer Architecture Lecture 22: Operating Systems, Interrupts, Virtual Memory Instructor: Sören Schwertfeger School.
MIPS I/O and Interrupt.
Inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 35 – Input / Output Lecturer SOE Dan Garcia
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.
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.
CS61C - Machine Structures Lecture 14 - Input/Output
COMP3221: Microprocessors and Embedded Systems
Interrupts and Exception Handling
Presentation transcript:

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

CS61C L25 I/O (2) A Carle, Summer 2005 © UCB Review Virtual memory to Physical Memory Translation too slow? Add a cache of Virtual to Physical Address Translations, called a TLB Spatial Locality means Working Set of Pages is all that must be in memory for process to run fairly well Virtual Memory allows protected sharing of memory between processes with less swapping to disk

CS61C L25 I/O (3) A Carle, Summer 2005 © UCB Recall : 5 components of any Computer Processor (active) Computer Control (“brain”) Datapath (“brawn”) Memory (passive) (where programs, data live when running) Devices Input Output Keyboard, Mouse Display, Printer Disk, Network Earlier LecturesCurrent Lectures

CS61C L25 I/O (4) A Carle, Summer 2005 © UCB Motivation for Input/Output I/O is how humans interact with computers I/O gives computers long-term memory. I/O lets computers do amazing things: Read pressure of synthetic hand and control synthetic arm and hand of fireman Control propellers, fins, communicate in BOB (Breathable Observable Bubble) Computer without I/O like a car without wheels; great technology, but won’t get you anywhere

CS61C L25 I/O (5) A Carle, Summer 2005 © UCB I/O Device Examples and Speeds I/O Speed: bytes transferred per second (from mouse to Gigabit LAN: 10-million-to-1) DeviceBehaviorPartner Data Rate (KBytes/s) KeyboardInputHuman0.01 MouseInputHuman0.02 Voice outputOutputHuman5.00 Floppy diskStorageMachine50.00 Laser PrinterOutputHuman Magnetic DiskStorageMachine10, Wireless NetworkI or OMachine 10, Graphics DisplayOutputHuman30, Wired LAN NetworkI or OMachine125, When discussing transfer rates, use 10 x

CS61C L25 I/O (6) A Carle, Summer 2005 © UCB What do we need to make I/O work? A way to present them to user programs so they are useful cmd reg. data reg. Operating System APIsFiles Proc Mem A way to connect many types of devices to the Proc-Mem PCI Bus SCSI Bus A way to control these devices, respond to them, and transfer data

CS61C L25 I/O (7) A Carle, Summer 2005 © UCB Instruction Set Architecture for I/O What must the processor do for I/O? Input: reads a sequence of bytes Output: writes a sequence of bytes Some processors have special input and output instructions Alternative model (used by MIPS): 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)

CS61C L25 I/O (8) A Carle, Summer 2005 © UCB Memory Mapped I/O Certain addresses are not regular memory Instead, they correspond to registers in I/O devices cntrl reg. data reg. 0 0xFFFFFFFF 0xFFFF0000 address

CS61C L25 I/O (9) A Carle, Summer 2005 © UCB Processor-I/O Speed Mismatch 1GHz microprocessor can execute 1 billion load or store instructions per second, or 4,000,000 KB/s data rate I/O devices data rates range from 0.01 KB/s to 125,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 not be ready to accept data as fast as processor stores it What to do?

CS61C L25 I/O (10) A Carle, Summer 2005 © UCB Processor Checks Status before Acting Path to device generally has 2 registers: Control Register, says it’s OK to read/write (I/O ready) [think of a flagman on a road] Data Register, contains data Processor reads from Control Register in loop, waiting for device to set Ready bit in Control reg (0  1) to say its OK Processor then loads from (input) or writes to (output) data register Load from or Store into Data Register resets Ready bit (1  0) of Control Register

CS61C L25 I/O (11) A Carle, Summer 2005 © UCB 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 Received Byte Receiver Data 0xffff0004 Unused ( ) (IE) Receiver Control 0xffff0000 Ready (I.E.) Unused ( ) Transmitted Byte Transmitter Control 0xffff0008 Transmitter Data 0xffff000c Ready (I.E.) Unused ( ) Unused

CS61C L25 I/O (12) A Carle, Summer 2005 © UCB 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

CS61C L25 I/O (13) A Carle, Summer 2005 © UCB I/O Example Input: Read from keyboard into $v0 lui$t0, 0xffff #ffff0000 Waitloop:lw$t1, 0($t0) #control andi$t1,$t1,0x1 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,0x1 beq$t1,$zero, Waitloop sw$a0, 12($t0) #data Processor waiting for I/O called “Polling” “Ready” bit from processor’s point of view!

CS61C L25 I/O (14) A Carle, Summer 2005 © UCB Administrivia Project 3 Due Friday Project 4 Out Soon Final Exam will be Next Friday!

CS61C L25 I/O (15) A Carle, Summer 2005 © UCB Cost of Polling? Assume for a processor with a 1GHz 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 16 MB/second. Again, no transfer can be missed.

CS61C L25 I/O (16) A Carle, Summer 2005 © UCB % Processor time to poll [p. 677 in book] Mouse Polling, Clocks/sec = 30 [polls/s] * 400 [clocks/poll] = 12K [clocks/s] % Processor for polling: 12*10 3 [clocks/s] / 1*10 9 [clocks/s] = %  Polling mouse little impact on processor Frequency of Polling Floppy = 50 [KB/s] / 2 [B/poll] = 25K [polls/s] Floppy Polling, Clocks/sec = 25K [polls/s] * 400 [clocks/poll] = 10M [clocks/s] % Processor for polling: 10*10 6 [clocks/s] / 1*10 9 [clocks/s] = 1%  OK if not too many I/O devices

CS61C L25 I/O (17) A Carle, Summer 2005 © UCB % Processor time to poll hard disk Frequency of Polling Disk = 16 [MB/s] / 16 [B] = 1M [polls/s] Disk Polling, Clocks/sec = 1M [polls/s] * 400 [clocks/poll] = 400M [clocks/s] % Processor for polling: 400*10 6 [clocks/s] / 1*10 9 [clocks/s] = 40%  Unacceptable

CS61C L25 I/O (18) A Carle, Summer 2005 © UCB What is the alternative to polling? Wasteful to have processor spend most of its time “spin-waiting” for I/O to be ready Would like 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

CS61C L25 I/O (19) A Carle, Summer 2005 © UCB I/O Interrupt An I/O interrupt is like 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

CS61C L25 I/O (20) A Carle, Summer 2005 © UCB 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: Many systems folks say “interrupt” to mean what we mean when we say “exception”.

CS61C L25 I/O (21) A Carle, Summer 2005 © UCB Interrupt Driven Data Transfer (1) I/O interrupt (2) save PC Memory add sub and or user program read store... jr interrupt service routine (3) jump to interrupt service routine (4) perform transfer (5)

CS61C L25 I/O (22) A Carle, Summer 2005 © UCB 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 Receiver Data 0xffff0004 Unused ( ) (IE) Receiver Control 0xffff0000 Ready (I.E.) Unused ( ) Transmitted Byte Transmitter Control 0xffff0008 Transmitter Data 0xffff000c Ready (I.E.) Unused ( ) Unused

CS61C L25 I/O (23) A Carle, Summer 2005 © UCB Benefit of Interrupt-Driven I/O Find the % of processor consumed if the hard disk is only active 5% of the time. Assuming 500 clock cycle overhead for each transfer, including interrupt: Disk Interrupts/s = 16 MB/s / 16B/interrupt = 1M interrupts/s Disk Interrupts, clocks/s = 1M interrupts/s * 500 clocks/interrupt = 500,000,000 clocks/s % Processor for during transfer: 500*10 6 / 1*10 9 = 50% Disk active 5%  5% * 50%  2.5% busy

CS61C L25 I/O (24) A Carle, Summer 2005 © UCB Generalizing Interrupts We can handle all sorts of exceptions with interrupts. Big idea: jump to handler that knows what to do with each interrupt, then jump back Our types: syscall, overflow, mmio ready.

CS61C L25 I/O (25) A Carle, Summer 2005 © UCB 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 L25 I/O (26) A Carle, Summer 2005 © UCB 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 L25 I/O (27) A Carle, Summer 2005 © UCB 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 L25 I/O (28) A Carle, Summer 2005 © UCB 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 L25 I/O (29) A Carle, Summer 2005 © UCB 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 L25 I/O (30) A Carle, Summer 2005 © UCB 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 L25 I/O (31) A Carle, Summer 2005 © UCB 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 L25 I/O (32) A Carle, Summer 2005 © UCB 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 L25 I/O (33) A Carle, Summer 2005 © UCB 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 L25 I/O (34) A Carle, Summer 2005 © UCB 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 L25 I/O (35) A Carle, Summer 2005 © UCB 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 L25 I/O (36) A Carle, Summer 2005 © UCB 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 L25 I/O (37) A Carle, Summer 2005 © UCB 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 L25 I/O (38) A Carle, Summer 2005 © UCB 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 L25 I/O (39) A Carle, Summer 2005 © UCB 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 L25 I/O (40) A Carle, Summer 2005 © UCB 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 L25 I/O (41) A Carle, Summer 2005 © UCB 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 L25 I/O (42) A Carle, Summer 2005 © UCB 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 L25 I/O (43) A Carle, Summer 2005 © 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 MIPS architecture enables priorities for different I/O events

CS61C L25 I/O (44) A Carle, Summer 2005 © UCB 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) Others

CS61C L25 I/O (45) A Carle, Summer 2005 © UCB 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 L25 I/O (46) A Carle, Summer 2005 © UCB 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 L25 I/O (47) A Carle, Summer 2005 © UCB 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 L25 I/O (48) A Carle, Summer 2005 © UCB Implementation? Take 150 & 152

CS61C L25 I/O (49) A Carle, Summer 2005 © UCB Peer Instruction A. A faster CPU will result in faster I/O. B. Hardware designers handle mouse input with interrupts since it is better than polling in almost all cases. C. Low-level I/O is actually quite simple, as it’s really only reading and writing bytes.

CS61C L25 I/O (50) A Carle, Summer 2005 © UCB “And in conclusion…” I/O gives computers their 5 senses I/O speed range is 100-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