Skip to content

I/O Systems | Computer Science

------------- | -------------------------- | -------------- | | Human-readable | Keyboard, screen, printer | Low |“

Section titled “------------- | -------------------------- | -------------- | | Human-readable | Keyboard, screen, printer | Low |“”
CategoryExamplesData rate
Human-readableKeyboard, screen, printerLow
Machine-readableDisk, tape, sensorsMedium to high
CommunicationNetwork interfaces, modemsVariable

A device driver is kernel-mode software that translates OS I/O requests into device-specific Operations. It provides a uniform interface to the OS while hiding hardware details.

Driver architecture (layered):

User application
System call interface (read, write, ioctl)
File system / block layer
Device driver (kernel module)
Device controller (hardware)

Types:

  • Block device drivers: Manage fixed-size block access (disks, SSDs). Use a buffer cache to reduce physical I/O. The OS can reorder and merge block requests for performance.
  • Character device drivers: Manage byte-stream access (terminals, serial ports). No buffering or reordering by the OS.

Driver loading. Most modern OSes support loadable kernel modules (LKMs): drivers loaded at Runtime without rebooting. On Linux: insmod``modprobe. This allows third-party hardware support Without kernel recompilation.

I/O schedulers reorder and merge requests to improve performance:

  • FCFS: Simple but may cause starvation.
  • SSTF: Service the request closest to the current head position. Minimises seek but can starve distant requests.
  • SCAN (elevator): Head moves in one direction servicing requests, then reverses.
  • C-SCAN: Like SCAN but only services in one direction; returns without servicing.
  • LOOK / C-LOOK: Optimised SCAN/C-SCAN that reverses when no requests remain ahead.

Theorem 7.1. C-SCAN provides more uniform wait times than SCAN.

Proof. SCAN services requests in both directions, so requests at the extremes of the disk wait Longer. C-SCAN treats the disk as a circular queue, ensuring every request is serviced within one Full sweep. \blacksquare

Worked Example 7.1 — Disk Scheduling Comparison

Disk with 200 cylinders (0—199). Request queue (sorted): 98, 183, 37, 122, 14, 124, 65, 67. Current head position: 53, moving toward higher cylinders.

FCFS: 53 → 98 → 183 → 37 → 122 → 14 → 124 → 65 → 67. Total seek = 5398+98183+18337+37122+12214+14124+12465+6567=45+85+146+85+108+110+59+2=640\lvert 53-98 \rvert + \lvert 98-183 \rvert + \lvert 183-37 \rvert + \lvert 37-122 \rvert + \lvert 122-14 \rvert + \lvert 14-124 \rvert + \lvert 124-65 \rvert + \lvert 65-67 \rvert = 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 cylinders.

SSTF: 53 → 65 → 67 → 37 → 14 → 98 → 122 → 124 → 183. Total seek = 12+2+30+23+84+24+2+59=23612 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236 cylinders.

SCAN (elevator, moving right): 53 → 65 → 67 → 98 → 122 → 124 → 183 → 199 → 37 → 14. Total seek = 12+2+31+24+2+59+16+162+23=33112 + 2 + 31 + 24 + 2 + 59 + 16 + 162 + 23 = 331 cylinders.

C-SCAN (moving right): 53 → 65 → 67 → 98 → 122 → 124 → 183 → 199 → 0 → 14 → 37. Total seek = 12+2+31+24+2+59+16+199+14+23=38212 + 2 + 31 + 24 + 2 + 59 + 16 + 199 + 14 + 23 = 382 cylinders.

LOOK (stops at last request): 53 → 65 → 67 → 98 → 122 → 124 → 183 → 37 → 14. Total seek = 12+2+31+24+2+59+146+23=29912 + 2 + 31 + 24 + 2 + 59 + 146 + 23 = 299 cylinders.

AlgorithmTotal SeekMax WaitFairness
FCFS640335Fair
SSTF236130Starves
SCAN331313Good
C-SCAN382329Best
LOOK299299Good

SSTF minimises total seek but starves requests at the extremes. C-SCAN provides the most uniform Wait time at the cost of higher total seek.

DMA allows I/O devices to transfer data directly to/from memory without per-word CPU Intervention.

Without DMA: CPU reads each word from the device controller to memory. For a 4 KiB read, the CPU Is interrupted 4096 times.

With DMA: CPU programs the DMA controller with source, destination, and count. DMA handles the Transfer, interrupting the CPU only when complete.

  • DMA transfers are cycle-stealing: the DMA controller uses the system bus, pausing the CPU.
  • Modern systems use bus mastering: the I/O device controller performs the transfer autonomously.
  • Confusing polling (busy-waiting) with interrupt-driven I/O. Polling wastes CPU cycles; interrupts are preferred for low-frequency devices.
  • Assuming DMA eliminates all CPU overhead. The CPU must still set up DMA descriptors and handle the completion interrupt.
  • Forgetting that I/O schedulers only apply to block devices. Character devices use FIFO ordering.
  • Mixing up virtual and physical addresses when programming DMA controllers. The DMA controller operates on physical addresses.
flowchart TD
A[7_I O Systems] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]

I/O systems are the nervous system connecting the CPU to the outside world. Polling is like checking the mailbox every minute — simple but wasteful. Interrupts are like a doorbell — the device signals when it needs attention, and the CPU drops what it is doing to respond. DMA is like hiring a delivery service — the device transfers data directly to memory without bothering the CPU for every byte. Buffering is the waiting room — data is collected in a holding area before being processed in bulk, smoothing out the mismatch between fast producers and slow consumers.

This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.

Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.

Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.

This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.

Ensure you have mastered the prerequisite material before attempting this advanced content.

This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.

Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.

Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.

This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.

Ensure you have mastered the prerequisite material before attempting this advanced content.