Transcription and Subtitles
Input/Output Systems
1. Purpose and Diversity of I/O Systems
An input/output (I/O) system enables a computer to exchange data with devices and external systems. Input devices provide data to the computer, while output devices receive data from it. Many devices perform both functions.
Examples include:
Input devices: keyboards, mice, webcams, foot pedals, microphones, and sensors
Output devices: monitors, printers, and speakers
Input/output devices: hard disks, solid-state drives, USB drives, and network interfaces
I/O devices differ substantially in their:
Connection methods and interfaces
Data-transfer speeds
Amount of data transferred at a time
Direction of data transfer
Access patterns
Control requirements
Ability to support multiple processes simultaneously
For example, an SSD can transfer data very quickly, whereas a printer or tape drive is comparatively slow. A keyboard normally provides one character at a time, while a disk transfers blocks of data. A monitor primarily receives output, while a hard disk can both read and write data.
The operating system must provide a consistent way for applications and users to work with these different devices despite their hardware differences.
The main challenge of I/O management is coordinating devices with different speeds, interfaces, data formats, and operating requirements through a common operating-system framework.
2. I/O Hardware Architecture
Buses, Ports, and Interfaces
Devices communicate with the computer through ports, interfaces, and buses.
A port is a physical or logical connection through which a device communicates.
An interface defines how the device communicates with the computer.
A bus is a communication pathway that carries data, addresses, and control signals.
A modern computer may contain devices connected through:
USB
HDMI
VGA
Display interfaces
Storage interfaces such as SATA
PCI or PCI Express expansion buses
Network interfaces
Many physically different devices can share the same type of connection. For example, USB may connect:
Keyboards
Mice
Webcams
Mobile phones
External hard disks
USB flash drives
Foot pedals
Monitors functioning as USB hubs
Although these devices use the same general connection, their internal operation is different.
Expansion and System Buses
A device may connect to an expansion bus, which then connects to a larger system bus. For example:
A USB device connects to a USB port.
The port is managed by a USB controller.
The controller communicates through an expansion or PCI bus.
The PCI bus connects to the processor and main memory.
This arrangement allows many different devices to communicate with the CPU and memory through shared pathways.
Device Controllers
Each device generally has a device controller, which is hardware responsible for managing the device.
A controller may contain:
Control electronics
Registers
Status information
Temporary storage
A buffer or cache
Logic specific to the device
The controller for a USB mouse is different from the controller for a USB flash drive, even though both use USB. The controller hides many hardware-specific details and provides a manageable interface to the operating system.
3. Device Drivers
A device driver is operating-system software that communicates with a particular type of hardware.
A device driver translates general operating-system requests into commands that a specific device controller can understand.
For example, the operating system may issue a general request such as “read data.” The device driver converts that request into the specific sequence of commands required by:
A hard disk
A USB flash drive
A keyboard
A printer
A graphics adapter
A network interface
Applications and the operating system should not need to understand the detailed hardware operation of every device. Instead, the driver provides a standard interface while handling device-specific details.
Relationship Between Drivers and Controllers
A device driver and device controller work together:
The driver is software running within the operating system.
The controller is hardware connected to the device.
The driver sends instructions to the controller.
The controller operates the physical device and reports results.
The driver passes the results back to the operating system.
Both components are necessary. A mouse may be physically connected and functioning, but without a suitable driver the operating system may not be able to communicate with it. Conversely, installing a driver is not useful if the corresponding device is not connected.
4. I/O Registers
I/O devices commonly use registers to exchange information with the CPU.
Data Registers
A data register temporarily stores data being transferred:
During input, data is placed in a register so that the CPU can read it.
During output, the CPU places data in a register so that the controller can send it to the device.
Status Registers
A status register records the current state of the device. It may indicate whether the device is:
Ready
Busy
Available
Finished
Experiencing an error
Waiting for data
Holding data that has not yet been read
Status information is important when several processes may attempt to use the same device. For example, two applications should not write to a printer at the same time, because their output could become mixed together.
Control Registers
A control register receives commands that determine how the device should operate. These commands may:
Start an operation
Stop an operation
Select a mode
Request a read
Request a write
Acknowledge an interrupt
Reset the controller
Registers allow the CPU and device controller to communicate using a structured set of values rather than requiring the CPU to manage every electrical detail of the device.
5. Memory-Mapped I/O and Port-Mapped I/O
The operating system and hardware must decide how devices are represented in the computer’s address space.
Memory-Mapped I/O
With memory-mapped I/O, device registers are assigned addresses within the same address space used for main memory.
The CPU uses ordinary memory instructions to access the device. Although the address appears to refer to memory, the hardware recognizes that it actually refers to a device register.
For example, writing a value to a particular address might cause a graphics adapter to change the color of a pixel. The operation appears to be a memory write, but the graphics hardware interprets the value as a display command.
Advantages include:
Use of ordinary load and store instructions
A uniform addressing model
Easier integration with the CPU’s existing memory-access mechanisms
Port-Mapped or Isolated I/O
With port-mapped I/O, devices have a separate address space from main memory. The CPU uses special I/O instructions to communicate with them.
These instructions explicitly identify the operation as an I/O operation rather than a normal memory operation.
Well-Known Device Addresses
Some systems assign well-known addresses to particular hardware functions. These may include:
Interrupt controllers
Graphics hardware
Storage controllers
Other system devices
The operating system uses these known locations to communicate with hardware. As hardware technology changes, addresses formerly associated with obsolete devices may be reused or reassigned.
6. Polling
Polling is a method in which the CPU repeatedly checks devices to determine whether they need attention.
A polling sequence works as follows:
The CPU checks the first device.
It asks whether the device has data or requires service.
If not, it checks the next device.
The CPU continues through the devices in sequence.
When a device needs attention, the CPU services it.
Polling is similar to asking every participant in turn whether they have something to report.
Advantages of Polling
Simple to implement
Predictable ordering
Suitable when there are only a few devices
Acceptable when devices respond quickly
Useful when the operating system knows exactly which devices exist and can manage their service times
Disadvantages of Polling
The CPU spends time checking devices that may have nothing to report.
A slow device can delay the checking of all later devices.
Important data may be missed if a device cannot retain it for long.
Polling becomes inefficient as the number of devices increases.
The CPU may repeatedly perform unnecessary checks.
For example, if the CPU is delayed while checking one slow device, data arriving from a keyboard or network interface might have to wait in a buffer or could potentially be lost.
7. Interrupt-Driven I/O
Most modern systems use interrupts to avoid constant polling.
An interrupt allows a device to notify the CPU when it requires attention. The typical process is:
The CPU executes a process.
A device completes an operation or receives data.
The device raises an interrupt request.
The CPU temporarily suspends its current work.
The CPU runs the appropriate interrupt handler.
The interrupt handler communicates with the device controller.
The data is copied into a buffer or another suitable location.
The CPU returns to the interrupted process.
For example, when a key is pressed:
The keyboard controller generates an interrupt.
The CPU invokes the keyboard interrupt handler.
The handler obtains the character from the controller.
The character is placed into a buffer.
The interrupted process resumes.
The interrupt handler normally performs only the urgent, essential work. It should not attempt to interpret or process the character fully. Instead, it stores the data so that the appropriate process can use it later.
Interrupt handlers should be small, efficient, and fast so that the CPU spends as little time as possible handling the interrupt.
Interrupt Lines
A computer bus may contain:
Data lines, which carry data
Address lines, which identify locations or devices
Control lines, which indicate operations such as reading or writing
Interrupt lines, which allow devices to request CPU attention
When an interrupt line becomes active, the CPU identifies the source and invokes the corresponding handler.
Interrupt Priorities
Several devices may request service at nearly the same time. Systems therefore assign priorities to interrupts.
Some interrupts are treated as more important than others. For example:
Serious hardware faults may receive very high priority.
Memory-management exceptions may require immediate handling.
Ordinary device activity may be assigned a lower priority.
A processor may support many interrupt types, including:
Divide errors
Debug events
Breakpoints
Page faults
Floating-point exceptions
System calls
Hardware-device requests
USB events
8. Maskable and Non-Maskable Interrupts
Maskable Interrupts
A maskable interrupt can be temporarily ignored or disabled by the CPU.
Maskable interrupts are appropriate for events that can safely wait for a short time. The operating system may mask them while executing a critical section or while handling a higher-priority event.
Non-Maskable Interrupts
A non-maskable interrupt cannot be ignored in the normal way. It is reserved for events that require immediate attention, such as serious hardware failures or conditions that could cause data loss.
Nested Interrupts
A question arises when an interrupt handler is itself running: can another interrupt interrupt the handler?
The answer depends on the interrupt configuration:
A lower-priority interrupt may be delayed.
A maskable interrupt may be temporarily disabled.
A high-priority or non-maskable interrupt may be allowed to interrupt another handler.
This creates a hierarchy in which urgent events can be serviced before less urgent events.
9. Direct Memory Access
Limitations of CPU-Controlled Transfers
Without special hardware, the CPU may have to manage every unit of data transferred between a device and memory.
For a disk transfer, the CPU might repeatedly:
Request one word of data.
Receive the word.
Store it in memory.
Request the next word.
Repeat the process until the transfer is complete.
This is inefficient because the CPU remains occupied during the entire transfer and cannot perform other useful work effectively.
DMA Operation
Direct memory access (DMA) allows a device controller to transfer a block of data directly to or from main memory without requiring the CPU to manage every individual word.
A typical DMA sequence is:
The CPU specifies the source or destination.
The CPU specifies the amount of data to transfer.
The CPU starts the DMA operation.
The DMA controller transfers the data directly between the device and memory.
The CPU continues executing other work.
The DMA controller raises an interrupt when the transfer finishes or encounters an error.
For example, the CPU can request that a disk transfer a block of several kilobytes into a specified memory location. It does not need to issue a separate command for every word.
Benefits and Cost of DMA
Benefits include:
Reduced CPU workload
Faster block transfers
Better overlap of computation and I/O
More efficient use of system resources
DMA also has a cost:
It requires additional hardware.
The DMA controller consumes system resources.
It may compete with the CPU for access to the memory bus.
The operating system must coordinate the transfer carefully.
DMA is particularly useful for high-volume devices such as:
Hard disks
SSDs
Network interfaces
Graphics devices
Audio and video hardware
10. Types and Characteristics of I/O Devices
I/O devices can be classified according to how they transfer and access data.
Character Devices
A character device transfers data one character or byte at a time.
Examples include:
Keyboards
Serial communication devices
Some terminals
Character devices commonly behave as streams. The data arrives in sequence, and the operating system processes or buffers it as it becomes available.
Block Devices
A block device transfers data in blocks rather than individual characters.
Examples include:
Hard disks
SSDs
USB storage devices
A block may contain a fixed amount of data, such as a few kilobytes. Block transfers are more efficient for storage because large amounts of data can be moved with fewer control operations.
Sequential-Access Devices
A sequential-access device must generally process data in order.
Examples include:
Tape drives
Keyboards
Serial streams
To reach later data, the device may need to pass through earlier data first.
Random-Access Devices
A random-access device can access a selected location without reading all preceding data.
Examples include:
Hard disks
SSDs
Main memory
Graphics display memory
A random-access display device can change one pixel without redrawing the entire screen.
Synchronous Devices
A synchronous device performs operations according to an expected timing relationship. The requesting process may wait for the operation to complete or receive a result through a coordinated sequence.
Asynchronous Devices
An asynchronous device operates independently after receiving a request. The requesting process can continue doing other work and be notified later when the operation completes.
Sharable Devices
A sharable device can be used by multiple processes, either simultaneously or through controlled interleaving.
A hard disk is generally sharable because requests can be scheduled and serviced in turn.
Dedicated Devices
A dedicated device must be assigned to one process at a time.
A printer is commonly treated as dedicated during a particular print operation. Allowing several processes to write directly to it at once could interleave their output.
Transfer Direction
Devices may be:
Read-only from the computer’s perspective: data can be received but not sent
Write-only from the computer’s perspective: data can be sent but not received
Read/write: data can move in both directions
A keyboard is primarily an input device, a monitor is primarily an output device, and a disk is a read/write device.
11. I/O Subsystem Structure
The operating system normally contains an I/O subsystem within the kernel. This subsystem coordinates the various device drivers and controllers.
A simplified structure is:
User or application layer
Requests operations such as opening, reading, writing, or closing a file.
I/O subsystem
Provides general I/O services.
Checks permissions and device status.
Manages buffering, caching, scheduling, and errors.
Device driver
Translates general requests into device-specific commands.
Interrupt handler
Responds when the device needs CPU attention.
Device controller
Controls the hardware.
Physical device
Performs the actual input or output.
The layered structure allows applications to use a common interface even when their data is stored on very different devices.
Device Records and Status Tables
The operating system maintains information about devices, including:
Which devices are connected
Which drivers are associated with them
Whether each device is busy or available
Which process is using a device
Pending requests
Transfer locations
Transfer sizes
Error conditions
Device capabilities and speeds
These records allow the kernel to coordinate access and prevent conflicting operations.
Operating systems may represent device information using structured records or object-oriented methods. Each record can describe a device, its controller, its driver, and its current requests.
12. Blocking and Non-Blocking I/O
Blocking I/O
With blocking I/O, a process waits until the requested I/O operation has completed.
The sequence is:
The process requests I/O.
The process stops running.
The device performs the operation.
The operation completes.
The process resumes.
Advantages:
Simple programming model
Easy to implement
Straightforward control flow
Disadvantages:
The process cannot perform other useful work while waiting.
Slow devices can significantly reduce performance.
CPU and system resources may be underused.
Non-Blocking I/O
With non-blocking I/O, a process does not wait for the entire operation to finish. It performs some work, checks the operation, and continues.
The system may report:
How much data has been transferred
Whether the operation is complete
Whether more data remains
Whether an error occurred
Advantages:
The process can continue performing other work.
Resources are used more efficiently.
It is suitable for devices that transfer data gradually.
The programming model is more complicated because the process must track incomplete operations and determine when to check again.
Synchronous I/O
In synchronous I/O, the request and its completion are coordinated as part of a defined operation. The process generally receives a result associated with the request, although the exact amount of waiting depends on the implementation.
Asynchronous I/O
With asynchronous I/O, the process submits a request and continues immediately. The device and operating system perform the operation in the background. The process is notified later when:
The transfer completes
Data becomes available
An error occurs
The operation is cancelled
Asynchronous I/O is more difficult to implement because the process must manage outstanding requests and completion notifications. However, it provides better performance because computation and I/O can overlap.
13. Buffering
A buffer is a temporary area of memory used to hold data while it moves between components with different speeds or transfer sizes.
Buffering allows a fast component and a slow component to operate without requiring both to proceed at exactly the same speed.
Why Buffering Is Necessary
Different devices transfer data at different rates:
Main memory and the CPU are very fast.
Storage devices are slower.
Keyboards generate small amounts of data irregularly.
Printers accept data much more slowly than the CPU can produce it.
Without buffering, the CPU might have to stop and wait for every slow operation.
Example: Disk Buffering
A disk controller may receive a complete block and store it in its buffer. Once the block is ready, it can be transferred to memory quickly over the system bus.
This is more efficient than transferring tiny pieces while the disk is still physically retrieving the data.
Example: Keyboard Buffering
A keyboard buffer stores characters as they are typed. The application does not have to process every character at the exact moment it is entered. It can retrieve the characters when it is ready.
Buffering and Data-Size Differences
Buffering also helps when the producer and consumer use different data sizes. A device may produce one character at a time, while an application may read a line or a larger group of characters. The buffer temporarily collects the smaller units until the larger operation can be completed.
Multiple Copies of Data
Data may exist simultaneously in several locations:
The device’s internal storage
The device controller’s buffer
An operating-system buffer
A cache
A user-space application buffer
This creates a consistency problem. If one copy changes, the operating system must know:
Which copy is current
Which copies need updating
Whether modified data must be written back to the device
This issue is related to copy semantics, which concerns how multiple copies of the same data are managed and synchronized.
14. Caching
A cache stores recently used data in faster memory so that future requests can be served more quickly.
When data is retrieved from a slow device, the operating system may retain it in a cache. If the same or nearby data is requested again, the system can use the cached copy rather than accessing the device again.
Caching improves performance because:
Memory is faster than most I/O devices.
Repeated requests can be served without another device operation.
Nearby data may be available before it is explicitly requested.
Network and storage delays can be avoided.
Caching must be managed carefully because several copies of data may exist at once. If cached data has been modified, the system must eventually synchronize it with the underlying device.
Buffering Versus Caching
Buffering primarily handles differences in speed, timing, and transfer size during an active transfer.
Caching primarily retains data for possible reuse in future requests.
A device can use both. Data may first be placed in a device buffer, then copied into memory, and later retained in a cache.
15. Spooling
Spooling allows a process to write data to a file or queue instead of waiting for a slow device to handle the data immediately.
The most common example is printing:
An application creates a print job.
The job is stored in a file or spool queue.
The application continues running.
The printer retrieves jobs from the queue.
The printer processes each job in an appropriate order.
Spooling is useful because printers are much slower than CPUs and applications. The application does not need to remain blocked while the printer physically produces the output.
A spool file contains the formatted information required by the printer, including text, layout, and other output instructions.
Benefits include:
Applications finish more quickly.
Multiple print requests can be queued.
The printer can process jobs sequentially.
Direct simultaneous access to the printer is avoided.
16. Scheduling I/O Requests
When several processes request access to a device, the operating system may need to schedule those requests.
Scheduling can be used to:
Determine which request is handled first
Prevent one process from monopolizing a device
Reduce movement or delay in storage devices
Improve overall throughput
Ensure fairness among processes
Prevent conflicting operations
For example, if a device has pending requests for both a large transfer and a small transfer, it may be more efficient to complete the small transfer first. The best decision depends on the device and the scheduling goals.
Different devices may require different algorithms because their characteristics differ. A disk scheduler may optimize physical access locations, while a printer scheduler may focus on queue order and fairness.
17. Quality of Service
Quality of service (QoS) refers to guarantees about how system resources are allocated among processes.
For I/O, QoS may ensure that:
Every process receives a fair opportunity to use a device.
A process cannot hold a device indefinitely.
Certain operations receive priority.
Response-time or throughput requirements are met.
Resource access is predictable.
QoS is especially important when many processes compete for a shared resource. Without appropriate scheduling and QoS controls, one process could prevent others from obtaining the data or device access needed to continue.
18. Device Reservation and Deadlock
Some devices may be reserved for one process at a time. Reservation can prevent interference, but it can also contribute to deadlock.
Deadlock occurs when processes wait indefinitely for resources held by one another.
A typical pattern is:
Process A holds device or resource 1 and waits for resource 2.
Process B holds resource 2 and waits for resource 1.
Neither process can continue.
Neither process releases its resource.
The system remains permanently stuck.
This resembles several vehicles at a roundabout where each vehicle gives priority to another vehicle. Every vehicle waits, so none can move.
I/O deadlock may occur when:
One process holds a device while waiting for data from another process.
The second process needs the first process to release the device.
Both processes are waiting for conditions controlled by the other.
To reduce the risk of deadlock, operating systems must carefully manage:
Device reservations
Resource acquisition order
Process waiting
Timeouts
Resource release
Scheduling policies
19. Error Handling
I/O devices can fail in many ways. The operating system must detect and respond to errors such as:
Read failures
Write failures
Lost connections
Invalid requests
Device timeouts
Hardware faults
Corrupted data
Bad storage blocks
Possible responses include:
Retrying the operation
Reporting an error to the process
Marking a storage block as unusable
Logging the problem
Replacing or remapping a damaged block
Disconnecting or disabling the device
Notifying the user or system administrator
Storage controllers may retry a failed read several times. If a block continues to fail, it may be marked as bad so that the operating system does not use it again.
The system must determine appropriate limits. Repeating an operation indefinitely wastes time and may conceal a serious hardware problem. Eventually, repeated failures should be reported.
Error handling may differ depending on:
Whether the operation is a read or write
Whether the device is removable
Whether the data can be reconstructed
Whether the error is temporary or permanent
Whether retrying risks further damage
20. I/O Protection
I/O operations must be protected from unsafe or unauthorized access.
A poorly behaved process might attempt to communicate directly with a device instead of using operating-system system calls. This could allow it to:
Read data belonging to another process
Overwrite device data
Interfere with another process’s output
Bypass access permissions
Crash the system
Corrupt hardware state
The operating system therefore controls access to I/O through the kernel. Processes normally request I/O using protected system calls, and the kernel checks whether the operation is allowed.
Direct access to hardware is blocked or restricted unless the operating system explicitly grants it.
Protection ensures that:
Devices are accessed only by authorized processes.
One process cannot disrupt another process’s I/O.
Shared devices are synchronized.
Device commands are validated.
Hardware remains under kernel control.
21. Network I/O
Network communication is also an I/O operation. Network devices require:
Device controllers
Device drivers
Buffers
Interrupts
Scheduling
Error handling
Operating-system coordination
Network I/O differs from local storage I/O because data must travel through a communication protocol and may involve another computer.
Applications commonly use a socket interface to communicate over a network. A socket provides an abstraction through which a program can send and receive data without directly controlling the network hardware.
The network stack separates responsibilities into layers. These layers distinguish among:
Physical transmission
Data-link communication
Network addressing
Transport reliability
Application-level communication
This layered design allows different hardware and protocols to work together while presenting applications with a consistent interface.
Network I/O is often slower and less predictable than local I/O because it includes:
Transmission delay
Routing delay
Network congestion
Packet loss
Remote-system processing
Protocol overhead
22. File Access Through the I/O System
Users and applications generally think in terms of files rather than physical devices. When an application opens a file, the operating system must translate the user-level file request into device-level operations.
A typical file-read process is:
The application requests a file by name.
The operating system determines which device contains the file.
The file name is translated into a device and physical or logical location.
The operating system identifies the appropriate device driver.
The driver communicates with the device controller.
The device retrieves the requested data.
The data is placed in a device or operating-system buffer.
The data may be copied into a cache.
The result is returned through the I/O subsystem.
The application receives the data.
If the requested data is already in a cache, the operating system may return it immediately without accessing the physical device.
This layered process occurs for many everyday actions:
Opening a document
Reading a file
Saving changes
Pressing a keyboard key
Displaying a character
Accessing cloud storage
Sending a print job
Local and Network-Based Files
When a file is stored on a network service, additional network operations are required:
The local operating system processes the file request.
The request is sent through the network stack.
The remote system receives and processes the request.
Data travels back through the network.
The local system places the data into buffers or caches.
The application receives the result.
Because network access adds delay, systems such as cloud-storage services often keep local synchronized copies of frequently used files. The local copy improves performance while synchronization ensures that changes are eventually reflected in the remote copy.
23. Overall Performance Challenges
I/O is often much slower than CPU computation. The operating system therefore uses several techniques to improve performance:
Interrupt-driven I/O
DMA
Buffering
Caching
Spooling
Device scheduling
Asynchronous operations
Local copies of frequently accessed network data
Efficient drivers and controllers
These techniques reduce the amount of time that the CPU spends waiting and allow computation and device activity to occur simultaneously.
However, every optimization introduces management costs. Buffers, caches, DMA controllers, queues, drivers, and device records all require:
Memory
Processing time
Synchronization
Error handling
Consistency management
The operating system must balance speed, fairness, reliability, security, and resource consumption.
Effective I/O management coordinates hardware, drivers, interrupts, memory, processes, and devices so that slow and diverse hardware can appear to applications as a consistent and reliable system.

Ask anything
We've read this whole study set, so questions about it get the best answers.