Chapter 13: I/O Systems
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.2 Silberschatz, Galvin and Gagne 2005
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 13.3 Silberschatz, Galvin and Gagne 2005
I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (ex. PCI) Peripheral Component Interconnect: an industry-standard bus for attaching peripherals to computers Controller (host adapter) device registers I/O instructions are those that control devices 13.4 Silberschatz, Galvin and Gagne 2005
I/O Instructions How can the processor give commands and data to a controller to accomplish an I/O transfer? The short answer is that the controller has one or more registers for data and control signals. The processor communicates with the controller by reading and writing bit patterns in these registers. One way in which this communication can occur is through the use of special I/O instructions that specify the transfer of a byte or word to an I/O port address. Alternatively the device controller can support memory-mapped I/O. Device-control registers are mapped into the address space of the processor. The CPU executes I/O requests using the standard datatransfer instructions to read and write the device-control registers. 13.5 Silberschatz, Galvin and Gagne 2005
A Typical PC Bus Structure 13.6 Silberschatz, Galvin and Gagne 2005
32 and 64-bit PCI 13.7 Silberschatz, Galvin and Gagne 2005
Device I/O Port Locations on PCs (partial) 13.8 Silberschatz, Galvin and Gagne 2005
I/O Port An I/O port typically consists of four registers, called the (1) status, (2) control, (3) data-in, and (4) data-out 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 can be read by the host. These bits indicate states, such as whether the current command has completed, whether a byte is available to be read from the data-in register, and whether a device error has occurred. The control register can be written by the host to start a command or to change the mode of a device. 13.9 Silberschatz, Galvin and Gagne 2005
Busy Waiting Busy bit The host repeatedly reads the busy bit until that bit becomes clear. State of device: command-ready busy error Busy-wait cycle to wait for I/O from device 13.10 Silberschatz, Galvin and Gagne 2005
Interrupts CPU has an Interrupt-request line triggered by I/O device Interrupt handler receives interrupts Interrupt vector to dispatch interrupts to correct handlers Interrupts have priority Interrupt mechanism also used for exceptions Division by zero 13.11 Silberschatz, Galvin and Gagne 2005
Interrupt-Driven I/O Cycle 13.12 Silberschatz, Galvin and Gagne 2005
Intel Pentium Processor Event-Vector Table 13.13 Silberschatz, Galvin and Gagne 2005
Direct Memory Access Programmed I/O General purpose CPU deals with I/O Wasteful since the CPU is used also for I/O DMA used to avoid programmed I/O for large data movement Requires DMA controller: a special processor Bypasses CPU to transfer data directly between I/O device and memory 13.14 Silberschatz, Galvin and Gagne 2005
Six Step Process to Perform DMA Transfer 13.15 Silberschatz, Galvin and Gagne 2005
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.16 Silberschatz, Galvin and Gagne 2005
Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel 13.17 Silberschatz, Galvin and Gagne 2005
A Kernel I/O Structure 13.18 Silberschatz, Galvin and Gagne 2005
Devices Devices vary in many dimensions Character-stream or block Sequential or random-access Synchronous or asynchronous. Sharable or dedicated Speed of operation read-write, read only, or write only 13.19 Silberschatz, Galvin and Gagne 2005
Characteristics of I/O Devices 13.20 Silberschatz, Galvin and Gagne 2005
Block and Character Devices Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing 13.21 Silberschatz, Galvin and Gagne 2005
Network Devices Varying enough from block and character to have own interface Most OSs provide Network Interfaces 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) 13.22 Silberschatz, Galvin and Gagne 2005
Clocks and Timers Provide current time, elapsed time, timer to trigger operation Programmable interval timer used for timings, periodic interrupts Timers used by Scheduler Disk I/O subsystem Network subsystem User processes can also use them 13.23 Silberschatz, Galvin and Gagne 2005
Blocking and Nonblocking I/O Blocking - process suspended until I/O completed Easy to use and understand Process moved from run queue to wait queue 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 13.24 Silberschatz, Galvin and Gagne 2005
Two I/O Methods Synchronous Asynchronous 13.25 Silberschatz, Galvin and Gagne 2005
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.26 Silberschatz, Galvin and Gagne 2005
Kernel I/O Services Kernels provide many services related to I/O. Several services scheduling buffering caching spooling device reservation error handling are provided by the kernel's I/O subsystem and build on the hardware and device driver infrastructure. The I/O subsystem is also responsible for protecting itself from errant processes and malicious users. 13.27 Silberschatz, Galvin and Gagne 2005
Kernel I/O Subsystem I/O Scheduling Some I/O request ordering Some OSs try fairness 13.28 Silberschatz, Galvin and Gagne 2005
Scheduling can: I/O Scheduling improve overall system performance share device access fairly among processes reduce the average waiting time for I/O to complete. Suppose that a disk arm is near the beginning of a disk and that three applications issue blocking read calls to that disk. Application 1 requests a block near the end of the disk, application 2 requests one near the beginning, and application 3 requests one in the middle of the disk. The operating system can reduce the distance that the disk arm travels by serving the applications in the order 2, 3, 1. Rearranging the order of service in this way is the essence of I/O scheduling. We have seen disk I/O scheduling in the last class 13.29 Silberschatz, Galvin and Gagne 2005
Device-status Table When a kernel supports asynchronous I/O, it must be able to keep track of many I/O requests at the same time. For this purpose, the operating system might attach the wait queue to a device-status table. 13.30 Silberschatz, Galvin and Gagne 2005
Buffering Store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch 13.31 Silberschatz, Galvin and Gagne 2005
Sun Enterprise 6000 Device-Transfer Rates 13.32 Silberschatz, Galvin and Gagne 2005
Caching A cache is a region of fast memory that holds copies of data. Access to the cached copy is more efficient than access to the original. For instance, the instructions of the currently running process are stored on disk, cached in physical memory, and copied again in the CPU's secondary and primary caches. The difference between a buffer and a cache is that a buffer may hold the only existing copy of a data item, whereas a cache, by definition, just holds a copy on faster storage of an item that resides elsewhere. 13.33 Silberschatz, Galvin and Gagne 2005
Spooling A spool is a buffer that holds output for a device, such as a printer that cannot accept interleaved data streams. Although a printer can serve only one job at a time, several applications may wish to print their output concurrently, without having their output mixed together. The operating system solves this problem by intercepting all output to the printer. Each application's output is spooled to a separate disk file. When an application finishes printing, the spooling system queues the corresponding spool file for output to the printer. The spooling system copies the queued spool files to the printer one at a time. In some operating systems, spooling is managed by a system daemon process. 13.34 Silberschatz, Galvin and Gagne 2005
Device reservation Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock 13.35 Silberschatz, Galvin and Gagne 2005
Error Handling OS can recover from disk read, device unavailable or write failures Most return an error number or code when I/O request fails System error logs hold problem reports 13.36 Silberschatz, Galvin and Gagne 2005
I/O Protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions!!! Solution: All I/O instructions defined to be privileged Thus I/O must be performed via system calls This way the OS can check them 13.37 Silberschatz, Galvin and Gagne 2005
Use of a System Call to Perform I/O 13.38 Silberschatz, Galvin and Gagne 2005
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 13.39 Silberschatz, Galvin and Gagne 2005
UNIX I/O Kernel Structure 13.40 Silberschatz, Galvin and Gagne 2005
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.41 Silberschatz, Galvin and Gagne 2005
I/O Requests to Hardware Operations Consider reading a file from disk for a process Determine the device that holds file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process 13.42 Silberschatz, Galvin and Gagne 2005
Life Cycle of An I/O Request 13.43 Silberschatz, Galvin and Gagne 2005
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.44 Silberschatz, Galvin and Gagne 2005
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 Modules provide the functionality of STREAMS processing Each module contains a read queue and a write queue Message passing is used to communicate between queues 13.45 Silberschatz, Galvin and Gagne 2005
The STREAMS Structure 13.46 Silberschatz, Galvin and Gagne 2005
Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance 13.47 Silberschatz, Galvin and Gagne 2005
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 13.48 Silberschatz, Galvin and Gagne 2005
Intercomputer Communications 13.49 Silberschatz, Galvin and Gagne 2005
Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers and smart controllers Use DMA to offload a part of data copying from the CPU Balance CPU, memory, bus, and I/O performance for highest throughput An overload of one these will cause the idleness in others 13.50 Silberschatz, Galvin and Gagne 2005
Device-Functionality Progression Where should the I/O functionality be implemented? Development time 13.51 Silberschatz, Galvin and Gagne 2005
End of Chapter 13
GOOD LUCK 13.53 Silberschatz, Galvin and Gagne 2005