persistence: i/o devicespages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · what good is a computer...

40
PERSISTENCE: I/O DEVICES Shivaram Venkataraman CS 537, Spring 2020

Upload: others

Post on 12-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

PERSISTENCE: I/O DEVICES

Shivaram VenkataramanCS 537, Spring 2020

Page 2: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

CHECK: 1,2,3

1. Can you hear me?

2. Can you see the slides and the annotations?

3. Can you write a question on the chat?

Page 3: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

ADMINISTRIVIA

Project 4a: Out today! Due April 2nd, 10pm

Grades: Project 3 grades out!Midterm grades end of the week (hopefully)

Page 4: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

AGENDA / LEARNING OUTCOMES

How does the OS interact with I/O devices?

What are the components of a hard disk drive?

Page 5: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

RECAP

Page 6: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

OPERATING SYSTEMS: THREE EASY PIECES

Three conceptual pieces

1. Virtualization

2. Concurrency

3. Persistence

Make each application believe it has each resource to itselfCPU and Memory

Provide mutual exclusion, ordering

Page 7: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Motivation

What good is a computer without any I/O devices?

keyboard, display, disks

We want:- H/W that will let us plug in different devices

- OS that can interact with different combinations

Page 8: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Hardware support for I/O

Page 9: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us
Page 10: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Canonical Device

OS reads/writes to these

Status COMMAND DATADevice Registers

Page 11: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Example Write Protocol

while (STATUS == BUSY); // spin

Write data to DATA registerWrite command to COMMAND registerwhile (STATUS == BUSY)

; // spin

Status COMMAND DATA

Microcontroller (CPU+RAM)Extra RAMOther special-purpose chips

Page 12: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

while (STATUS == BUSY) // 1;

Write data to DATA register // 2Write command to COMMAND register // 3while (STATUS == BUSY) // 4

;

CPU:

Disk:

Page 13: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

23,4

A BCPU:

Disk: C A

B B AA

1

while (STATUS == BUSY) // 1

wait for interrupt;

Write data to DATA register // 2

Write command to COMMAND register // 3

while (STATUS == BUSY) // 4

wait for interrupt;

Interrupts!

Page 14: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Interrupts vs. Polling

Are interrupts always better than polling?

Fast device: Better to spin than take interrupt overhead– Device time unknown? Hybrid approach (spin then use interrupts)

Flood of interrupts arrive– Can lead to livelock (always handling interrupts)– Better to ignore interrupts while make some progress handling them

Other improvement – Interrupt coalescing (batch together several interrupts)

Page 15: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Protocol Variants

Status checks: polling vs. interrupts

Status COMMAND DATA

Microcontroller (CPU+RAM)Extra RAMOther special-purpose chips

Page 16: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

DATA TRANSFER COSTS

Page 17: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Programmed I/O vs. Direct Memory Access

PIO (Programmed I/O):– CPU directly tells device what the data is

DMA (Direct Memory Access):– CPU leaves data in memory

– Device reads data directly from memory

Page 18: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us
Page 19: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

while (STATUS == BUSY) // 1;

Write data to DATA register // 2Write command to COMMAND register // 3while (STATUS == BUSY) // 4

;

ACPU:

Disk: C A

B B A

1 3,4

Page 20: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Protocol Variants

Status checks: polling vs. interrupts

PIO vs DMA

Status COMMAND DATA

Microcontroller (CPU+RAM)Extra RAMOther special-purpose chips

Page 21: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

while (STATUS == BUSY) // 1;

Write data to DATA register // 2Write command to COMMAND register // 3while (STATUS == BUSY) // 4

;

Status COMMAND DATA

Microcontroller (CPU+RAM)Extra RAMOther special-purpose chips

Page 22: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Special Instructions vs. Mem-Mapped I/O

Special instructions– each device has a port

– in/out instructions (x86) communicate with device

Memory-Mapped I/O

– H/W maps registers into address space– loads/stores sent to device

Doesn’t matter much (both are used)

Page 23: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Protocol Variants

Status checks: polling vs. interrupts

PIO vs DMA

Special instructions vs. Memory mapped I/O

Status COMMAND DATA

Microcontroller (CPU+RAM)Extra RAMOther special-purpose chips

Page 24: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Storage Stack

applicationfile systemscheduler

driverhard drive

build common interfaceon top of all HDDs

DEVICE DRIVERS

Page 25: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Variety is a Challenge

Problem:

– many, many devices

– each has its own protocol

How can we avoid writing a slightly different OS for each H/W combination?

Write device driver for each device

Drivers are 70% of Linux source code

Page 26: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

QUIZ 20

If you have a fast non-volatile memory based storage device, which approach would work better?

What part of a device protocol is improved by using DMA ?

https://tinyurl.com/cs537-sp20-quiz20

Page 27: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

HARD DISKS

Page 28: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

HARD DISK INTERFACE

Disk has a sector-addressable address spaceAppears as an array of sectors

Sectors are typically 512 bytes

Main operations: reads + writes to sectors

Mechanical and slow (?)

Page 29: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Platter

Page 30: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Surface

Surface

Spindle

Page 31: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

RPM?

Motor connected to spindle spins platters

Rate of rotation: RPM

10000 RPM à single rotation is 6 ms

Page 32: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Surface is divided into rings: tracks

Stack of tracks(across platters): cylinder

Page 33: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

123

065 4

789

1011

1514

1312

16

17

18

19

23

22

21

20

Tracks are divided into numbered sectors

Page 34: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

123

065 4

789

1011

1514

1312

16

17

18

19

23

22

21

20

Heads on a moving arm can read from each surface.

Page 35: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

READING DATA FROM DISK

Rotational delay

Page 36: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

READING DATA FROM DISK

Seek Time

Page 37: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Time to Read/write

Three components:Time = seek + rotation + transfer time

Page 38: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

Seek, Rotate, Transfer

Seek cost: Function of cylinder distanceNot purely linear costMust accelerate, coast, decelerate, settleSettling alone can take 0.5 - 2 ms

Entire seeks often takes 4 - 10 msAverage seek = 1/3 of max seek

Depends on rotations per minute (RPM)7200 RPM is common, 15000 RPM is high end

Average rotation?

Pretty fast: depends on RPM and sector density.

100+ MB/s is typical for maximum transfer rate

Page 39: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

QUIZ 21

What is the time for 4KB random read?

https://tinyurl.com/cs537-sp20-quiz21

Page 40: PERSISTENCE: I/O DEVICESpages.cs.wisc.edu/.../cs537-io-devices-notes.pdf · What good is a computer without any I/O devices? keyboard, display, disks We want:-H/Wthat will let us

NEXT STEPS

Advanced disk featuresScheduling disk requests

Project 4a: Out tonightGrades: Project 2b, 3, midterm by tomorrow!