Two principal types:
1. block devices: stores information in xed size blocks (128 to 1024 bytes). Example:
disks.
:: can read or write blocks independently
:: related is ability to seek
Tape drive: can seek and read, but probably cannot write at arbitrary place.
2. character devices: stream of characters (independent of blocks). Examples:
terminals, line printers, network drivers
:: not addressable
:: no seek operation
Clocks fall outside of this categorization.
Device Controllers
Operating systems do not deal with devices directly. Rather there is a mechanical and
electronic portion. Electronic portion is a device controller. A printed circuit card.
Look at Silbershatz Fig 13.1. Also a network interface card.
Example: CRT controller takes care of details of rescanning the CRT beam
How do controllers and the CPU communicate?
Use memory-mapped I/O
:: CPU puts command in registers (I/O address space) (Silbershatz Fig. 13.2) example
commands: read, write, seek. Also parameters.
:: CPU goes o and does other things.
:: When device done, the controller causes an interrupt. CPU reads any results from
the controller's registers.
Polled I/O
No interrupts used. CPU puts request in controller's registers and then polls waiting for
the request to nish.
Also called programmed I/O.
Might be used for debugging in operating system interrupt handler because it doesn't block.
Direct Memory Access (DMA)
What about large amounts of data to transfer? For example, disk read. Controller gets the
data and bu ers it.
CPU could only get data in small chunks (byte or word at a time).
CPU also gives:
:: memory address (physical, so the page must be tied down)
:: count
Principles of I/O Software
Issues of the software:
:: e ciency|I/O operations are very slow compared to main memory and the CPU.
Want to avoid them being a bottleneck on the system.
:: device independence|programs do not need to know about input or output device.
:: uniform naming|same naming convention regardless of the device. Large systems
typically have multiple disk drives, but user sees a common le space on top. Extend
to a distributed le system.
:: error handling|as close to device as possible, if controller detects an error it ideally
corrects it or rereads (use checksum to detect)
:: synchronous vs. asynchronous|physical I/O is asynchronous (interrupt-driven).
However want to make it appear synchronous (blocking) to the user. Can also use
polled I/O where the device driver continually polls the device (may be used by
kernel to not wait in debugging a device driver).
:: buff ering|may have to bu er data read from a device (such as a packet from
network). However, may end up and copy bu er multiple times.
:: sharable vs. dedicated| le is shared, printer cannot be shared. Operating System
must handle both kinds of devices.
I/O Software Layers
Interrupt Handlers
Bowels of the system. Occurs when a device controller wants to tell CPU something (clock
tick, write done, ready to read more, etc)
What happens on interrupt:
:: Interrupt handler gets invoked.
:: Could send a message to blocked device driver process.
:: On other systems a semaphore is signalled
Device Drivers
Contains device-dependent code. May have a device driver for a class of related devices
(terminal driver for example).
It knows details about device.
device independent request -> device driver -> device dependent request
It may queue up the request if device is already busy. Will send that request when the
current request is complete. Puts data in registers and retrieves results as needed.
Reports results to device-independent software.
Device-Independent I/O Software
Two major functions:
:: perform I/O functions common to all devices
:: provide a uniform interface to the user-level software
:: naming-read/write to terminal using /dev/tty
:: protection-look at le protection (user, group, world)
:: bu ffering-read one byte from disk. Will actually read a block of data and pass one
byte to program. .
User-Space I/O Software
For example, printf() is a library routine that calls write().
Also user-level software to support other operations. Spooling for example where a daemon
process controls access to a spooling directory. When you print, the le is put in the
directory and when your turn comes it is printed.
Also used for le transfer. UUCP networks use this approach.
Typical Computer Input/Output and Storage Devices
Input / Output and Storage Devices
Input Output Storage
Keyboard Monitor Floppy Disk
Mouse Printers (all types) Diskette
Trackballs Audio Card Hard Disk
Touchpads Plotters Disk Cartridge
Pointing Sticks LCD Projection Panels CD-ROM
Joysticks Computer Output Microfilm (COM) Optical Disk
Pen Input Facsimile (FAX) Magnetic Tape
. .
. .
Typical Computer Input/Output and Storage Devices
Input | Output | Storage |
---|---|---|
Keyboard | Monitor | Floppy Disk |
Mouse | Printers (all types) | Diskette |
Trackballs | Audio Card | Hard Disk |
Touchpads | Plotters | Disk Cartridge |
Pointing Sticks | LCD Projection Panels | CD-ROM |
Joysticks | Computer Output Microfilm (COM) | Optical Disk |
Pen Input | Facsimile (FAX) | Magnetic Tape |
. | . | |
. | . |