UMUC CS 412, Sp 97, Input and Output
Silberschat and Gavin chapter 12
Tanenbaum, chapter 5
Outline (in this section we will mostly follow Tanenbaum)
Hardware
I/O Devices
-
Block devices
-
Typically 128 to 1024 Bytes
-
Random access, get any block
-
Disks, CDROM
-
Tapes can be treated this way, but not in the spirit
-
Character devices
-
Stream of characters, no seek operation
-
Terminals, printers, tapes, punch cards, network interfaces, mice (rats?)
-
Robotic controls: sensors and actuators
-
Other types:
-
Clocks
-
Memory mapped screens
Device Controllers
-
Mechanical component - device itself
-
Electronic component - device controller or adapter - printed circuit
card
-
May control more than one device
-
Typically standard: ISO, ANSI, IEEE, etc.
-
Architecture:
-
Bus - micro and mini computers
-
I/O channels - mainframes
-
Disks
-
Looks like serial bit stream at a low level
-
Preamble include cylinder and sector numbers, sector size, and similar
data
-
Disk controller S/W (firmware) to turn bit stream into blocks of data
-
Must also to checksums and error detection, perhaps correction
-
Terminal
-
Put characters on screen
-
Horizontal and vertical retrace signals
-
Controller I/O
-
Memory mapped - rather large sections of memory space are devoted to
various devices or ports
-
IBM PC - I/O addresses and Interrupt vectors
Direct Memory Access (DMA)
-
Typically an option with block oriented devices
-
Data transferred to/from memory directly from/to controller with CPU
involvement
-
CPU starts operation, device interrupts upon completion
-
Provides address and length of data to transfer
-
Data actually transferred to an internal buffer on controller card
-
Because controller must act in real time, sychronized to disk rotation
-
If data not available, controller will terminate operation with an
error
-
Interleaving sectors on disk (see T, page 210, Figure 5-4)
-
Allow time between transfer of sectors for system recovery & error
checking
-
Striping between cylinders and between tracks
Software
Goals of I/O software
-
Device independence
-
Try to program all devices the same way - from the user's and programmer's
point of view
-
UNIX solution - look at everything as a character stream file
-
Uniform naming
-
Identify all devices using similar terminology
-
Error handling
-
Get the lower layers to handle errors - do not bug the users or programmers
if possible
-
Synchronous vs asynchronous transfers
-
Blocking - issue read or write and wait for operation to complete
-
Nonblocking - issue operation and continue, requires interrupts and
interrupt handlers, perhaps polling
-
Sharable vs dedicated devices
-
In a multiuser computer, essentially everything is sharable
-
Viewed as layers:
-
Interrupt handlers
-
Device drivers
-
Device independent operating system software
-
User level software
Interrupt handlers
-
Hide from users and programmers
-
Process can block itself:
-
DOWN on a semaphore
-
WAIT on a condition
-
RECEIVE on a message
-
O/S then sends message to process starting it
Device drivers
-
Each driver handles a class of similar devices
-
Knowledge about the following should stop at device driver level:
-
Number of sectors per track
-
Number of registers and their meaning
-
Arm motion, interleave factors, motor drives, head settling times,
etc.
-
Interface level: get/put block N
-
Queue device operation requests if this makes sense
-
May block or poll
-
Check for errors and try to recover
Device-independent I/O software
-
Functions (See T, page 214, Figure 5-5)
-
Uniform interfacing for device drivers
-
Device naming
-
Device protection
-
Device independent block size
-
Buffering
-
Storage allocation on devices
-
Allocating and releasing dedicated devices
-
Error reporting
User-space I/O software
-
Library procedures
-
formatting
-
putting I/O into lines
-
Spooling - sharing device by taking turns
-
Spooling daemon - only process allowed to write to physical device
-
Spooling directory
-
Applications include printers and network I/O
Disks
-
Key benefits:
-
large storage capacity
-
low price per bit
-
save information when powered off
Hardware
-
heads, cylinders, tracks, sectors
-
Typically, 8 to 32 sectors per track
-
Normally same throughout disk
-
Overlapped seeks are possible if there is more than one disk drive
Arm scheduling algorithms
-
Parameters related to performance:
-
Seek time - moving the arm
-
Rotational delay
-
Data transfer time (rate)
-
If many disk access requests are outstanding, they can be ordered
-
significantly better performance
-
Algorithms:
-
FCFS - first come first served
-
SSF - shortest seek first
-
elevator algorithm - remember which way heads are going
-
switching heads faster than moving heads, so priority to requests in
same cylinder
-
RAID - redundant array of inexpensive disks
-
For example, 38 bits at a time, very fast transfer rate; seek time
still a problem
-
Use error correction coding
Error handling
Some of the more common errors:
-
Programming error
-
Transient checksum error - try again
-
Permanent checksum error - e.g., bad disk block
-
mark block bad,
-
mark file bad
-
reconstruct information through backups or previous versions
-
bad block maps
-
Seek error - arm went to wrong track
-
reset, recalibrate
-
pull arm back to beginning and try again
-
arm tells where it is by using a stepper motor - basic operation is:
move head one track (cylinder) in or out
-
Controller error - card will not accept commands
-
Try reset
-
Try CPU directed reset
-
Try reboot
-
Try new card
Track at a time caching
-
Not available at the device independent layer
RAM disks
-
Use some RAM as a disk drive
-
Convenient for some software operations
Clocks
Hardware
-
Counters
-
line frequency - 50 or 60 Hz
-
independent clock chip, powered by battery; similar to wrist watch
-
CPU clock, bus clock, vertical drive, horizontal drive, etc.
-
Operation
-
load with target count
-
count down
-
interrupt when reaches 0
-
modes: reset to original value and continue or stop
-
interrupt may enabled or disabled
-
Periodic interrupts are called "clock ticks"
-
Maximum period determined by clock being counted and register size
Software
-
Clock driver
-
Duties - vary, but typically:
-
maintain time of day
-
time slice processes
-
time limit processes
-
account for CPU usage
-
ALARM system call from users
-
watchdog timers
-
profiling, monitoring and statistics gathering
-
Maintaining time of day
-
problem is: how big a register?
-
64 bits, seconds since 1/1/70, good until 2038
-
32 bit time of day in seconds, 32 bit number of ticks in current second
-
32 bit counter ticks since boot, 32 bit system boot time in seconds
-
Many interrupts on a single clock -
-
sort and queue interrupts in a linked list,
-
keep track of who requested interrupt
-
Watchdog timers - give some hardware devices time to perform requested
actions
Terminals
Terminal driver should hide differences among terminals, as much as possible
Hardware
-
RS-232 interfaces
-
Hardcopy - on paper (decwriter)
-
screen - 24x80 characters
-
Intelligent - larger character set, reacts to more control signals
-
Blit - memory buffer
-
Memory mapped interface
-
Character oriented
-
bit/pixel oriented
-
vector oriented
Memory-mapped terminals
-
Video RAM
-
switch/load during vertical refresh (v-drive)
-
Video controller
-
takes bytes and generates video control signals
-
200 to 1200 points per line (pixels)
-
200 to 1200 lines per screen, sometimes more
-
colors - red/green/blue
-
LUT's, look up tables
-
refresh rate: 30 to 70 times per second
-
Progressive vs interlaced
-
Character
-
character size (e.g., 9x14 pixels)
-
attributes - blink, reverse, color
-
Keyboards
-
code for each key
-
code for any modifiers (control, shift, caps lock, alt, num lock, etc.)
-
interrupt on depress and another on release
Input software
-
keystroke mode (character oriented, raw mode)
-
all keys actions directly sent to program
-
program must do line editing
-
line mode (line oriented, cooked mode)
-
driver provides programs with a full line of input
-
input not available until user types <cr>
-
type-ahead buffering
-
echoing -
-
local or remote
-
passwords are a problem
-
program writing while user typing?
-
<cr> <lf> problem
-
special characters (to O/S), see T, page 233, Figure 5-18 for example
from UNIX
-
escape character to surpress meaning of special characters (e.g., \)
-
I/O control
-
CTRL-S and CTRL-Q
-
X-ON and X-OFF
-
BREAK
Output software
-
RS-232 terminals
-
Memory mapped (character)
-
write character directly into memory
-
Memory mapped (pixel)
-
go through a drawing package
-
determine and map through font
-
generate glyph in correct location
-
many attributes possible
-
type managers for cross-platform and cross-device operations
-
WSYIWYG - what you see is what you get ?!?!?!
-
Screen control:
-
scrolling
-
cursor position
-
bell
-
Graphical screen control systems:
-
Mac
-
Windows 3.1
-
Windows 95/NT
-
X
-
Others