I/O Systems: Source: Operating System Concepts by Silberschatz, Galvin and Gagne
I/O Systems: Source: Operating System Concepts by Silberschatz, Galvin and Gagne
13.1
Overview
Computer does I/O and processing IO can be a major job (browse web or edit a file) OS manages I/O devices and operations Two conflicting trends: A wide variety of I/O devices Standardization of software and hardware interfaces. I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance
13.2
I/O Hardware
A variety of I/O devices Common concepts Port - a connection point Bus (daisy chain) PCI bus Controller (Simple controller or a host adapter) I/O transfer mechanism Direct I/O instructions Memory-mapped I/O
13.3
13.4
Status register Read to indicate command completion, data availability, device error. Control register Write to start a command or to change a device mode. Data-in register Read to get input Data-out register Write to send the output
13.5
Polling
Protocol for interaction between the host and a controller. Simple handshaking notion using bits. Determines state of device busy command-ready error
Busy-waiting or polling loop Reading the status register over and over until the busy bit becomes clear.
13.6
Interrupts
CPU Interrupt request line triggered by I/O device Interrupt handler receives interrupts Two interrupt request lines: Nonmaskable for events such as unrecoverable memory errors Maskable to ignore or delay some interrupts Interrupt mechanism: Interrupt vector to dispatch interrupt to correct handler Based on priority Interrupt mechanism also used for Exceptions (dividing by zero, attempting to execute a privileged instruction from user mode) Virtual-memory paging (page fault) System calls ( executes a trap) Managing flow control (e.g., interrupting a disk read) Timers
13.7
13.8
13.9
Programmed I/O (PIO) Watch status bits and feed data into a controller register one byte at a time PIO is not useful for large data movement Direct-memory-access (DMA) controller A special purpose processor to bypass CPU to transfer data directly between I/O device and memory CPU writes the address of a DMA command-block into DMA controller which then operates the memory bus directly. Handshaking between the DMA and device controllers occurs using DMA-request and DMA-acknowledge wires. Cycle stealing - preventing CUP from accessing main memory.
13.10
DMA Transfer
13.11
classes.
Device-driver layer hides differences among I/O controllers
from kernel.
To interface the hardware to OS.
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.12
How the I/O-related portions of the kernel are structured in the software layers.
CSC 4103: Operating System 13.13 B.B. Karki, LSU
13.14
Block-device interface: transfer blocks of data Disk device Commands: read, write, seek Raw I/O or file-system access Memory-mapped file access possible. Character-stream interface: transfer byte by byte Keyboards, mice, serial ports Commands: get, put Libraries layered on top allow line-at-a-time access.
13.15
Network Devices
Network I/O interface: network socket interface Unix and Windows NT Separates network protocol from network operation Includes select functionality to manage a set of sockets Approaches vary widely (pipes, FIFOs, streams,
13.16
Three basic functions: Provide current time Provide elapsed time Set a timer to trigger an operation at a specified time. Hardware a programmable interval timer: Used for timings, periodic interrupts (e.g., CPU scheduler).
13.17
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
13.18
Kernels provide many services related to I/O Built on the hardware and device driver infrastructure. Scheduling Some I/O request ordering via per-device queue Some OSs try fairness 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.
13.19
13.20
13.21
to implement I/O.
13.22
13.23
representation Physically read data from disk into buffer Make data available to requesting process Return control to process.
STREAMS
STREAM a full-duplex
Performance
I/O a major factor in
system performance:
Demands CPU to
execute device driver, kernel I/O code, process scheduling Context switches due to interrupts Data copying Network traffic especially stressful
Intercomputer communications
CSC 4103: Operating System 13.26 B.B. Karki, LSU
Improving Performance
Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers,
polling
Use DMA Move processing primitives into hardware (device controllers) Balance CPU, memory, bus, and I/O performance for highest
throughput.
13.27
Device-Functionality Progression
13.28
Summary
Basic I/O hardware elements are buses, device controllers, and devices Two ways of data transfer between devices and memory Programmed I/O DMA controller System-call interface provides a wide range of functionality Kernels I/O subsystem provides services such as I/O scheduling,
user-level process.
I/O system calls consume CPU time a lot because of the many layers of