31
I/O Systems & Mass-Storage Systems

I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Embed Size (px)

Citation preview

Page 1: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

I/O Systems & Mass-Storage Systems

Page 2: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

I/O Hardware

Incredible variety of I/O devices Common concepts

Port Bus (daisy chain or shared direct access) Controller (host adapter)

I/O instructions control devices Devices have addresses, used by

Direct I/O instructions Memory-mapped I/O

Page 3: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

A Typical PC Bus Structure

Page 4: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Polling

Determines state of device command-ready busy Error

Busy-wait cycle to wait for I/O from device

Page 5: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Interrupts

CPU Interrupt request line triggered by I/O device

Interrupt handler receives interrupts

Maskable to ignore or delay some interrupts

Interrupt vector to dispatch interrupt to correct handler Based on priority Some unmaskable

Interrupt mechanism also used for exceptions

Page 6: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Direct Memory Access Used to avoid programmed I/O for large data movement

Requires DMA controller

Bypasses CPU to transfer data directly between I/O device and memory

Page 7: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Six Step Process to Perform DMA Transfer

Page 8: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Application I/O Interface

I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel Devices vary in many dimensions

Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only

Page 9: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Block and Character Devices

Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible

Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing

Page 10: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Network Devices

Varying enough from block and character to have own interface

Unix and Windows NT/9i/2000 include socket interface Separates network protocol from network operation Includes select functionality

Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes)

Page 11: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Clocks and Timers

Provide current time, elapsed time, timer

If programmable interval time used for timings, periodic interrupts

ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers

Page 12: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Blocking and Nonblocking I/O

Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs

Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written

Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed

Page 13: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Kernel I/O Subsystem

Scheduling Some I/O request ordering via per-device queue Some OSs try fairness

Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain “copy semantics”

Page 14: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Kernel I/O Subsystem

Caching - fast memory holding copy of data Always just a copy Key to performance

Spooling - hold output for a device If device can serve only one request at a time i.e., Printing

Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock

Page 15: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Error Handling

OS can recover from disk read, device unavailable, transient write failures

Most return an error number or code when I/O request fails

System error logs hold problem reports

Page 16: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Kernel Data Structures

Kernel keeps state info for I/O components, including open file tables, network connections, character device state

Many, many complex data structures to track buffers, memory allocation, “dirty” blocks

Some use object-oriented methods and message passing to implement I/O

Page 17: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

I/O Requests to Hardware Operations

Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process

Page 18: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

STREAMS

STREAM – a full-duplex communication channel between a user-level process and a device

A STREAM consists of:

- STREAM head interfaces with the user process

- driver end interfaces with the device- zero or more STREAM modules between them.

Each module contains a read queue and a write queue

Message passing is used to communicate between queues

Page 19: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Disk Structure

Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.

The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the outermost cylinder. Mapping proceeds in order through that track, then the rest of the tracks

in that cylinder, and then through the rest of the cylinders from outermost to innermost.

Page 20: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Disk Scheduling

The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and disk bandwidth.

Access time has two major components Seek time is the time for the disk are to move the heads to the cylinder

containing the desired sector. Rotational latency is the additional time waiting for the disk to rotate the

desired sector to the disk head. Minimize seek time Seek time seek distance Disk bandwidth is the total number of bytes transferred, divided by the total

time between the first request for service and the completion of the last transfer.

Page 21: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

Disk Scheduling (Cont.)

Several algorithms exist to schedule the servicing of disk I/O requests. We illustrate them with a request queue (0-199).

98, 183, 37, 122, 14, 124, 65, 67

Head pointer 53

Page 22: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

FCFSIllustration shows total head movement of 640 cylinders.

Page 23: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

SSTF

Selects the request with the minimum seek time from the current head position.

SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests.

Illustration shows total head movement of 236 cylinders.

Page 24: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

SSTF (Cont.)

Page 25: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

SCAN

The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk, where the head movement is reversed and servicing continues.

Sometimes called the elevator algorithm. Illustration shows total head movement of 208 cylinders.

Page 26: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

SCAN (Cont.)

Page 27: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

C-SCAN

Provides a more uniform wait time than SCAN. The head moves from one end of the disk to the other. servicing requests as

it goes. When it reaches the other end, however, it immediately returns to the beginning of the disk, without servicing any requests on the return trip.

Treats the cylinders as a circular list that wraps around from the last cylinder to the first one.

Page 28: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

C-SCAN (Cont.)

Page 29: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

C-LOOK

Version of C-SCAN Arm only goes as far as the last request in each direction, then reverses

direction immediately, without first going all the way to the end of the disk.

Page 30: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

C-LOOK (Cont.)

Page 31: I/O Systems & Mass-Storage Systems. I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller

END