Chapter 12: I/O Systems Silberschatz, Galvin and Gagne ©2013 – 2

advertisement
Chapter 12: I/O Systems
Operating System Concepts Essentials – 2nd Edition
Silberschatz, Galvin and Gagne ©2013
Chapter 12: I/O Systems
 Overview
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Performance
Operating System Concepts Essentials – 2nd Edition
12.2
Silberschatz, Galvin and Gagne ©2013
Objectives
 Explore structure of OS’s I/O subsystem
 Discuss principles of I/O hardware and its
complexity
 Provide details of performance aspects of I/O
hardware and software
Operating System Concepts Essentials – 2nd Edition
12.3
Silberschatz, Galvin and Gagne ©2013
Overview
 I/O management is major component OS design
and operation

Important aspect of computer operation

I/O devices vary greatly

Various methods to control them

Performance management

New types of devices frequent
Operating System Concepts Essentials – 2nd Edition
12.4
Silberschatz, Galvin and Gagne ©2013
Overview
 Ports, busses, device controllers connect to various
devices
 Device drivers encapsulate device details

Present uniform device-access interface to I/O
subsystem
Operating System Concepts Essentials – 2nd Edition
12.5
Silberschatz, Galvin and Gagne ©2013
Chapter 12: I/O Systems
 Overview
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Performance
Operating System Concepts Essentials – 2nd Edition
12.6
Silberschatz, Galvin and Gagne ©2013
I/O Hardware
 Variety of I/O devices

Storage (e.g., disk, CD-ROM)

Transmission (e.g., network card)

Human-interface (e.g., keyboard, mouse, screen)
Operating System Concepts Essentials – 2nd Edition
12.7
Silberschatz, Galvin and Gagne ©2013
I/O Hardware
 Common concepts – signals from I/O devices
interface with computer

Port – connection point for device

Bus - daisy chain or shared direct access
 PCI
bus common in PCs and servers
 Expansion
bus connects relatively slow devices
Operating System Concepts Essentials – 2nd Edition
12.8
Silberschatz, Galvin and Gagne ©2013
I/O Hardware
 Common concepts – signals from I/O devices
interface with computer

Controller (host adapter) – electronics that operate
port, bus, device
 Sometimes
integrated
 Sometimes
separate circuit board (host adapter)
 Contains
processor, microcode, private memory, bus
controller, etc.
Operating System Concepts Essentials – 2nd Edition
12.9
Silberschatz, Galvin and Gagne ©2013
A Typical PC Bus Structure
Operating System Concepts Essentials – 2nd Edition
12.10
Silberschatz, Galvin and Gagne ©2013
I/O Hardware (Cont.)
 I/O instructions control devices
 Devices have registers (1-4 bytes), e.g.,

Control register

Status register

Data-in register

Data-out register
Operating System Concepts Essentials – 2nd Edition
12.11
Silberschatz, Galvin and Gagne ©2013
I/O Hardware (Cont.)
 Devices have addresses, used by

Direct I/O instructions

Memory-mapped I/O
 Device
data and command registers mapped to
processor address space
 Especially
for large address spaces (graphics)
Operating System Concepts Essentials – 2nd Edition
12.12
Silberschatz, Galvin and Gagne ©2013
Device I/O Port Locations on PCs (partial)
Operating System Concepts Essentials – 2nd Edition
12.13
Silberschatz, Galvin and Gagne ©2013
Polling
 For each byte of I/O:
1.
Read busy bit from device status register until 0 (busy wait)
2.
Host sets read/write bit (if write, copies data into DO reg)
3.
Host sets command-ready bit
4.
Controller sets busy bit, executes transfer
5.
Controller clears busy bit, error bit, command-ready bit
when transfer done
Operating System Concepts Essentials – 2nd Edition
12.14
Silberschatz, Galvin and Gagne ©2013
Interrupts
 CPU Interrupt-request line triggered by I/O device

Checked by processor after each instruction
 Interrupt handler receives interrupts

Maskable - ignore or delay interrupt

Non-maskable – interrupt cannot be disabled
Operating System Concepts Essentials – 2nd Edition
12.15
Silberschatz, Galvin and Gagne ©2013
Interrupts
 Interrupt vector - dispatches interrupt to correct
handler

Context switch at start and end

Based on priority

Interrupt chaining - if more than one device share
same interrupt number
Operating System Concepts Essentials – 2nd Edition
12.16
Silberschatz, Galvin and Gagne ©2013
Interrupt-Driven I/O Cycle
Operating System Concepts Essentials – 2nd Edition
12.17
Silberschatz, Galvin and Gagne ©2013
Intel Pentium Processor Event-Vector Table
Operating System Concepts Essentials – 2nd Edition
12.18
Silberschatz, Galvin and Gagne ©2013
Interrupts (Cont.)
 Interrupt mechanism also used for exceptions

Terminate process, crash system due to HW error
 Page fault executes on memory access error
 System call executes via trap - triggers kernel to
execute request
 Multi-CPU systems can process interrupts
concurrently

