Operating systems

I/O Devices

Prashanth L.A.

2023-11-06

Lecture 38

I/O Devices

The crux

How should I/O be integrated into systems?

What are the general mechanisms?

How can we make the efficiently?

Prototypical System Architecture

I/O Architecture

Canonical Device

Register Description
Status register See the current status of the device
Command register Tell the device to perform a certain task
Data register Pass data to the device or get data from the device

Canonical protocol

while  STATUS == BUSY
; //wait until device is not busy
write data to data register
write command to command register
  (Doing so starts the device and executes the command)
while  STATUS == BUSY
; //wait until device is done with your request
Plus Minus
Simple, works. Wastes CPU time

Crux 2

How to avoid the costs of polling?

How can the OS check device status without frequent polling, and thus lower the CPU overhead required to manage the device?

Interrupts

Plus Minus
CPU used better Not good for fast devices

Crux 3: How to lower PIO overheads

What is PIO?

With PIO, the CPU spends too much time moving data to and from devices by hand. How can we offload this work and thus allow the CPU
to be more effectively utilized?

DMA (Direct Memory Access)

When completed DMA raises an interrupt I/O begins on Disk

Polling vs interrupts vs DMA

Polling

Intterupt

CPU copies data from memory to device

DMA

Crux 4: How to communicate with devices

How should the HW communicate with a device? 

Should there be explicit instructions? 

Or are there other ways to do it?

Two methods

Crux 5

How to build a device-neutral OS

How can we keep most of the OS device-neutral, thus hiding the details of device interactions from major OS subsystems?

File system abstraction

File system stack

LOC

According to cloc run against 3.13, Linux is about 12 million lines of code.

Ref: https://unix.stackexchange.com/questions/223746/why-is-the-linux-kernel-15-million-lines-of-code

Problems with top 2 million?