33
Chapter 13: I/O Systems 肖卿俊 办公室:九龙湖校区计算机楼212电邮:[email protected] 主页: https://csqjxiao.github.io/PersonalPage 电话:025-52091022

Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

Chapter 13: I/O Systems

肖卿俊办公室:九龙湖校区计算机楼212室电邮:[email protected]

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

Page 2: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 3: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 4: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.4

A Typical PC Bus Structure

Page 5: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.5

Device I/O Port Locations on PCs (partial)

Page 6: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.6

Polling

!Determines state of device ucommand-readyubusyuError

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

Page 7: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 8: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.8

Interrupt-Driven I/O Cycle

Page 9: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.9

Intel Pentium Processor Event-Vector Table

Page 10: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 11: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.11

Six Step Process to Perform DMA Transfer

Page 12: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 13: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.13

A Kernel I/O Structure

Page 14: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.14

Characteristics of I/O Devices

Page 15: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 16: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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)

Page 17: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 18: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 19: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 20: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.20

Two I/O Methods

Synchronous Asynchronous

Page 21: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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”

Page 22: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.22

Device-status Table

Page 23: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 24: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 25: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 26: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.26

Use of a System Call to Perform I/O

Page 27: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 28: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.28

UNIX I/O Kernel Structure

Page 29: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 30: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.30

Life Cycle of An I/O Request

Page 31: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 32: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

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

Page 33: Chapter 13: I/O Systems - GitHub Pages · 14.23 College of Software Engineering, Southeast University Kernel I/O Subsystem Caching - fast memory holding copy of data uAlways just

College of Software Engineering, Southeast University14.33

Device-Functionality Progression