Knowledge / Computer Science and Engineering / I/O systems and device management

I/O systems and device management

Computer Science and Engineering (B.E./B.Tech) · Operating systems · free study notes for exams, placements and interviews

In short

The I/O system is the part of the operating system that moves data between the CPU/memory and the outside world - keyboards, disks, NICs, printers, touchscreens, sensors - and hides the differences between hundreds of device types behind a few uniform interfaces (read, write, open, close, ioctl). It matters because I/O, not computation, is the bottleneck in most real systems: a CPU instruction takes a nanosecond, a disk access milliseconds, so the design question is always "how do we avoid making the CPU wait?" In exams it appears as programmed I/O vs interrupt-driven I/O vs DMA, interrupt handling steps, buffering/spooling and device-driver structure; GATE sets numericals on data-transfer rates, DMA cycle stealing and interrupt overhead. In placement rounds (TCS, Infosys, Wipro, Cognizant, Qualcomm, Samsung R&D, Bosch, Tata Elxsi, Zoho, embedded and firmware roles) the standard questions are "what is DMA and why use it", "polling vs interrupt", "how does a device driver work" and "what is memory-mapped I/O".

Explained

Hardware: devices, controllers, buses and ports

The three techniques of data transfer

1. Programmed I/O (polling / busy-waiting)

2. Interrupt-driven I/O

3. Direct Memory Access (DMA)

Interrupt mechanism in detail

Kernel I/O subsystem: software layers and services

Layering (bottom to top): device hardware → device controller → device driver → device-independent kernel I/O subsystem → system-call interface → user-level I/O library (stdio) → application.

Blocking, non-blocking and asynchronous I/O

Performance, I/O protection and transformation of a request

Key points

Formulas and examples

Effective transfer time per byte (programmed I/O) = (instructions per byte × cycles per instruction × CPU cycle time) — the CPU is occupied for the whole transfer
CPU time for interrupt-driven I/O = (number of transfers) × (interrupt overhead + ISR time); number of transfers = total bytes / bytes per interrupt
CPU time for DMA = setup time + completion-interrupt time (independent of block size)
Device data rate R = bytes per second; time to transfer N bytes = N / R
DMA bus cycles stolen per block = block size (bytes) / bus width (bytes per cycle)
CPU slowdown with cycle stealing (%) = (cycles stolen per second / total CPU cycles per second) × 100
Effective access time with buffering/cache = h × t_cache + (1 − h) × t_device, where h = hit ratio
Interrupts per second = device rate / transfer size per interrupt
Throughput utilisation of a device = (useful transfer time) / (useful transfer time + overhead time)

Example 1 - Polling vs interrupts for a keyboard. A keyboard delivers at most 100 characters per second. Polling the status register costs 50 CPU cycles per poll and the OS polls 1,000 times per second; an interrupt costs 400 cycles (save/restore + ISR). CPU runs at 1 GHz (10⁹ cycles/s).

Example 2 - Interrupt-driven I/O vs DMA for a disk block. Transfer 4 KB (4,096 bytes) from disk. Interrupt-driven I/O moves 2 bytes per interrupt; each interrupt costs 1,000 cycles. DMA needs 1,500 cycles of setup and 1,000 cycles for the completion interrupt. CPU = 2 GHz.

Example 3 - Cycle stealing and CPU slowdown. A device transfers 40 MB/s (40 × 10⁶ bytes/s) by DMA in cycle-stealing mode. The bus moves 4 bytes per cycle and the CPU runs at 500 MHz, one bus cycle per CPU cycle.

Example 4 - Interrupts per second and ISR budget for a NIC. A 1 Gbps Ethernet NIC receives minimum-size frames of 64 bytes (plus 20 bytes of inter-frame gap and preamble ⇒ 84 bytes on the wire = 672 bits).

Example 5 - Effective access time with a buffer cache. A block read hits the page cache 85% of the time (hit cost 1 µs); a miss costs about 8 ms from an HDD, or about 0.1 ms (100 µs) from a SATA SSD - both are worked below for comparison.

TechniqueWho moves the dataInterrupts per blockCPU costExtra hardwareTypical use
Programmed I/O (polling)CPU, in a loop0Very highNoneBoot code, tiny MCUs, very fast devices
Interrupt-driven I/OCPU, inside ISROne per byte/wordHigh at high ratesInterrupt controllerKeyboard, mouse, UART, low-rate sensors
DMADMA controllerOne per blockVery lowDMA controller, bus arbiterDisk, SSD, NIC, audio, graphics
Channel I/OI/O processorOne per channel programLowestI/O processorMainframes
FeatureMemory-mapped I/OPort-mapped I/O
Address spaceShares physical memory spaceSeparate I/O space
InstructionsNormal load/storeSpecial IN/OUT
Address space costConsumes memory addressesNone
Large regions (frame buffer)EasyAwkward
Typical platformARM, RISC-V, PCIe BARsLegacy x86 peripherals
AspectBufferCacheSpool
PurposeSmooth speed/size mismatchSpeed up repeat accessSerialise jobs for a dedicated device
Copy statusMay be the only copyAlways a duplicateA queued job file
ExampleUART ring bufferPage cacheCUPS print queue

Where it is used

Interview questions

Common mistakes

Related topics

Open in the Knowledge reader →Find jobs →