Download Systems - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity! I/O Systems Chapter 13 Docsity.com I/O Systems • I/O Hardware • Application I/O Interface • Kernel I/O Subsystem • Transforming I/O Requests to Hardware Operations • Streams • Performance Docsity.com A Typical PC Bus Structure
Gist
s||-Ge
a re
monitor processor a
cache
pea ea f— memory SCSI controller
IDE disk controller expansion bus keyboard
interface
(ask) Gist) parallel serial
port port
Docsity.com
Device |/O Port Locations on PCs (partial)
I/O address range (hexadecimal) device
000-—00F DMA controller
020-021 interrupt controller
040-043 timer
200-20F game controller
2F8—2FF serial port (secondary)
320-32F hard-disk controller
378-37F parallel port
3D0-3DF graphics controller
3FO-3F7 diskette-drive controller
3F8—3FF serial port (primary)
Docsity.com
Polling • Determines state of device – command-ready – busy – Error • Busy-wait cycle to wait for I/O from device Docsity.com Intel Pentium Processor Event-Vector Table
vector number
description
(Coy DC) eco) no
(Oo Op) On) eS co) nS) =) co)
19-31
32-255
divide error
debug exception
null interrupt
breakpoint
INTO-detected overflow
bound range exception
invalid opcode
device not available
double fault
coprocessor segment overrun (reserved)
invalid task state segment
segment not present
stack fault
general protection
page fault
(Intel reserved, do not use)
floating-point error
alignment check
machine check
(Intel reserved, do not use)
maskable interrupts
Docsity.com
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 Docsity.com Six Step Process to Perform DMA Transfer
1. device driver is told
to transfer disk data
to buffer at address X
. DMA controller 2. device driver tells
transfers bytes to disk controller to
buffer X, increasing transfer C bytes
memory address from disk to buffer
and decreasing C at address X
until C = 0
. when C = 0, DMA
interrupts CPU to signal
transfer completion
DMA/bus/
interrupt
controller
x
memory
IDE disk
controller
3. disk controller initiates
DMA transfer
4. disk controller sends
e¢
disk} (disk)
each byte to DMA
controller
Docsity.com
Characteristics of |/O Devices
aspect variation example
RR raneiennnacie character terminal
block disk
sequential modem
access method ae CD-ROM
transfer schedule eee ae
asynchronous keyboard
hatin dedicated tape
g sharable keyboard
device speed latency
seek time
transfer rate
delay between operations
read only CD-ROM
\/O direction write only graphics controller
read-write disk
Docsity.com
Block 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 – Libraries layered on top allow line editing Docsity.com Network Devices • Varying enough from block and character to have own interface • Unix and Windows NT/9x/2000 include socket interface – Separates network protocol from network operation – Includes select functionality • Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) Docsity.com Two I/O Methods
requesting process
waiting A
,fequesting process |
device driver
device driver
interrupt handler
i
interrupt handler
Tt
hardware
i— data transfer —
hardware
--data transfer —Ct
time —»
Synchronous
time ————>
Asynchronous
Docsity.com
Kernel I/O Subsystem • Scheduling – Some I/O request ordering via per-device queue – Some OSs try fairness • 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” Docsity.com Device-status Table
device: keyboard
status: idle
device: laser printer
status: busy
device: mouse
status: idle
device: disk unit 1
status: idle
request for
> laser printer
address: 38546
length: 1372
device: disk unit 2
status: busy
request for
disk unit 2
file: xxx
operation: read
address: 43046
length: 20000
request for
disk unit 2
file: yyy
operation: write
address: 03458
length: 500
Docsity.com
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 Docsity.com I/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 Docsity.com Use of a System Call to Perform |/O
system call n
©
to
Docsity.com
I/O Requests to Hardware Operations • 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 Docsity.com request iO
systom call
<n cai,
ae
yes
send request to deviee
driver, block process if
appropriate
I
process request, issue
commands to controller,
configure contrcller to
book url interrupted
deviee-contioller commands
monitor device,
interrupt when /O
completed
user
process
kernel
VO subsystem
kernel
VO subsystem
device
driver
interrupt
handler
device
controller
Life Cycle of An I/O Request
VO completed
Input data available, or
coutout completed
retum from system call
transfer data
(if appropriate) to procass,
retum completion
of error code
determine which VO
completed, incicate siate
chiang to VO subsysiet
receive interrupt, store
data in device-driver butter
it input, signal to unblock
device driver
interrupt
time
VO completed
generate interrupt
Docsity.com
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. • Each module contains a read queue and a write queue • Message passing is used to communicate between queues Docsity.com Intercomputer Communications
—— —
character — network
typed system call packet
| received
—
ale 3/8 zie
sls 3 ae
£2 8|3 £(=
interrupt interrupt network
generated handled adapter
fig 2/¢
s
=|5 o|8
interrupt interrupt interrupt
handled generated generated
A___
network is
eaetworkcas fis
a5
device network device
driver adapter driver
Rernel device rerael network
driver lsubdaemon
a\s a\s 8/s
Ea =/= —\s
gla Al ae
context context
kernel network kernel
BeGeea| switch aemon | ewitch
sending system receiving system
Docsity.com
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 Docsity.com Device-Functionality Progression
new algorithm
w
velopment cost
abstraction
application code
kernel code
device-driver code
device-controller code (hardware)
increased flexibili
device code (hardware)
Docsity.com