ch13

27
Chapter 13: I/O Systems Chapter 13: I/O Systems

Upload: tech2click

Post on 02-Jun-2015

1.952 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Ch13

Chapter 13: I/O SystemsChapter 13: I/O Systems

Page 2: Ch13

13.2 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

I/O HardwareI/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: Ch13

13.3 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

A Typical PC Bus StructureA Typical PC Bus Structure

Page 4: Ch13

13.4 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Device I/O Port Locations on PCs (partial)Device I/O Port Locations on PCs (partial)

Page 5: Ch13

13.5 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

PollingPolling

Determines state of device

command-ready

busy

Error

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

Page 6: Ch13

13.6 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

InterruptsInterrupts

CPU Interrupt-request line triggered by I/O device

Interrupt vector to dispatch interrupt to correct handler

Interrupt handler receives interrupts

Two interrupt request lines :

Nonmaskable

Maskable to ignore or delay some interrupts

Interrupt priority levels, i.e. high preempt low

Interrupt mechanism also used for exceptions

Page 7: Ch13

13.7 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Interrupt-Driven I/O CycleInterrupt-Driven I/O Cycle

Page 8: Ch13

13.8 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Intel Pentium Processor Event-Vector TableIntel Pentium Processor Event-Vector Table

Page 9: Ch13

13.9 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Direct Memory AccessDirect 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 10: Ch13

13.10 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Six Step Process to Perform DMA TransferSix Step Process to Perform DMA Transfer

Page 11: Ch13

13.11 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

I/O Hardware summeryI/O Hardware summery

A bus

A controller

An I/O port and its registers

The handshaking relationship between host and device controller

The execution of the handshaking in a polling loop or via interrupts

The offloading of this work to DMA controller for large transfers

Page 12: Ch13

13.12 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Application I/O InterfaceApplication 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 13: Ch13

13.13 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

A Kernel I/O StructureA Kernel I/O Structure

Page 14: Ch13

13.14 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Characteristics of I/O DevicesCharacteristics of I/O Devices

Page 15: Ch13

13.15 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Block and Character DevicesBlock 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

Page 16: Ch13

13.16 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Blocking and Nonblocking I/OBlocking 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

Asynchronous - process runs while I/O executes

I/O subsystem signals process when I/O completed

Page 17: Ch13

13.17 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Two I/O MethodsTwo I/O Methods

Synchronous Asynchronous

Kernel

Page 18: Ch13

13.18 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Kernel I/O SubsystemKernel I/O Subsystem

Scheduling

Some I/O request ordering via per-device queue

Some OSs try fairness; by maintaining a wait queue of requests for each device

When a kernel supports asynchronous I/O, it must be able to keep track of many I/O requests at the same time.

Thus attach the wait-queue to a device status table.

Page 19: Ch13

13.19 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Device-status TableDevice-status Table

Page 20: Ch13

13.20 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Kernel I/O SubsystemKernel I/O Subsystem

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”

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

Page 21: Ch13

13.21 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Error HandlingError 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: Ch13

13.22 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

I/O ProtectionI/O Protection

User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions

All 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: Ch13

13.23 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Use of a System Call to Perform I/OUse of a System Call to Perform I/O

Page 24: Ch13

13.24 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Kernel Data StructuresKernel 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 25: Ch13

13.25 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

UNIX I/O Kernel StructureUNIX I/O Kernel Structure

Page 26: Ch13

13.26 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Transforming I/O Requests to Hardware Transforming I/O Requests to Hardware OperationsOperations

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 27: Ch13

13.27 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 2, 2005

Life Cycle of An I/O RequestLife Cycle of An I/O Request