1 / 58

I/O Principles: Hardware, Software, and Device Interfaces

This chapter introduces the main function of the operating system, which is to provide a device independent interface between devices and the rest of the computer system. It covers the principles of I/O hardware and software, the layer structure of I/O software, and specific I/O devices as examples. The chapter also discusses the structure of I/O units, the role of mechanical and electronic components, memory in I/O controllers, I/O ports, memory-mapped I/O, and direct memory access (DMA). It concludes with an overview of interrupts, I/O software goals, and different methods of performing I/O.

beulahg
Télécharger la présentation

I/O Principles: Hardware, Software, and Device Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5Input/Output

  2. Introduction • I/O: main function of OS • Drive devices, catch interrupts, handle errors • Provide a device independent interface between devices and rest of the computer systems • To understand I/O • Principles of I/O hardware • Principles of I/O software • Layer structure of I/O software • Some specific I/O devices as examples

  3. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks

  4. Block and Character Devices • Block devices: store info in fixed-size blocks • Examples: disks • Each block has its own address • Each block can be read/written independently • Character devices: no block structure, deliver/accept a stream of characters • Examples: printers, network, mice • Not addressable, no seek operation • Devices not in the classification: clock

  5. Huge Range in Speeds • Many orders of magnitude in data rates • Keyboard: 10 bytes/sec • Mouse: 100 bytes/sec • Laser printer: 100kb/sec • IDE disk: 5mb/sec • PCI bus: 528mb/sec • Challenge: how to design a general structure to control various I/O devices?

  6. Structure of I/O Units • A mechanical component: the device itself • An electronic component: device controller, adaptor • Printed circuit card inserted into expansion slot • Connector: a cable to device • Interface between controller and device • ANSI, IEEE, ISO, e.g. IDE and SCSI interface • Very low level • Convert a serial bit stream into a block of bytes and perform necessary error correction

  7. Mechanical / Electronic Components Mechanical components Floppy disk driver Hard disk driver Monitor Keyboard Floppy disk controller Video controller Keyboard controller Hard disk controller CPU Memory Electronic components Bus

  8. Memory in I/O Controllers • Some registers for communication with CPU • CPU writes commands into registers • CPU reads states of devices from registers • Data buffer for transferring data • How CPU communicates with control registers/device data buffers?

  9. I/O Port • Each control register is assigned an I/O port number (8-/16-bit integer) • Instruction IN and OUT • IN REG, PORT • OUT PORT, REG • Used in early computers, mainframes • Separated address spaces Memory I/O ports

  10. Memory-Mapped I/O • Map all control registers into memory space • Usually at the top of the address space • Hybrid scheme Memory Memory I/O ports

  11. Pros & Cons of Memory-Mapped I/O • Advantages • Hide details of I/O for programming • No special protection mechanism is needed • Access control registers directly, save time • Disadvantages • Caching a control register is disastrous • Memory modules and I/O devices must examine all memory references

  12. Direct Memory Access (DMA) • Disk reads without DMA • Controller reads the block from drive • Interrupt, OS read controller’s buffer  memory • DMA approach Drive 1. CPU programs the DMA and controller Disk controller DMA controller Main memory Buffer Address CPU Count 4. Ack Control Interrupt when done 3. Data transferred 2. DMA requires transfer to memory Bus

  13. DMA Controller  Memory Transfer • Use bus to transfer • Cycle stealing • Send a word at at time • Don’t block CPU for bus control • Burst mode • Acquire bus, transfer in blocks • More efficient • Block CPU from using bus

  14. Interrupts Revisited 1. Device is finished Interrupt controller 3. CPU acks interrupt Disk Keyboard CPU Clock 2. Controller issues interrupt Printer Bus

  15. Interrupt Processing • I/O devices raise interrupt by asserting a signal on a bus line assigned • Multiple interrupts  the one with high priority goes first • Interrupt controller interrupts CPU • Put device # on address lines • Device #  check interrupt vector table for interrupt handler (a program) • Enable interrupts shortly after the handler starts

  16. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks

  17. Goals of The I/O Software • Device independence • Uniform naming • Error handling • Synchronous (blocking) vs. asynchronous (interrupt-driven) transfers • Synchronous transfers: easy to program • Asynchronous transfers: good for CPU • Buffering • Sharable vs. dedicated devices

  18. How to Perform I/O? • Programmed I/O • Have the CPU do all the work • Interrupt-driven I/O • I/O using DMA A

  19. Polling/Busy Waiting • Simple • Waste a lot of CPU time

  20. Interrupt-Driven I/O Print system call copy_from_user(buffer, p, count); enable_interrupts(); while (*printer_status_reg!=READY); *printer_data_register=p[0]; scheduler(); Interrupt service procedure if (count==0){ unblock_user(); } else { *printer_data_register=p[I]; count--; i++; } acknowledge_interrupt(); return_from_interrupt(); Interrupt occurs on every character!

  21. I/O Using DMA • Too many interrupts in interrupt-driven I/O • DMA reduces # of interrupts from 1/char to 1/buffer printed Print system call copy_from_user(buffer, p, count); set_up_DMA_controller(); scheduler(); Interrupt service procedure acknowledge_interrupt(); unblock_user(); return_from_interrupt();

  22. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks

  23. An Overview

  24. Interrupt Handlers • Hide IO interrupts deep in OS • Driver starts I/O and blocks • Interrupt wakes up driver • See details in text book • Process switching and interrupt • Interrupt processing takes considerable number of CPU instructions

  25. Device Drivers • Device-specific code for controlling I/O devices • Written by manufacture, delivered along with device • One driver for one (class) device(s) • Position: below the rest of OS • Interfaces for rest of OS • Block device and character device have different interfaces

  26. Logical Position of Device Drivers User program User space Rest of the OS Kernel space Printer driver Hardware Printer controller printer Devices

  27. How to Install a Driver? • UNIX systems • Often run by computer centers, devices rarely change • Drivers and OS are in a single binary program • Windows • Devices often change, users don’t know how to compile OS • Dynamically load drivers into OS during execution

  28. Functions of Device Drivers • Accept abstract read/write requests • Initialize device, if necessary • Manage power requirements and log events • Etc.

  29. Structure of Device Drivers • Check input parameters • If invalid, return error • Translate form abstract to concrete terms • For disk driver, convert a linear block number into head, track, sector, and cylinder numbers • Check if the device is currently in use • If so, queue the request • If not, prepare device for the request • Issue a sequence of command to execute the request • May block and wait for interrupt • Return data and status information

  30. Why dev-independent I/O software? Perform I/O functions common to all devices Provide a uniform interface to user-level software Functions in device-independent software Uniform interfacing for dev. drivers Buffering Error reporting Allocating and releasing dedicated devices Providing a device-independent block size Device-Independent I/O Software

  31. Uniform Interfacing for Device Drivers • Diverse device drivers  modify OS for new device, tedious work! • Mapping symbolic device names onto proper driver • Protection of devices from illegal access

  32. Buffering for Input • Unbuffered input • User process is started up for every character • Many short runs in a process  inefficient! • Buffering in user space • More efficient than unbuffered input • Can the buffer be paged out? • Yes  how to handle the next character? • No  the pool of available pages shrink unbuffered Buffering in user space

  33. Buffering in Kernel • Buffering in kernel • Buffer is full  copy the buffer to user space • More efficient • What happens for characters during page swapping? • Double buffering in kernel • Buffers are used in turn Buffering in kernel Double buffering

  34. Buffering for Output • Buffering in user space is not good • Block user process, or • Unblocked call, don’t know when the buffer can be reused • Buffering in kernel • User can reuse the buffer in user space immediately Buffering in user space Buffering in kernel

  35. If Data Buffered Too Many Times • Many sequential buffering slow down transmission User process User space 5 1 Kernel space 2 4 Network controller 3 Network

  36. Classes of I/O Errors • Programming errors: ask for mission impossible • E.g. writing a keyboard, reading a printer • Invalid parameters, like buffer address • Report an error code to caller • Actual I/O error • E.g. write a damaged disk block • Up to the driver and software, e.g., A dialog box • Serious error: display message, system terminates • E.g. root directory is destroyed

  37. Allocating/Releasing Dedicated Devices • Blocking calls • Block the process if the device is unavailable • Non-blocking calls • Operation “open” • If the device is unavailable, return “fail”

  38. User-Space I/O Software • Libraries of I/O software linked with user programs • Make system calls, e.g. write(fd, buffer, nbytes); • Format input/output, e.g. printf/scanf • Spooling • User-level, controlled by a daemon • Eliminated unnecessarily waiting/deadlock

  39. Summary I/O request I/O reply

  40. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks

  41. Kinds of Disks • Magnetic disks • Hard disks and floppy disks • Reads/writes are equally fast • Ideal secondary memory • Highly reliable storage • Optical disks • CD-ROM, CD-Recordable, DVD

  42. Structure of Magnetic Disks • Cylinders  tracks  sectors • IDE disks • The drive contains a microcontroller • Real controller issues higher-level commands • Overlapped seeks • Seeks on two or more drives simultaneously • Virtual geometry • x cylinders, y heads, z sectors/track • Logical block addressing • Continuous numbering sectors Sector Track

  43. RAID • Redundant array of independent disks • Use six specific disk organization to improve disk performance and reliability • A disk box connected to computer • RAID controller • Appear like a single large disk • Data distributed over drives • Allow parallel operations • Several different schemes: level 0 - 5

  44. Strip 0 Strip 1 Strip 2 Strip 3 Strip 4 Strip 5 Strip 6 Strip 7 RAID Level 0 • Virtual single disk is divided into n strips • Each strip has k sectors • Total disk space: n * k sectors • Striping: allocate consecutive strips over drives in round-robin fashion • Read 4 consecutive strips  parallel I/O Sector 0-(k-1) Sector k-(2k-1) Sector 2k-(3k-1) Sector 3k-(4k-1)

  45. Pros and Cons of RAID Level 0 • Good for large requests • Parallel I/O • The bigger the better • Straightforward implementation • Not good for one sector at a time • No parallelism  no performance gain • Poorer reliability than SLED • 1/n mean time to failure for n disks • No redundancy – not a true RAID

  46. RAID Level 1 • Duplicate all disks • Primary disks and backup disks • Write  every strip is written twice • Read  either copy can be used Primary disks backup disks Strip 0 Strip 1 Strip 2 Strip 3 Strip 0 Strip 1 Strip 2 Strip 3 Strip 4 Strip 5 Strip 6 Strip 7 Strip 4 Strip 5 Strip 6 Strip 7

  47. Pros and Cons of RAID Level 1 • Write performance is poorer than SLED • Read performance is up to twice as good as SLED • Excellent fault tolerance • A drive fails  use its copy • Recovery: install a new drive, copy the whole backup drive

  48. Bit 4 Bit 5 Bit 6 Bit 7 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 1 Bit 2 Bit 3 RAID Level 3 • Work on a word/byte basis • Split each byte into a pair of 4-bit nibbles • Add a Hamming code to each one to form a 7-bit word • 7 drives are synchronized in terms of arm position and rotational position • Write the 7-bit Hamming coded word over 7 drives, 1 bit/drive Word 1 Word 2

  49. Pros and Cons of RAID Level 2 • Advantages • Immense throughput • Quadruple I/O capability if 7 drives are used • 32 times speedup if 39 drives are used • One I/O request at a time • Highly fault tolerant • Using Hamming code to correct faults on the fly • Disadvantages • Require all drives rotationally synchronized • Use substantial number of drives • Do Hamming checksum every bit time

  50. Bit 4 Parity Bit 1 Bit 2 Bit 3 Bit 4 Parity Bit 1 Bit 2 Bit 3 RAID Level 3 • Simplified version of RAID level 2 • A single parity bit for each data word • Drives must be exactly synchronized • Fault correction • Parity bit + crashed drive id • High data rate • One I/O request at a time

More Related