Download 13. IO Systems

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Burroughs MCP wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

VS/9 wikipedia , lookup

Mobile operating system wikipedia , lookup

Security-focused operating system wikipedia , lookup

DNIX wikipedia , lookup

Spring (operating system) wikipedia , lookup

CP/M wikipedia , lookup

Distributed operating system wikipedia , lookup

Unix security wikipedia , lookup

Transcript
I/O Systems
Electrical and Computer Engineering
Stephen Kim ([email protected])
Operating Systems
1
I/O Systems
n
n
n
n
n
n
I/O Hardware
Application I/O Interface
Kernel I/O Subsystem
Transforming I/O Requests to Hardware
Operations
Streams
Performance
Operating Systems
2
1
I/O Hardware (1)
n
Incredible variety of I/O devices in functions and
speed
u Storage devices – disks, tapes
u Transmission devices – network cards, modem
u human-interface devices – monitor, keyboard,
mouse
u Special devices – sensor, motor
Operating Systems
3
I/O Hardware (2)
n
n
n
Port – connection pointer b/w system and device
eg) serial port
Bus – 2+ devices use a common set of wires
eg) PCI, VME, SCSI (daisy chain)
Controller (host adapter) – electronic operating port, bus, or
a device
u Complication is depending on devices
t serial port controller – mostly embedded into multifunction controller
t SCSI bus controller – mostly built as a separate
circuit board (host adapter)
u Some controller has its own microprocessor and
microcode
Operating Systems
4
2
A Typical PC Bus Structure
Operating Systems
5
Bus
n
n
n
Daisy Chain
u devices are connected in a cascading fashion
u usually operate in a bus
PCI Bus
u to connect memory sub-system to fast devices (monitor,
hard disk)
Expansion Bus
u to connect relatively slow devices such as keyboard
Operating Systems
6
3
Device I/O Port Locations on PCs
(partial)
Operating Systems
7
I/O Hardware (3)
n
How to give commands and data to a controller
u A controller has a set of registers for data and control
signals. A CPU reads or writes data in the registers
u Typical IO registers
t status register
t control register
t data-in register
t data-out register
u Devices have addresses, used by
t Direct I/O instructions – to use special IO
instructions
t Memory- mapped I/O – controller registers are
mapped into the address space of the processor
Operating Systems
8
4
Polling (1)
n
Operation for Data Output
1.
Host repeatedly reads a busy-bit in a controller status
register until that bit becomes clear
2.
Host sets a write-bit in the command register and
writes a byte into data-out register
3.
Host sets the command-ready bit
4.
When the controller notices that the command-ready
bit is set, it sets the busy-bit
5.
Controller reads the command register and see the
write command. It reads the data-out register to get the
byte, and does the I/O to the device
6.
Controller clears the command-ready bit, an error-bit
in the status register
Operating Systems
9
Polling (2)
n
n
Need a buffer to adjust the speeds of consumer and
producer
Inefficient because of the busy waiting
u In multi-task operating systems, it is
recommended not to use the polling, because of
context switch overhead, but not because of the
polling itself
Operating Systems
10
5
Interrupts (1)
n
n
CPU Interrupt request line triggered by I/O device
1.
Device controller raise an interrupt
2.
CPU catches the interrupt and dispatches to the
interrupt handler
3.
The handler clears the interrupt
OS has to support
1.
ability to defer interrupt handling during critical
processing
2.
effective dispatch to a proper handler without polling
all devices
3.
multilevel interrupt for prioritized interrupt handling
Operating Systems
11
Interrupts (2)
n
n
Two Interrupts
u Maskable – to ignore or delay some interrupts
u Non-Maskable – reserved for urgency
Interrupt Chaining
u a small number of interrupt lines, but a large
number of devices
u interrupt vector table contains a pointer to a list
of interrupt handlers, which are called one by
one until a proper handler is found
Operating Systems
12
6
Interrupts (3)
n
n
Interrupt Priority
u CPU delays handling of lower priority interrupts
without masking all interrupts
u A high priority interrupt can preempt a lower
priority interrupt
Other Usages of Interrupt
u Exception handling
u Trap
Operating Systems
13
Intel Pentium Processor Event-Vector
Table
Operating Systems
14
7
Direct Memory Access
n
n
Programmed I/O
u CPU reads or writes 1 byte (or word) at a time
u Inefficient for a large data transfers
DMA
u Used to avoid programmed I/O for large data
movement
u Requires DMA controller
u Bypasses CPU to transfer data directly between
I/O device and memory
Operating Systems
15
Six Step Process to Perform DMA
Transfer
Operating Systems
16
8
Application I/O Interface
n
n
n
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
u Character-stream or block
u Sequential or random-access
u Sharable or dedicated
u Speed of operation
u read-write, read only, or write only
Operating Systems
17
A Kernel I/O Structure
Operating Systems
18
9
Characteristics of I/O Devices
Operating Systems
19
Block and Character Devices
n
Block devices include disk drives
u Commands include read, write, seek
u Raw I/O or file-system access
u Memory-mapped file access possible
n
Character devices include keyboards, mice, serial
ports
u Commands include get, put
u
Libraries layered on top allow line editing
Operating Systems
20
10
Network Devices
n
Varying enough from block and character to have
own interface
n
Unix and Windows include socket interface
u Separates network protocol from network
operation
u Includes select functionality
n
Approaches vary widely (pipes, FIFOs, streams,
queues, mailboxes)
Operating Systems
21
Clocks and Timers
n
Provide current time, elapsed time, timer
n
If programmable interval time used for timings,
periodic interrupts
n
ioctl (on UNIX) covers odd aspects of I/O such
as clocks and timers
Operating Systems
22
11
Blocking and Nonblocking I/O
n
Blocking - process suspended until I/O completed
u Easy to use and understand
u Insufficient for some needs
n
Nonblocking - I/O call returns as much as available
u User interface, data copy (buffered I/O)
u Implemented via multi-threading
u Returns quickly with count of bytes read or written
n
Asynchronous - process runs while I/O executes
u Difficult to use
u I/O subsystem signals process when I/O completed
Operating Systems
23
Kernel I/O Subsystem
n
Scheduling
u Some I/O request ordering via per-device queue
u Some OSs try fairness
n
Buffering - store data in memory while transferring
between devices
u To cope with device speed mismatch
u To cope with device transfer size mismatch
u To maintain “copy semantics”
Operating Systems
24
12
Kernel I/O Subsystem
n
Caching - fast memory holding copy of data
u Always just a copy
u Key to performance
n
Spooling - hold output for a device
u If device can serve only one request at a time
u i.e., Printing
n
Device reservation - provides exclusive access to a device
u System calls for allocation and deallocation
u Watch out for deadlock
Operating Systems
25
Error Handling
n
OS can recover from disk read, device unavailable,
transient write failures
n
Most return an error number or code when I/O
request fails
n
System error logs hold problem reports
Operating Systems
26
13
Kernel Data Structures
n
Kernel keeps state info for I/O components,
including open file tables, network connections,
character device state
n
Many, many complex data structures to track
buffers, memory allocation, “dirty” blocks
n
Some use object-oriented methods and message
passing to implement I/O
Operating Systems
27
UNIX I/O Kernel Structure
Operating Systems
28
14
I/O Requests to Hardware Operations
n
Consider reading a file from disk for a process:
Determine device holding file
u Translate name to device representation
u Physically read data from disk into buffer
u Make data available to requesting process
u Return control to process
u
Operating Systems
29
Life Cycle of An I/O Request
Operating Systems
30
15
Performance
n
I/O a major factor in system performance:
u Demands CPU to execute device driver, kernel
I/O code
u Context switches due to interrupts
u Data copying
u Network traffic especially stressful
Operating Systems
31
Improving Performance
n
n
n
n
n
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
Operating Systems
32
16
Device-Functionality Progression
Operating Systems
33
17