If operating system designed to handle it
Operating System Concepts Essentials – 2nd Edition
12.19
Silberschatz, Galvin and Gagne ©2013
Direct Memory Access
 Used to avoid programmed I/O (one byte at a time)
for large data movement
 Requires DMA controller
 Bypasses CPU - transfers data directly between I/O
device and memory
Operating System Concepts Essentials – 2nd Edition
12.20
Silberschatz, Galvin and Gagne ©2013
Direct Memory Access
 OS writes DMA command block into memory

Source and destination addresses

Read or write mode

Count of bytes

Writes location of command block to DMA controller

Bus mastering of DMA controller – grabs bus from CPU
 Cycle
stealing from CPU
... but still more efficient

When done, interrupts CPU to signal completion
Operating System Concepts Essentials – 2nd Edition
12.21
Silberschatz, Galvin and Gagne ©2013
Six Step Process to Perform DMA Transfer
Operating System Concepts Essentials – 2nd Edition
12.22
Silberschatz, Galvin and Gagne ©2013
Chapter 12: I/O Systems
 Overview
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Performance
Operating System Concepts Essentials – 2nd Edition
12.23
Silberschatz, Galvin and Gagne ©2013
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
 Each OS has own I/O subsystem structures and
device driver frameworks
Operating System Concepts Essentials – 2nd Edition
12.24
Silberschatz, Galvin and Gagne ©2013
Application I/O Interface
 Devices vary:

Character-stream or block

Sequential or random-access

Synchronous or asynchronous (or both)

Sharable or dedicated

Speed of operation

read-write, read only, or write only
Operating System Concepts Essentials – 2nd Edition
12.25
Silberschatz, Galvin and Gagne ©2013
A Kernel I/O Structure
Operating System Concepts Essentials – 2nd Edition
12.26
Silberschatz, Galvin and Gagne ©2013
Characteristics of I/O Devices
Operating System Concepts Essentials – 2nd Edition
12.27
Silberschatz, Galvin and Gagne ©2013
Characteristics of I/O Devices (Cont.)
 Subtleties of devices handled by device drivers
 I/O devices grouped by OS into:

Block I/O

Character I/O (Stream)

Memory-mapped file access

Network sockets
Operating System Concepts Essentials – 2nd Edition
12.28
Silberschatz, Galvin and Gagne ©2013
Characteristics of I/O Devices (Cont.)
 Direct manipulation of I/O device characteristics

UNIX ioctl()- send arbitrary bits to
 device
 data
control register
to device data register
Operating System Concepts Essentials – 2nd Edition
12.29
Silberschatz, Galvin and Gagne ©2013
Block and Character Devices
 Block devices include disk drives

Commands include read, write, seek

Raw I/O, direct I/O, or file-system access

Memory-mapped file access possible
 File
mapped to virtual memory
 Clusters

brought via demand paging
DMA
Operating System Concepts Essentials – 2nd Edition
12.30
Silberschatz, Galvin and Gagne ©2013
Block and Character Devices
 Character devices include keyboards, mice, serial
ports, terminals

Commands include get(), put()

Libraries allow line editing
Operating System Concepts Essentials – 2nd Edition
12.31
Silberschatz, Galvin and Gagne ©2013
Network Devices
 Have own interface (not block or character)
 Linux, Windows, etc. include socket interface

Separates network protocol from network operation

Includes select() functionality
 Approaches vary widely

pipes, FIFOs, streams, queues, mailboxes
Operating System Concepts Essentials – 2nd Edition
12.32
Silberschatz, Galvin and Gagne ©2013
Clocks and Timers
 Provide current time, elapsed time, timer
 Normal resolution about 1/60 second

Some systems provide higher-resolution timers
 Programmable interval timer used for timings,
periodic interrupts
Operating System Concepts Essentials – 2nd Edition
12.33
Silberschatz, Galvin and Gagne ©2013
Nonblocking and Asynchronous I/O
 Blocking - process suspended until I/O completes

Easy to use and understand

Insufficient for some needs
Operating System Concepts Essentials – 2nd Edition
12.34
Silberschatz, Galvin and Gagne ©2013
Nonblocking and Asynchronous I/O
 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
Operating System Concepts Essentials – 2nd Edition
12.35
Silberschatz, Galvin and Gagne ©2013
Nonblocking and Asynchronous I/O
 Asynchronous - process runs while I/O executes

Difficult to use

I/O subsystem signals process when I/O completed
Operating System Concepts Essentials – 2nd Edition
12.36
Silberschatz, Galvin and Gagne ©2013
Vectored I/O
 Vectored I/O allows one system call to perform
multiple I/O operations

E.g., UNIX readve() accepts vector of multiple
buffers to read into or write from
 This scatter-gather method better than multiple
(individual) I/O calls

Decreases context switching

Decreases system call overhead

Some versions provide atomicity
Operating System Concepts Essentials – 2nd Edition
12.37
Silberschatz, Galvin and Gagne ©2013
Chapter 12: I/O Systems
 Overview
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Performance
Operating System Concepts Essentials – 2nd Edition
12.38
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Scheduling

