Input/Output � Principles of I/O hardware � Principles of I/O software Chapter 5: I/O Systems � I/O software layers � Disks � Clocks � Character-oriented terminals � Graphical user interfaces � Network terminals � Power management Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 2 How fast is I/O hardware? Device controllers Device Data rate � I/O devices have components Keyboard 10 bytes/sec � Mechanical component Mouse 100 bytes/sec � Electronic component 56K modem 7 KB/sec � Electronic component controls the device Printer / scanner 200 KB/sec � May be able to handle multiple devices USB 1.5 MB/sec � May be more than one controller per mechanical Digital camcorder 4 MB/sec component (example: hard drive) Fast Ethernet 12.5 MB/sec � Controller's tasks Hard drive 20 MB/sec � Convert serial bit stream to block of bytes FireWire (IEEE 1394) 50 MB/sec XGA monitor 60 MB/sec � Perform error correction as necessary PCI bus 500 MB/sec � Make available to main memory CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 3 4 Memory-Mapped I/O How is memory-mapped I/O done? � Single-bus Memory � All memory accesses go over CPU Memory I/O 0xFFF… a shared bus � I/O and RAM accesses I/O ports compete for bandwidth � Dual-bus � RAM access over high-speed bus 0 � I/O access over lower-speed CPU Memory I/O bus � Less competition Separate Memory-mapped I/O Hybrid: both � More hardware (more I/O & memory memory-mapped & expensive…) This port allows I/O devices space separate spaces access into memory CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 5 6 1
Direct Memory Access (DMA) operation Hardware’s view of interrupts Bus Chapter 5 Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 7 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 8 Programmed I/O: printing a page I/O software: goals � Device independence � Programs can access any I/O device � No need to specify device in advance � Uniform naming � Name of a file or device is a string or an integer User Printed Printed Printed � Doesn’t depend on the machine (underlying hardware) page page page � Error handling � Done as close to the hardware as possible ABCD ABCD ABCD � Isolate higher-level software EFG H EFG H EFG H A AB � Synchronous vs. asynchronous transfers Kernel ABCD ABCD � Blocked transfers vs. interrupt-driven EFG H EFG H � Buffering � Data coming off a device cannot be stored in final destination � Sharable vs. dedicated devices CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 9 10 Interrupt-driven I/O Code for programmed I/O copy_from_user (buffer, p, count); copy_from_user (buffer, p, count); // copy into kernel buffer j = 0; for (j = 0; j < count; j++) { // loop for each char enable_interrupts(); Code run by system call while (*printer_status_reg != READY) while (*printer_status_reg != READY) ; // wait for printer to be ready ; *printer_data_reg = p[0]; *printer_data_reg = p[j]; // output a single character scheduler(); // and block user } return_to_user(); if (count == 0) { unblock_user(); } else { *printer_data_reg = p[j]; count--; Code run at interrupt time j++; } acknowledge_interrupt(); return_from_interrupt(); CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 11 12 2
I/O using DMA Layers of I/O software copy_from_user (buffer, p, count); Code run by system call set_up_DMA_controller(); scheduler(); // and block user User User-level I/O software & libraries acknowledge_interrupt(); Device-independent OS software Code run at interrupt time unblock_user(); Operating return_from_interrupt(); Device drivers system (kernel) Interrupt handlers Hardware Chapter 5 Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 13 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 14 Interrupt handlers What happens on an interrupt � Interrupt handlers are best hidden � Set up stack for interrupt service procedure � Driver starts an I/O operation and blocks � Ack interrupt controller, reenable interrupts � Interrupt notifies of completion � Copy registers from where saved � Interrupt procedure does its task � Run service procedure � Then unblocks driver that started it � (optional) Pick a new process to run next � Perform minimal actions at interrupt time � Set up MMU context for process to run next � Some of the functionality can be done by the driver after it is unblocked � Load new process' registers � Interrupt handler must � Start running the new process � Save regs not already saved by interrupt hardware � Set up context for interrupt service procedure � DLXOS: intrhandler (in dlxos.s) CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 15 16 Device drivers Device-independent I/O software User � Device drivers go between User � Device-independent I/O software provides common space program device controllers and rest “library” routines for I/O software of OS � Helps drivers maintain a standard appearance to the Kernel � Drivers standardize interface space rest of the OS to widely varied devices � Uniform interface for many device drivers for Rest of the OS � Device drivers � Buffering communicate with � Error reporting Keyboard Disk controllers over bus � Allocating and releasing dedicated devices driver driver � Controllers communicate � Suspending and resuming processes with devices themselves � Common resource pool Keyboard Disk controller controller � Device-independent block size (keep track of blocks) � Other device driver resources CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 17 18 3
Why a standard driver interface? Buffering device input User User User User space space space space Kernel Kernel Kernel Kernel 2 2 space space space space 1 1 3 Non-standard driver interfaces Standard driver interfaces Unbuffered Buffering in Buffer in kernel Double buffer input user space Copy to user space in kernel Chapter 5 Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 19 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) 20 Anatomy of an I/O request Disk drive structure head � Data stored on surfaces sector � Up to two surfaces per platter � One or more platters per disk � Data in concentric tracks platter � Tracks broken into sectors � 256B-1KB per sector track � Cylinder: corresponding cylinder tracks on all surfaces � Data read and written by heads surfaces � Actuator moves heads � Heads move in unison spindle actuator CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 21 22 Disk drive specifics Disk “zones” IBM 360KB floppy WD 18GB HD � Outside tracks are longer than inside tracks Cylinders 40 10601 Tracks per cylinder 2 12 � Two options Sectors per track 9 281 (average) � Bits are “bigger” Sectors per disk 720 35742000 � More bits (transfer faster) Bytes per sector 512 512 � Modern hard drives use Capacity 360 KB 18.3 GB second option Seek time (minimum) 6 ms 0.8 ms � More data on outer tracks Seek time (average) 77 ms 6.9 ms � Disk divided into “zones” Rotation time 200 ms 8.33 ms � Constant sectors per track in Spinup time 250 ms 20 sec each zone � 8–20 (or more) zones on a Sector transfer time 22 ms 17 µ sec disk CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5 23 24 4
Recommend
More recommend