---
title: "Programmed I/O, DMA, device-independent software"
subject: "Operating System"
chapter: 6
key: "semester_6/operating_system:programmed-io-dma-device-independent"
source: https://www.bctengineer.com/q/semester_6/operating_system/programmed-io-dma-device-independent
site: BCT Engineering
---

# Programmed I/O, DMA, device-independent software

Operating System · Chapter 6: I/O Management and Disk Scheduling

- Asked in: 2070 Bhadra, 2+2+4 marks
- Video: [techniques for performing I/O in OS || HINDI ||#operatingsystem  #trending #viral #educationcandle](https://www.youtube.com/watch?v=zXifj94Gx_g) — Education Candle - Anjali Sharma
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/programmed-io-dma-device-independent
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-6

## Question

What are the disadvantages of programmed I/O? Explain about DMA. What are the functions of device independent I/O 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.

## Answer

#### 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).

```text
   +-----+   +--------+   +-----------------+
   | 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Main disadvantage of programmed I/O?
   A. It needs special DMA hardware
   B. The CPU busy-waits polling the status register for the whole transfer
   C. It interrupts on every block
   D. It cannot transfer data
   Answer: B. The CPU copies each byte and wastes cycles, so no overlap of computation and I/O. (Key point: Programmed I/O drawback)

2. In DMA, 'cycle stealing' means:
   A. The CPU steals disk cycles
   B. Interrupts are disabled forever
   C. The DMA controller takes bus cycles from the CPU to transfer a word
   D. Data is copied byte by byte by the CPU
   Answer: C. The DMA controller requests the bus and transfers data while the CPU waits for those cycles. (Key point: Cycle stealing)

3. A function of device-independent I/O software is:
   A. Issuing commands to controller registers
   B. Moving the disk arm
   C. Handling interrupts directly
   D. Presenting a uniform interface so drivers can be added without changing the OS
   Answer: D. Device-specific details stay in drivers. (Key point: Uniform interface)

4. Why does the device-independent layer provide a uniform block size?
   A. To hide different sector sizes of devices
   B. To speed up the arm
   C. To remove the need for drivers
   D. To reduce interrupts
   Answer: A. Higher layers then see one logical block size. (Key point: Block size)

## Related in Operating System

- [Disk scheduling; device-independent I/O software](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adisk-scheduling-device-independent-io) — Operating System, chapter 6
- [Device-independent I/O software with example](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adevice-independent-io-software-example) — Operating System, chapter 6
- [Programmed I/O disadvantages; DMA](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aprogrammed-io-disadvantages-dma) — Operating System, chapter 6
- [Device controller vs kernel; DMA](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adevice-controller-vs-kernel-dma) — Operating System, chapter 6

## Related in other subjects

- [Programmed vs interrupt-driven vs DMA](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Aio-techniques-compare) — Computer Organization and Architecture, chapter 7, asked 5×
- [DMA vs programmed and interrupt-driven I/O](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Adma-overcomes) — Computer Organization and Architecture, chapter 7, asked 3×
- [USB host, hub, device and packets](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Ausb-host-hub-device-packets) — Instrumentation II, chapter 3
