1Chapter 5: I/O SystemsChapter 52CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Input/Output Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks Character-oriented terminals Graphical user interfaces Network terminals Power managementChapter 53CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)How fast is I/O hardware?4MB/secDigital camcorder500 MB/secPCI bus60 MB/secXGA monitor50 MB/secFireWire (IEEE 1394)20 MB/secHard drive12.5 MB/secFast Ethernet1.5 MB/secUSB200 KB/secPrinter / scanner7KB/sec56K modem100 bytes/secMouse10 bytes/secKeyboardData rateDeviceChapter 54CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Device controllers I/O devices have components Mechanical component Electronic component Electronic component controls the device May be able to handle multiple devices May be more than one controller per mechanicalcomponent (example: hard drive) Controller's tasks Convert serial bit stream to block of bytes Perform error correction as necessary Make available to main memoryChapter 55CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Memory-Mapped I/OSeparateI/O & memoryspace0xFFF…0MemoryI/O portsMemory-mapped I/O Hybrid: bothmemory-mapped &separate spacesChapter 56CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)How is memory-mapped I/O done? Single-bus All memory accesses go overasharedbus I/O and RAM accessescompete for bandwidth Dual-bus RAM access over high-speedbus I/O access over lower-speedbus Less competition More hardware (moreexpensive…)CPU Memory I/OCPU Memory I/OThis port allows I/O devicesaccess into memory2Chapter 57CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Direct Memory Access (DMA) operationChapter 58CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Hardware’s view of interruptsBusChapter 59CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)I/O software: goals Device independence Programs can access any I/O device No need to specify device in advance Uniform naming Nameofafileordeviceisastringoraninteger Doesn’t depend on the machine (underlying hardware) Error handling Done as close to the hardware as possible Isolate higher-level software Synchronous vs. asynchronous transfers Blocked transfers vs. interrupt-driven Buffering Data coming off a device cannot be stored in final destination Sharable vs. dedicated devicesChapter 510CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Programmed I/O: printing a pagePrintedpageABCDEFGHKernelUserAPrintedpageABCDEFGHABCDEFGHABPrintedpageABCDEFGHABCDEFGHChapter 511CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Code for programmed I/Ocopy_from_user (buffer, p, count); // copy into kernel bufferfor (j = 0; j < count; j++) { // loop for each charwhile (*printer_status_reg != READY); // wait for printer to be ready*printer_data_reg = p[j]; // output a single character}return_to_user();Chapter 512CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Interrupt-driven I/Ocopy_from_user (buffer, p, count);j=0;enable_interrupts();while (*printer_status_reg != READY);*printer_data_reg = p[0];scheduler(); // and block userif (count == 0) {unblock_user();}else{*printer_data_reg = p[j];count--;j++;}acknowledge_interrupt();return_from_interrupt();CoderunbysystemcallCode run at interrupt time3Chapter 513CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)I/O using DMAcopy_from_user (buffer, p, count);set_up_DMA_controller();scheduler(); // and block useracknowledge_interrupt();unblock_user();return_from_interrupt();CoderunbysystemcallCode run at interrupt timeChapter 514CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Layers of I/O softwareUser-level I/O software & librariesDevice-independent OS softwareDevice driversInterrupt handlersHardwareOperatingsystem(kernel)UserChapter 515CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Interrupt handlers Interrupt handlers are best hidden Driver starts an I/O operation and blocks Interrupt notifies of completion Interrupt procedure does its task Then unblocks driver that started it Perform minimal actions at interrupt time Some of the functionality can be done by the driver after it isunblocked Interrupt handler must Save regs not already saved by interrupt hardware Set up context for interrupt service procedure DLXOS: intrhandler (in dlxos.s)Chapter 516CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)What happens on an interrupt Set up stack for interrupt service procedure Ack interrupt controller, reenable interrupts Copy registers from where saved Run service procedure (optional) Pick a new process to run next Set up MMU context for process to run next Load new process' registers Start running the new processChapter 517CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Device drivers Device drivers go betweendevice controllers and restof OS Drivers standardize interfaceto widely varied devices Device driverscommunicate withcontrollers over bus Controllers communicatewith devices themselvesUserspaceKernelspaceUserprogramKeyboarddriverDiskdriverRest of the OSKeyboardcontrollerDiskcontrollerChapter 518CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Device-independent I/O software Device-independent I/O software provides common“library” routines for I/O software Helps drivers maintain a standard appearance to therest of the OS Uniform interface for many device drivers for Buffering Error reporting Allocating and releasing dedicated devices Suspending and resuming processes Common resource pool Device-independent block size (keep track of blocks) Other device driver resources4Chapter 519CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Why a standard driver interface?Non-standard driver interfaces Standard driver interfacesChapter 520CS 1550, cs.pitt.edu (originaly modified by Ethan
View Full Document