Skip to main content

Programmed I/O, DMA, device-independent software

Short answer

Programmed I/O wastes CPU cycles on polling and byte-by-byte copying, eliminating overlap. DMA uses a controller to transfer data directly between device and memory, interrupting only on block completion. Device-independent I/O provides a uniform driver interface, buffering, error reporting, device allocation, naming, protection, and caching.

What are the disadvantages of programmed I/O? Explain about DMA. What are the functions of device independent I/O software?

Disadvantages of programmed I/O

In programmed I/O the CPU does all the work: it issues the command and then repeatedly checks the status register (polling, busy waiting) and copies each byte between memory and the device register.

  • The CPU is tied up for the whole I/O operation and wastes cycles in polling.
  • Very low CPU utilization and poor overall throughput, because I/O devices are slower than the CPU.
  • No overlap of computation and I/O; not suitable for multiprogramming.
  • Each byte/word needs a CPU instruction, so large transfers are slow.

DMA

Direct Memory Access (DMA) lets an I/O device transfer a block of data directly to or from main memory without the CPU copying every byte. A special DMA controller (on the device controller or the motherboard) performs the transfer, and the CPU is interrupted only once, when the whole block is done.

The DMA controller has registers: a memory address register, a byte/word count register, and control register(s) (device, direction read/write, transfer unit, burst mode).

   +-----+   +--------+   +-----------------+
   | CPU |   | Memory |   |  DMA controller |
   +--+--+   +---+----+   | addr|count|ctrl |
      |          |        +---+---------+---+
 =====+==========+============|=========|==== bus
                                  +-----+-----+
                                  | Disk ctrl |
                                  +-----------+

Steps (read from disk):

  1. The CPU programs the DMA controller (address, count, direction) and tells the disk controller to read a block.
  2. The disk controller reads the block into its internal buffer and checks the checksum.
  3. The DMA controller requests the bus and transfers data to the memory address, incrementing the address and decrementing the count (cycle stealing - it takes bus cycles from the CPU).
  4. When the count reaches zero the DMA controller sends an interrupt to the CPU.
  5. The CPU runs the interrupt handler; data is already in memory.

Modes: cycle-stealing (one word at a time), burst (a block at once). Advantages: the CPU is free for other work, faster transfers and fewer interrupts (one per block instead of one per byte). Disadvantage: extra hardware, and bus contention.

Functions of device-independent I/O software

Device-independent I/O software is the layer of the OS that performs I/O functions common to all devices and gives a uniform interface to the user-level programs, so that device specific details remain in the drivers.

Functions:

  1. Uniform interfacing for device drivers: all drivers present the same functions to the kernel, so a new driver can be added without changing the OS.
  2. Buffering: holds data temporarily in kernel buffers (user buffer vs kernel buffer, double buffering) to cope with speed differences.
  3. Error reporting: handles programming errors (illegal operation) and passes on actual I/O errors.
  4. Allocating and releasing dedicated devices: devices such as printers and tapes are given to one process at a time (open/close).
  5. Providing a device-independent block size: hides different sector sizes of disks by presenting a uniform logical block size.
  6. Naming and protection: device names (such as /dev/sda) map to the proper driver; access permissions are checked.
  7. Caching and scheduling: block cache and disk scheduling.

Example: a program calls write(fd, buf, n). The call works the same whether fd refers to a file on a disk, a USB drive or the terminal; the device-independent layer checks permissions, buffers the data and selects the driver, and only then the driver talks to the specific controller.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 6 questions →