Input-Output Systems in Operating Systems
Introduction to Input-Output Systems
Operating System Role in I/O
Shares the same device across different processes/users.
Abstracts hardware complexities from users: Users do not see how hardware operates.
Provides a device-independent interface for uniformity across different devices.
I/O Peripherals Architecture
Key Components:
CPU
Memory: Main Memory (including L1 and L2 caches)
I/O Buses: Memory Bus (e.g., DDRx), I/O Bus (e.g., PCI)
Addresses Range:
0x00…0
0x0ff..f
0x100…0
0x1ff….f
0x200…0
0x2ff….f
Memory-Mapped I/O
Allows reading and writing to device registers as if they are normal memory.
User programs typically do NOT have direct access to these operations.
OS Control: The operating system manages devices, facilitating secure access and control.
Address Translation:
These addresses may not require address translation because:
The OS accesses them directly, avoiding enforcement of protection.
There is no need for swapping/paging for these addresses.
Disk Device Operations
Process Overview:
Initial Command:
Store command in Command Register with READ_COMMAND.
Choose track number via Track Register.
Specify sector number in Sector Register.
Load Status:
Load R, [Status_Reg] cmp R, 0 jeqData Transfer:
Move data to the target memory.
Recommendation: Instead of blocking the entire CPU during transfers, employ interrupts to manage tasks efficiently.
DMA (Direct Memory Access) Engine
Purpose:
Offloads the CPU's workload by managing the data transfer between memory and peripheral devices directly.
Process Overview:
Command configuration for transfer is set (registers same as above plus Memory Address Register).
Disk Request Handling:
Use of interrupts to signal completion of transfers.
RAM on Controller
Serves as a buffer to address the speed mismatch between data streams from the disk and transfers to main memory.
Addressing in DMA
Address consideration:
Physical vs virtual addresses:
DMA needs physical addresses as it bypasses MMU (Memory Management Unit) for address translation.
The OS programs the DMA ensuring safe handling of addresses.
Addresses must be "pinned" in memory, preventing them from being evicted.
I/O Devices Classification
Block Devices:
Store information in fixed-sized blocks, individually addressable.
Common Examples: Disks, tapes.
Character Devices:
Deliver or accept streams of characters and are not individually addressable.
Common Examples: Terminals, printers, mice, network interfaces.
Principles of I/O Software
Key Principles:
Device Independence: Uniformity ensures that programs operate on any device.
Uniform Naming: Names should not directly depend on the type of device.
Error Handling: Should occur at the lowest level possible, escalate only if unavoidable.
Synchronization:
Synchronous (blocking) versus asynchronous (interrupt-driven) operations.
Asynchronous is more prevalent, yet synchronous is easier for programming.
I/O Software Architecture
Layered Approach:
Lowest layer (device-dependent): Device drivers.
Middle layer: Device-independent OS software.
Highest layer: User-level software/libraries.
Note: Device drivers and middleware are part of the kernel.
Device Drivers
Functionality: Handles abstract requests from device-independent software.
Interface: Consistent interface for all device drivers, including functions like Open(), Close(), Read(), Write(), Interrupt(), Ioctl().
Disk Driver Example
Semaphore Operations:
Open() and Close() methods defined.
Read() method programming the device while utilizing semaphores:
P(request)for synchronization.Write() and Interrupt handling specifically for disk read events.
Request Handling in Disk System
Multiple simultaneous requests can complicate order of service.
Efficiency of serving should consider not just order but seek time optimization.
Disks: Structure and Function
Physical Structure:
Comprises platters with surfaces, circular tracks, and sectors.
The assembly allows heads across surfaces to need synchronized positioning on cylinders.
Disk Access Costs
Actions Involved:
Seek to specific cylinder.
Wait for specified sectors to come under the head.
Transfer data.
Dominance of Seek:
Seek action inherently has the highest cost in terms of time (milliseconds).
Disk Scheduling Algorithms
First Come First Serve (FCFS):
Simple but often inefficient service order (example seek costs calculated).
Shortest Seek Time First (SSTF):
Services closest requests first, minimizing seek time but may lead to starvation.
SCAN Algorithm
technique where disk head moves in one direction servicing until the end, then reverses.
Provides bounded traverse distance for the head.
Circular-SCAN (C-SCAN) Algorithm
Variation of SCAN to ensure uniform wait time.
Only serves requests in an upward direction and returns to start without servicing in transit.
LOOK Algorithm
Similar to SCAN but moves only to the last request before reversing; avoids extremes.
C-LOOK Algorithm
A variant of C-SCAN that also only goes as far as the last request in the direction before reversing.
Device-Independent OS Layer
Manages device naming and permissions, providing a device independence and error reporting mechanism.
Final Integration in UNIX
System calls (e.g., open) interact directly with the file system to return device handles.
Behavior of User Requests:
Reference logical block ID for interactions with drivers across all devices.
Conclusion
The architecture of I/O systems is integral for ensuring efficient communication between the operating system and various hardware components, maintaining efficiency, uniformity, and reliability across operations related to input and output.