chapter 13: i/o systems - github pages · 14.23 college of software engineering, southeast...

Post on 04-Jun-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 13: I/O Systems

肖卿俊办公室:九龙湖校区计算机楼212室电邮:csqjxiao@seu.edu.cn

主页: https://csqjxiao.github.io/PersonalPage电话:025-52091022

College of Software Engineering, Southeast University14.2

Chapter 13: I/O Systems

! I/O Hardware!Application I/O Interface!Kernel I/O Subsystem!Transforming I/O Requests to Hardware

Operations!Streams!Performance

College of Software Engineering, Southeast University14.3

I/O Hardware! Incredible variety of I/O devices!Common concepts

uPortuBus (daisy chain

or shared direct access)uController (host

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

uDirect I/O instructionsuMemory-mapped I/O

College of Software Engineering, Southeast University14.4

A Typical PC Bus Structure

College of Software Engineering, Southeast University14.5

Device I/O Port Locations on PCs (partial)

College of Software Engineering, Southeast University14.6

Polling

!Determines state of device ucommand-readyubusyuError

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

College of Software Engineering, Southeast University14.7

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

handleruBased on priorityuSome nonmaskable

! Interrupt mechanism also used for exceptions

College of Software Engineering, Southeast University14.8

Interrupt-Driven I/O Cycle

College of Software Engineering, Southeast University14.9

Intel Pentium Processor Event-Vector Table

College of Software Engineering, Southeast University14.10

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

College of Software Engineering, Southeast University14.11

Six Step Process to Perform DMA Transfer

College of Software Engineering, Southeast University14.12

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

uCharacter-stream or blockuSequential or random-accessuSharable or dedicateduSpeed of operationuread-write, read only, or write only

College of Software Engineering, Southeast University14.13

A Kernel I/O Structure

College of Software Engineering, Southeast University14.14

Characteristics of I/O Devices

College of Software Engineering, Southeast University14.15

Block and Character Devices

!Block devices include disk drivesuCommands include read, write, seek uRaw I/O or file-system accessuMemory-mapped file access possible

!Character devices include keyboards, mice, serial portsuCommands include get, putuLibraries layered on top allow line editing

College of Software Engineering, Southeast University14.16

Network Devices!Varying enough from block and character to

have own interface

!Unix and Windows NT/9x/2000 include socket interfaceuSeparates network protocol from network

operationuIncludes select functionality

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

College of Software Engineering, Southeast University14.17

Clocks and Timers

!Provide current time, elapsed time, timer

!Programmable interval timer used for timings, periodic interrupts

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

College of Software Engineering, Southeast University14.18

Blocking and Nonblocking I/O!Blocking - process suspended until I/O

completeduEasy to use and understanduInsufficient for some needs

!Nonblocking - I/O call returns as much as availableuUser interface, data copy (buffered I/O)uImplemented via multi-threadinguReturns quickly with count of bytes read or written

College of Software Engineering, Southeast University14.19

Blocking and Nonblocking I/O

!Asynchronous - process runs while I/O executesuDifficult to useuI/O subsystem signals process when I/O completed

College of Software Engineering, Southeast University14.20

Two I/O Methods

Synchronous Asynchronous

College of Software Engineering, Southeast University14.21

Kernel I/O Subsystem

!SchedulinguSome I/O request ordering via per-device

queueuSome OSs try fairness

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

College of Software Engineering, Southeast University14.22

Device-status Table

College of Software Engineering, Southeast University14.23

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

uAlways just a copyuKey to performance

!Spooling - hold output for a deviceuIf device can serve only one request at a time ui.e., Printing

!Device reservation - provides exclusive access to a deviceuSystem calls for allocation and deallocationuWatch out for deadlock

College of Software Engineering, Southeast University14.24

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

College of Software Engineering, Southeast University14.25

I/O Protection

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

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

College of Software Engineering, Southeast University14.26

Use of a System Call to Perform I/O

College of Software Engineering, Southeast University14.27

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

College of Software Engineering, Southeast University14.28

UNIX I/O Kernel Structure

College of Software Engineering, Southeast University14.29

I/O Requests to Hardware Operations

!Consider reading a file from disk for a process:

uDetermine device holding file uTranslate name to device representationuPhysically read data from disk into bufferuMake data available to requesting processuReturn control to process

College of Software Engineering, Southeast University14.30

Life Cycle of An I/O Request

College of Software Engineering, Southeast University14.31

Performance

! I/O a major factor in system performance:

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

uContext switches due to interruptsuData copyinguNetwork traffic especially stressful

College of Software Engineering, Southeast University14.32

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

College of Software Engineering, Southeast University14.33

Device-Functionality Progression

top related