Lecture 33 Schedule for case studies posted Questions? Monday, April 2

advertisement
Lecture 33

Schedule for case studies posted

Questions?
Monday, April 2
CS 470 Operating Systems - Lecture 33
1
Outline

I/O systems

I/O hardware

Application I/O interface

Kernel I/O subsystem

System performance
Monday, April 2
CS 470 Operating Systems - Lecture 33
2
I/O Systems


Main jobs of a computer

Processing

I/O
Often the primary job is I/O with incidental
processing

Web browsing

Document editing
Monday, April 2
CS 470 Operating Systems - Lecture 33
3
I/O Systems

I/O devices are diverse - mouse, disk, monitor so various methods are needed to control them.
Collectively, they are known as the I/O
subsystem that separates the rest of the
kernel form the complexities of managing I/O.
Monday, April 2
CS 470 Operating Systems - Lecture 33
4
I/O Systems

Conflicting trends



Increasing standardization of software/hardware
interfaces makes is easier to incorporate new
devices
I/O devices are becoming more diverse, unlike any
previous devices.
Details and oddities of differing devices are
encapsulated in device drivers that allow the
OS to provide a uniform device-access
interface.
Monday, April 2
CS 470 Operating Systems - Lecture 33
5
I/O Hardware

Not too much detail; covered in CS 320

General categories:


Storage

Transmission

Human interface

Special I/O - sensors, actuators
Communicate with computer via port or bus
Monday, April 2
CS 470 Operating Systems - Lecture 33
6
I/O Hardware

Controller is a piece of electronics that
operates a port, bus, or device.



Sometimes a separate card, e.g. SCSI host
adapter, network interface card
Sometimes built into the device, e.g. disk controller
Communication is through special I/O
commands that write to registers at I/O port
addresses or through memory-mapped I/O.

E.g. PC graphics controller uses I/O ports for basic
operations, but maps screen memory for direct
writes.
Monday, April 2
CS 470 Operating Systems - Lecture 33
7
I/O Hardware

Interaction (or handshaking) between devices is
done through polling or interrupts.


Polling is fast (read, mask, branch on 0), but
wasted processing if event does not happen often.
Interrupts only happen when events happen, but
must have fast dispatch and ability to mask
interrupts for critical sections or higher-priority
interrupts.
Monday, April 2
CS 470 Operating Systems - Lecture 33
8
I/O Hardware

Direct-memory access (DMA) controller is
used to handle large transfers to memory so
that CPU does not have to watch status bits
and/or load data one word at a time.
Monday, April 2
CS 470 Operating Systems - Lecture 33
9
Application I/O Interface


As with other software-engineering problems,
approach is to abstract and encapsulate
behavior. Drivers provide a standardized set of
functions - an interface - for various generic I/O
devices.
Lots of different classes of drivers.
Monday, April 2
CS 470 Operating Systems - Lecture 33
10
Application I/O Interface
Kernel
Kernel I/O Subsystem
EIDE
device
driver
Ethernet
device
driver
USB
device
driver
PCI bus
device
driver
graphics
device
driver
ATAPI
device
driver
...
software
hardware
EIDE
device
controller
Ethernet
device
controller
USB
device
controller
PCI bus
device
controller
graphics
device
controller
ATAPI
device
controller
...
hard disk
network
mouse
keyboard
memory
monitor
CD/DVD
...
Monday, April 2
CS 470 Operating Systems - Lecture 33
11
Application I/O Interface


Unfortunately, each OS has its own standards
for device-driver interface, so many devices
ship with multiple drivers. Or are usable only
with certain OS's
Less so now that many devices use USB for
wired and Bluetooth for wireless interaction.
Monday, April 2
CS 470 Operating Systems - Lecture 33
12
Application I/O Interface

Devices vary on many dimensions





data transfer mode: character (e.g. terminal) vs.
block (e.g. disk)
access method: sequential (e.g. modem) vs.
random (e.g. CD-ROM)
transfer schedule: synchronous (e.g. tape) vs.
asynchronous (e.g. keyboard)
device speed: few bytes/sec (e.g. modem) vs. few
gigabytes/sec (e.g. Ethernet)
I/O direction: read-only (e.g. CD-ROM) vs. writeonly (e.g., monitor) vs. read-write (e.g. disk)
Monday, April 2
CS 470 Operating Systems - Lecture 33
13
Application I/O Interface