I/O request ordering via per-device queue

Some OSs try fairness
Operating System Concepts Essentials – 2nd Edition
12.39
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Buffering - store data in memory while transferring
between devices

Cope with device speed mismatch

Cope with device transfer size mismatch

To maintain “copy semantics”
 Application
 Kernel
writes to kernel buffer
buffer written to disk
Operating System Concepts Essentials – 2nd Edition
12.40
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Double buffering – two copies of data

Kernel and user

Varying sizes

Copy-on-write can be used for efficiency

E.g., network modem, disk, 2 memory buffers
 One
buffer filled by modem
... while other buffer written to disk
Operating System Concepts Essentials – 2nd Edition
12.41
Silberschatz, Galvin and Gagne ©2013
Device-status Table
kernel maintains table of devices + statuses
- each device has own queue...
Operating System Concepts Essentials – 2nd Edition
12.42
Silberschatz, Galvin and Gagne ©2013
Sun Enterprise 6000 Device-Transfer Rates
Operating System Concepts Essentials – 2nd Edition
12.43
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Caching - faster device holds copy of data

Always just a copy

Key to performance

Sometimes combined with buffering
Operating System Concepts Essentials – 2nd Edition
12.44
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Spooling - hold output for device

If device can serve only one request at a time

E.g., printing
Operating System Concepts Essentials – 2nd Edition
12.45
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
 Device reservation - exclusive access to device

System calls for allocation and de-allocation

Watch out for deadlock
Operating System Concepts Essentials – 2nd Edition
12.46
Silberschatz, Galvin and Gagne ©2013
Error Handling
 OS can recover transient failures

E.g., retry read() or write()
 Most systems return an error number or code when
I/O request fails

E.g., errno
 System error logs hold problem reports
Operating System Concepts Essentials – 2nd Edition
12.47
Silberschatz, Galvin and Gagne ©2013
I/O Protection
 User processes may accidentally or purposefully
attempt to disrupt normal operation via illegal I/O
instructions

All I/O instructions defined as privileged

I/O must be performed via system calls
 Memory-mapped
and I/O port memory locations must
be protected too
Operating System Concepts Essentials – 2nd Edition
12.48
Silberschatz, Galvin and Gagne ©2013
UNIX I/O Kernel Structure
Operating System Concepts Essentials – 2nd Edition
12.49
Silberschatz, Galvin and Gagne ©2013
Power Management
 Not strictly domain of I/O, but much is I/O related
 Computers and devices use electricity, generate
heat, frequently require cooling
 OSes can help manage and improve use
 Mobile computing considers power management
as first class OS issue

E.g., Android...
Operating System Concepts Essentials – 2nd Edition
12.50
Silberschatz, Galvin and Gagne ©2013
Android Power Management
 1) Power collapse – put device into deep sleep

Marginal power use

Only awake enough to respond to external stimuli
 button
press
 incoming
call
 etc.
Operating System Concepts Essentials – 2nd Edition
12.51
Silberschatz, Galvin and Gagne ©2013
Android Power Management
 2) Component-level power management

Understands relationship(s) between components

Builds device tree of physical device topology, e.g.,
 System
–

bus
I/O subsystem
»
flash
»
USB storage
Device driver tracks state of device (whether in use)
 Unused
 All
component –> turn off component
devices in tree branch unused –> turn off branch
Operating System Concepts Essentials – 2nd Edition
12.52
Silberschatz, Galvin and Gagne ©2013
Android Power Management
 3) Wake locks –

Prevent sleep of device when lock is held, e.g.,
 website
rendering
 watching
 playing
video
game
 etc.
Operating System Concepts Essentials – 2nd Edition
12.53
Silberschatz, Galvin and Gagne ©2013
Chapter 12: I/O Systems
 Overview
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Performance
Operating System Concepts Essentials – 2nd Edition
12.54
Silberschatz, Galvin and Gagne ©2013
Performance
 I/O is major factor in system performance:

CPU to execute device driver, kernel I/O code

Context switches due to interrupts

Data copying

Network traffic especially stressful
Operating System Concepts Essentials – 2nd Edition
12.55
Silberschatz, Galvin and Gagne ©2013
Improving Performance
 Reduce number of context switches
 Reduce data copying
 Reduce interrupts by using large transfers, smart
controllers, polling
 Use DMA
Operating System Concepts Essentials – 2nd Edition
12.56
Silberschatz, Galvin and Gagne ©2013
Improving Performance (cont.)
 Use smarter hardware devices
 Balance CPU, memory, bus, and I/O performance
for highest throughput
 Move user-mode processes / daemons to kernel
threads
Operating System Concepts Essentials – 2nd Edition
12.57
Silberschatz, Galvin and Gagne ©2013
Device-Functionality Progression
Operating System Concepts Essentials – 2nd Edition
12.58
Silberschatz, Galvin and Gagne ©2013
End of Chapter 13
Operating System Concepts Essentials – 2nd Edition
Silberschatz, Galvin and Gagne ©2013
Download