49
I/O Systems Maciej Sałata 2006

I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Embed Size (px)

Citation preview

Page 1: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

I/O Systems

Maciej Sałata 2006

Page 2: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

I/O Systems

PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware

Operations Streams PerformancePART II – Real-life PC I/O hardware

Page 3: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PART I

Abstract approach

Based on Operating System Concepts by Avi Silberschatz, Peter Baer Galvin and Greg Gagne

http://codex.cs.yale.edu/avi/os-book/os7/

Page 4: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 instructionsMemory-mapped I/O

Page 5: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

A Typical PC Bus Structure

Page 6: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Device I/O Port Locations on PCs (partial)

Page 7: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Polling

Determines state of device command-readybusyError

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

Page 8: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 handlerBased on prioritySome nonmaskable

Interrupt mechanism also used for exceptions

Page 9: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Interrupt-Driven I/O Cycle

Page 10: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 11: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Six Step Process to Perform DMA Transfer

Page 12: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 dimensionsCharacter-stream or blockSequential or random-accessSharable or dedicatedSpeed of operationread-write, read only, or write only

Page 13: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

A Kernel I/O Structure

Page 14: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Characteristics of I/O Devices

Page 15: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Block and Character Devices

Block devices include disk drivesCommands include read, write, seek Raw I/O or file-system accessMemory-mapped file access possible

Character devices include keyboards, mice, serial portsCommands include get, putLibraries layered on top allow line editing

Page 16: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 availableUser interface, data copy (buffered I/O) Implemented via multi-threadingReturns quickly with count of bytes read or written

Page 17: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Blocking and Nonblocking I/O

Asynchronous - process runs while I/O executesDifficult to use I/O subsystem signals process when I/O

completed

Page 18: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Two I/O Methods

Synchronous Asynchronous

Page 19: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Kernel I/O Subsystem

SchedulingSome I/O request ordering via per-device queueSome OSs try fairness

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

Page 20: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Kernel I/O Subsystem Caching - fast memory holding copy of data

Always just a copyKey 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 deviceSystem calls for allocation and deallocationWatch out for deadlock

Page 21: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

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 22: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

I/O Protection

User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructionsAll I/O instructions defined to be privileged I/O must be performed via system calls

Memory-mapped and I/O port memory locations must be protected too

Page 23: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

I/O Requests to Hardware Operations Consider reading a file from disk for a

process: Determine device holding file Translate name to device representationPhysically read data from disk into bufferMake data available to requesting processReturn control to process

Page 24: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Life Cycle of An I/O Request

Page 25: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

STREAMS

STREAM – a full-duplex communication channel between a user-level process and a device in Unix System V and beyond

A STREAM consists of:

- STREAM head interfaces with the user process

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

Page 26: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

STREAMS

Each module contains a read queue and a write queue

Message passing is used to communicate between queues

Page 27: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

The STREAMS Structure

Page 28: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Performance

I/O a major factor in system performance:

Demands CPU to execute device driver, kernel I/O code

Context switches due to interruptsData copyingNetwork traffic especially stressful

Page 29: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Intercomputer Communications

Page 30: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Improving Performance

Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers,

smart controllers, polling Use DMA Balance CPU, memory, bus, and I/O

performance for highest throughput

Page 31: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PART II

Real-life PC I/O hardware

Based on various articles from Wikipediahttp://wikipedia.org

Page 32: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Drive interfaces

Allow to communicate with disk/optical drives

Short-ranged (with exceptions)

Page 33: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

ATA (parallel)

Developed in late 80’s by Western Digital Integrated Drive Electronics (IDE) AT Attachment Packet Interface Bandwidth – up to 133 MB/s (UDMA-133)

Page 34: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

SCSI

Developed in 1986 Special controller needed Bandwidth – from 1.5 MB/s (SCSI 1) to

640 MB/s (Ultra-640 SCSI)

Page 35: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

SATA

Introduced in 2001 Hot-pluggable Natively supports command queueing Bandwidth – from 150 MB/s to 300 MB/s

Page 36: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Fibre Channel

Used for SANs Despite its name, runs on copper twisted-

pair cables too Topologies

Point-to-point (vide ordinary ATA)Arbitrated loop (vide token ring)Switched fabric (vide ethernet)

Page 37: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

System buses

Used for communication with peripheral devices

Allow to extend functionality High bandwidth

Page 38: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

ISA (Industry Standard Arch.)

Obsolete nowadays Bandwidth – from 4.77 MB/s (8-bit)

to 16.67 MB/s (16-bit)

Page 39: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PCI

Bandwidth – 133 MB/s (32-bit/33MHz) up to 533 MB/s (64-bit/66MHz)

Improvement – PCI-X

Page 40: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

AGP

Designed to cope with big throughput required by video cards

Bandwidth – 266 MB/s (1x) up to2133 MB/s (8x)

Page 41: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PCI-X („Extended”)

Connector physically identical to PCI Do not confuse with PCI Express Bandwidth – up to 4.27 GB/s

Page 42: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PCI Express

Fast and robust Comes in many flavors – from 1x to 16x

(250 MB/s – 8GB/s)

Page 43: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

External interfaces

Hot-pluggable (most of them) Allow further extension of functionality plus

additional convenience of use

Page 44: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Serial Port (RS-232)

Standard port used for serial communication, e.g.:Between a computer and a character deviceBetween two computers

Bandwidth – up to 115,200 bps

Page 45: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Parallel port

Transmits several bits in parallel (as the name suggests)

Omitted in modern computers Bandwidth – from 360 kBps to 2.5 MBps

Page 46: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

PS/2

DIN/RS-232 replacement Not hot-pluggable Bandwidth – 40 kB/s Used for mice/keyboards

Page 47: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

Universal Serial Bus

1.0 – about 0.2 MB/s 1.1 – 1.5 MB/s („Full-speed”) 2.0 – 60 MB/s („High-speed”) Power supply over bus

Page 48: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

IEEE 1394 (FireWire , i.Link )

Similar to USB Bandwidth – up to 50 MB/s 1394b – 100 MB/s – 400 MB/s

Page 49: I/O Systems Maciej Sałata 2006. I/O Systems PART I – Abstract aroach I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests

The End

Any questions?