shandong university 1 chapter 13 i/o systems. shandong university 2 contents i/o hardware ...

Download SHANDONG UNIVERSITY 1 Chapter 13 I/O Systems. SHANDONG UNIVERSITY 2 Contents  I/O Hardware  Application I/O Interface  Kernel I/O Subsystem  Transforming

If you can't read please download the document

Upload: abigayle-arnold

Post on 18-Jan-2018

226 views

Category:

Documents


0 download

DESCRIPTION

SHANDONG UNIVERSITY 3 Objectives  Explore the structure of an operating system’s I/O subsystem  Discuss the principles of I/O hardware and its complexity  Provide details of the performance aspects of I/O hardware and software

TRANSCRIPT

SHANDONG UNIVERSITY 1 Chapter 13 I/O Systems SHANDONG UNIVERSITY 2 Contents I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance SHANDONG UNIVERSITY 3 Objectives Explore the structure of an operating systems I/O subsystem Discuss the principles of I/O hardware and its complexity Provide details of the performance aspects of I/O hardware and software SHANDONG UNIVERSITY 4 I/O Hardware Incredible variety of I/O devices Function speed Device driver Present a uniform device-access interface to the I/O subsystem, much as systems calls SHANDONG UNIVERSITY 5 I/O Hardware Common concepts Port Bus (daisy chain or shared direct access) Controller (host adapter) I/O instructions control devices Devices have addresses, used by Direct I/O instructions Memory-mapped I/O SHANDONG UNIVERSITY 6 A Typical PC Bus Structure Peripheral component interconnection SHANDONG UNIVERSITY 7 Device I/O Port Locations on PCs (partial) SHANDONG UNIVERSITY 8 I/O port PCs use I/O instructions to control some devices. An I/O port typically consists of four registers The data-in register is read by the host to get input The data-out register is written by the host to send output The status register contains bits that be read by the host. The control register can be written by the host to start a command or to change the mode of a device. SHANDONG UNIVERSITY 9 Polling Determines state of device command-ready busy Error Busy-wait cycle to wait for I/O from device SHANDONG UNIVERSITY 10 Polling 1. The host repeatedly reads the busy bit until that bit becomes clear. 2. The host sets the write bit in the command register and writes a byte into the data-out register. 3. The host sets the command-ready bit. 4. When the controller notices that the command- ready bit is set, it sets the busy bit. 5. The controller reads the command register and sees the write command. It reads the data-out register to get the byte, and does the I/O to the device. 6. The controller clears the command-ready bit, clears the error bit in the status register to indicate that the device I/O succeeded, and clears the busy bit to indicate that it is finished SHANDONG UNIVERSITY 11 Example CPU CPU SHANDONG UNIVERSITY 12 Interrupts CPU Interrupt-request line triggered by I/O device Interrupt handler receives interrupts We need more sophisticated interrupt-handling features we need ability to defer interrupt handling during critical processing we need an efficient way to dispatch to the proper interrupt handler for a device without first polling all the devices to see which one raised the interrupt. we need multilevel interrupts, so that the OS can distinguish between high-and low- priority interrupts and can respond with the appropriate degree of urgency. Two interrupt request lines: Nonmaskable interrupt Maskable to ignore or delay some interrupts Interrupt vector to dispatch interrupt to correct handler Based on priority Some nonmaskable Interrupt mechanism also used for exceptions SHANDONG UNIVERSITY 13 Interrupts N4 IP 8 =0000 N4 SHANDONG UNIVERSITY 14 Interrupts "INT 13H" "0070H CS 0FC9H IP " CPU 13H 4 13H4=004CH 4 "INT 13H" SHANDONG UNIVERSITY 15 Interrupt-Driven I/O Cycle SHANDONG UNIVERSITY 16 Intel Pentium Processor Event-Vector Table SHANDONG UNIVERSITY 17 Example CPU CPU CPU CPU SHANDONG UNIVERSITY 18 Direct Memory Access Used to avoid programmed I/O for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory SHANDONG UNIVERSITY 19 Six Step Process to Perform DMA Transfer SHANDONG UNIVERSITY 20 Example CPU DMA CPU DMA DMA DMA CPU CPU DMA CPU DMA CPU DMA SHANDONG UNIVERSITY Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Devices vary in many dimensions Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only Device-driver layer hides differences among I/O controllers from kernel SHANDONG UNIVERSITY 22 A Kernel I/O Structure SHANDONG UNIVERSITY 23 Characteristics of I/O Devices SHANDONG UNIVERSITY 24 Block and Character Devices Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing SHANDONG UNIVERSITY 25 Network Devices Varying enough from block and character to have own interface Unix and Windows NT/9x/2000 include socket interface Separates network protocol from network operation Includes select functionality Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) SHANDONG UNIVERSITY 26 Clocks and Timers Provide current time, elapsed time, timer Programmable interval timer used for timings, periodic interrupts ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers SHANDONG UNIVERSITY 27 Blocking and Nonblocking I/O Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed SHANDONG UNIVERSITY 28 Two I/O Methods SHANDONG UNIVERSITY Kernel I/O Subsystem Kernels provide many services related to I/O: scheduling, buffering, caching, spooling, device reservation, and error handling. I/O Scheduling To schedule a set of I/O requests means to determine a good order in which to execute. Is it important? Implementation Some I/O request ordering via per-device queue Some OSs try fairness SHANDONG UNIVERSITY 30 Device-status Table SHANDONG UNIVERSITY 31 Buffering( ) A buffer is a memory area that stores data while they are transferred between two devices or between a device and an application. Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain copy semantics SHANDONG UNIVERSITY 32 Sun Enterprise 6000 Device-Transfer Rates SHANDONG UNIVERSITY 33 Caching ( ) Caching - fast memory holding copy of data Reasons to use it Speed Data size Differences between caching and buffering A buffer may hold the only existing copy of a data item. A cache is just holds a copy on faster storage of an item. SHANDONG UNIVERSITY 34 SHANDONG UNIVERSITY 35 SHANDONG UNIVERSITY 36 Spooling Spooling - hold output for a device Simultaneous peripheral Operations On-Line If device can serve only one request at a time Its speed is very slow i.e., Printing SHANDONG UNIVERSITY 37 Device reservation Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock SHANDONG UNIVERSITY 38 Error Handling OS can recover from disk read, device unavailable, transient write failures Most return an error number or code when I/O request fails System error logs hold problem reports SHANDONG UNIVERSITY 39 I/O Protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions All I/O instructions defined to be privileged I/O must be performed via system calls Memory-mapped and I/O port memory locations must be protected too SHANDONG UNIVERSITY 40 Use of a System Call to Perform I/O SHANDONG UNIVERSITY 41 Kernel Data Structures Kernel keeps state info for I/O components, including open file tables, network connections, character device state Many, many complex data structures to track buffers, memory allocation, dirty blocks Some use object-oriented methods and message passing to implement I/O SHANDONG UNIVERSITY 42 UNIX I/O Kernel Structure SHANDONG UNIVERSITY 43 Kernel I/O subsystem Summary The I/O subsystem supervises the following procedures: Management of the name space for files and devices Access control to files and devices Operation control File-system space allocation Devices allocation I/O scheduling Device-status monitoring, error handling, and failure recovery Device-driver configuration and initialization SHANDONG UNIVERSITY I/O Requests to Hardware Operations Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process SHANDONG UNIVERSITY 45 Life Cycle of An I/O Request SHANDONG UNIVERSITY 46 STREAMS STREAM a full-duplex communication channel between a user-level process and a device in Unix System V and beyond A STREAM consists of: - STREAM head interfaces with the user process - driver end interfaces with the device - zero or more STREAM modules between them. Each module contains a read queue and a write queue Message passing is used to communicate between queues SHANDONG UNIVERSITY 47 The STREAMS Structure SHANDONG UNIVERSITY Performance I/O a major factor in system performance: Demands CPU to execute device driver, kernel I/O code Context switches due to interrupts Data copying Network traffic especially stressful SHANDONG UNIVERSITY 49 Intercomputer Communications SHANDONG UNIVERSITY 50 Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Balance CPU, memory, bus, and I/O performance for highest throughput SHANDONG UNIVERSITY 51 Device-Functionality Progression SHANDONG UNIVERSITY 52 Assignment 33 End of Chapter 13 Any Question?