1 today i/o systems storage. 2 i/o devices many different kinds of i/o devices software that...

29
1 Today I/O Systems Storage

Post on 22-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

1

Today

I/O Systems Storage

Page 2: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

2

I/O Devices

Many different kinds of I/O devices Software that controls them: device

drivers

Page 3: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

3

Connection to CPU Devices connect to

ports or system bus: Allows devices to

communicate w/CPU Controller:

electronics to operate a port, bus or device

Communication between controller & CPU:

Ports (programmed I/O)

Direct-Memory Access (DMA)

Page 4: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

4

Ports (a.k.a. Programmed I/O)

CPU gives command/data to controller through registers

4 registers Status indicates device busy, data ready, error Control indicates command to perform Data-in read by CPU to get input from device Data-out written by CPU to device

Handshaking between CPU & controller Controller: clear busy bit (status) for new

command CPU: set command-ready bit (command)

Page 5: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

5

Polling: An Example

CPU wants to write a byte to a device CPU:

Busy-wait until status = idle Set command-ready bit, write to data-out

register Controller:

Reads command register set status = busy Read from data-out register, does I/O to

device Change status to idle or error

Page 6: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

6

Interrupts

Avoids busy waiting Device interrupts CPU when I/O

operation is complete CPU detects interrupt (sense

interrupt-request line) after each instruction

On interrupt: Determine which device caused

interrupt Interrupt vector to dispatch interrupt to

correct handler

Page 7: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

7

Interrupt-driven I/O Cycle

Page 8: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

8

DMA

Ports (“programmed I/O”) Fine for small amounts of data, low-speed Too expensive for large data transfers!

Solution: Direct Memory Access (DMA) Offload CPU large data transfers by a

special-purpose processor (DMA handler) DMA interrupts CPU when entire transfer

complete

Page 9: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

9

Steps in DMA Transfer

CPU writes a DMA command block into memory Pointer to source, destination, # of bytes for the

transfer CPU writes address of command block to DMA

controller DMA controller directly performs transfer

without help from CPU Handshaking between DMA controller & device

controller DMA interrupts CPU when entire transfer

complete

Page 10: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

10

I/O – Outline

I/O Systems I/O hardware basics I/O Services Buffering & Caching

Page 11: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

11

Low-Level Device Characteristics

Transfer unit: character, block Access method: sequential, random Sharing: dedicated, sharable (by multiple

threads/processes) Speed: a few bytes to gigabytes per second I/O direction: read-only, write-only, read-

write

Examples: terminal, CD-ROM, modem, keyboard, tape, graphics controller

Page 12: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

12

Application I/O Interface

High-level abstractions to hide device details Block devices (read, write, seek)

Also memory-mapped File abstraction

Character-stream devices (get, put) Keyboard, printers, etc.

Network devices (socket connections) Blocking & non-blocking

Blocking: wait until operation completes Non-blocking: returns immediately (or after

timeout) with whatever data is available (none, some, all)

Page 13: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

13

I/O – Outline

I/O Systems I/O hardware basics Services provided by OS Buffering & Caching

Page 14: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

14

I/O Buffering

Buffer = memory area to store data temporarily Disk buffer: stores block when read

from disk DMA: transferred over bus by DMA

controller into buffer in physical memory

Page 15: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

15

Why Buffering?

Speed mismatches between device, CPU Compute contents of display in buffer

(slow), send buffer to screen (fast) Different data transfer sizes

ftp brings file over network one packet at a time, stores to disk one block at a time

Minimizes time user process blocks on write Copy data to kernel buffer, return to user Kernel: writes from buffer to disk at later

time

Page 16: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

16

Caching

Cache: region of fast memory that holds copy of data

Example: CPU cache, TLB Cache write policies

Write-through Write to memory & disk (high reliability)

Write-back Write only to memory (committing later)

Trade-off between speed & reliability

Page 17: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

17

I/O Summary

I/O expensive for several reasons: Slow devices & slow communication

links Contention from multiple processes

Approaches to improving performance: Caching – reduces data copying Reduce interrupt frequency via large

data transfers DMA controllers – offload computation

from CPU

Page 18: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

18

Storage

Goal: Improve performance of storage systems (i.e., the disk) Disk Head Scheduling

Page 19: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

19

Disk Operations

Disks are SLOW! 1 disk seek = 40,000,000 cycles

Latency: Seek – position head over

track/cylinder Rotational delay – time for sector

to rotate underneath head Bandwidth:

Transfer time – move bytes from disk to memory

Page 20: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

20

Calculating Disk Operations Time

Read/write n bytes:

Can’t reduce transfer time Can we reduce latency?

I/O time = seek + rotational delay + transfer(n)

Page 21: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

21

Reducing Latency

Minimize seek time & rotational latency: Smaller disks Faster disks Sector size tradeoff Scheduling

Page 22: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

22

Disk Head Scheduling

Schedule order of disk accesses Reduce length & number of seeks

Algorithms FCFS SSTF SCAN, C-SCAN LOOK, C-LOOK

Page 23: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

23

FCFS

First-come, first-serve Example: disk tracks – (65, 40, 18,

78) assume head at track 50

Total seek time? 15+25+22+60 = 122

6518 7840

disk

I/O time = seek + rotational delay + transfer(n)

Page 24: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

24

SSTF

Shortest-seek-time first (like SJF) Example: disk tracks – (65, 40, 18,

78) assume head at track 50

Total seek time? 10+22+47+13 = 92

Is this optimal?

6518 7840

disk

I/O time = seek + rotational delay + transfer(n)

Page 25: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

25

SCAN

Always move back and forth across diska.k.a. elevator

Example: disk tracks – (65, 40, 18, 78) assume head at track 50, moving forwards,

total 100 cylinders

Total seek time? 15+13+22+60+22=132

When is this good?

6518 7840

disk

I/O time = seek + rotational delay + transfer(n)

Page 26: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

26

C-SCAN

Circular SCAN:Go back to start of disk after reaching end

Example: disk tracks – (65, 40, 18, 78) assume head at track 50, moving forwards,

total 100 cylinders

Total seek time? 15+13+22+100+18+22=190

Can be expensive, but more fair

6518 7840

disk

I/O time = seek + rotational delay + transfer(n)

Page 27: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

27

LOOK variants

Instead of going to end of disk,go to last request in each direction SCAN, C-SCAN → LOOK, C-LOOK

Page 28: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

28

Exercises

200 cylinders, currently at 140, moving forwards(5, 15, 90, 180, 80, 10 ) FCFS SSTF SCAN LOOK C-SCAN C-LOOK

Find sequence & total seek time First = 0, last = 200

Page 29: 1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

29

Solutions