Most OS's support several general categories
of devices.


Block devices: read/write/seek operations.
Sometimes raw I/O with direct access to controller.
Sometimes direct I/O with no buffering or locking,
but all other services.
Character streams: single-character get/put
operations. Buffered, concept of a line. Editing is
built on top of these.
Monday, April 2
CS 470 Operating Systems - Lecture 33
14
Application I/O Interface



Network devices use socket interface: create,
bind, connect, listen, accept, select
Clocks and timers: operations to get current time,
get elapsed time, set timer to trigger operation X at
time T. Interface is not standardized. Interrupt
rates are 18-60 ticks/sec. Heavily used by the OS
and real-time applications.
Most OS's have an escape (or backdoor)
command that will pass arbitrary commands to
a device. E.g. Unix ioctl( ) system call.
Monday, April 2
CS 470 Operating Systems - Lecture 33
15
Application I/O Interface


Blocking vs. non-blocking I/O. Most physical
actions are asynchronous, but most system
calls are blocking, since they are easier to
understand and use.
Some user-level processes need non-blocking
I/O to do "simultaneous" I/O operations. E.g.
keyboard and display, or video read and
display.
Monday, April 2
CS 470 Operating Systems - Lecture 33
16
Application I/O Interface

Sometimes there is a difference between nonblocking and asynchronous



Non-blocking: call attempts to perform an
operation and returns in a short amount of time with
indication of how far it got.
Asynchronous: call returns immediately without
waiting for I/O to complete. Notification is given
when operation complete. (Event interrupt.)
Threads can be used to provide simultaneous
execution. E.g., Solaris for user-level
asynchronous I/O
Monday, April 2
CS 470 Operating Systems - Lecture 33
17
Kernel I/O Subsystem

In addition to device drivers, the kernel I/O
subsystem provides several services.



I/O scheduling to increase performance. Also
keeps track of asynchronous requests; same or
separate Wait queue.
Error handling: masks transient failures like disk
skip and network overload by retrying system calls
automatically.
I/O protection: mediates application use of I/O data
structures. E.g. locking for mutual exclusive access
to video memory.
Monday, April 2
CS 470 Operating Systems - Lecture 33
18
Kernel I/O Subsystem


Main service is various uses of memory to
improve performance.
Buffering: memory area devoted to storing
data during transfers. Three reasons:



Cope with speed mismatch. E.g. modem to disk.
Use double buffering so neither side needs to wait.
Adapt between different transfer sizes. E.g. in
networking where messages are large, but packets
are small
Support copy semantics. Write data at time of the
call, even if changed afterwards. E.g. printing files.
Monday, April 2
CS 470 Operating Systems - Lecture 33
19
Kernel I/O Subsystem


Caching: region of fast memory that holds
copies for efficiency. Different than a buffer,
because a buffer may hold the only copy of
data whereas a cache is a copy by definition.
Sometimes buffers also are used as caches.
E.g. disk buffers used for transfers also can be
used to speed up access.
Spooling: a buffer that holds output for a
device that cannot accept interleaved data
streams. E.g. printers. Allows clients not to
have to wait.
Monday, April 2
CS 470 Operating Systems - Lecture 33
20
System Performance


Since most applications spend more time doing
I/O than processing, I/O is a major factor in
system performance.
Requires

rapid context switching

efficient interrupt handling

efficient copying from kernel buffers to application
space
Monday, April 2
CS 470 Operating Systems - Lecture 33
21
System Performance

Principles for improving efficiency include

reduce number of context switches

reduce number of data copies

reduce frequency of interrupts during large transfers



use DMA to allow copying to be concurrent with
CPU execution
move processing primitives into hardware to allow
concurrent execution with CPU and bus
balance CPU, memory, bus, and I/O performance
Monday, April 2
CS 470 Operating Systems - Lecture 33
22
System Performance



Often I/O functionality starts out as part of an
application. It is easier to implement and easier
to debug that way. (Do not have to reboot
device.)
If found generally useful, may be reimplemented as part of the kernel as a driver. If
maximum performance is needed, implement in
the device itself (controller or hardware).
Tradeoff is flexibility and control. Once in the
device, OS has little way to influence behavior.
Monday, April 2
CS 470 Operating Systems - Lecture 33
23
Download