Chapter 8 I - O System
Chapter 8 I - O System
Sli
de
1
Major components of a computer system:
- CPU
- Memories (primary/secondary),
- I/O system
One of the main functions of OS is to control all I/O devices.
◦ Issue commands
◦ Catch interrupts
◦ Handle errors
◦ Interfacing b/n devices and the rest of the system
◦ handles communication with the devices via their drivers.
Sli
de
2
It keeps track of data, status, location, uses, etc.
It decides which process receives the device when and for how
long.
It improves the performance of specific devices.
It monitors the status of every device, including printers,
storage device, and other devices.
It allocates and effectively locates devices.
Sli
de
3
Interactive systems are often more concerned with I/O than
computing.
I/O devices - vary in many dimensions
◦ Vary widely in functionality and speed
◦ Standard software and hardware interfaces help to
◦ Sequential or random-access
◦ Sharable or dedicated
◦ Speed of operation
◦ read-write, read only, or write only
Incorporate new devices
◦ New devices are constantly introduced
Device driver
◦ Bridge between OS subsystems and I/O devices
◦ Encapsulate device particularities delivering a uniform interface
Sli
de
4
Sli
de
5
Device management in an operating system means controlling
the input/output devices like disk, microphone, keyboard,
printer, magnetic tape, USB ports, camcorder, scanner, other
accessories, etc.
Device controller is used to handle these physical or virtual
devices by the operating system.
Sli
de
6
An operating system manages the devices in a computer
system with the help of device controllers and device
drivers.
Each device in the computer system is equipped with the
help of device controller.
◦ E.g. devices controllers disk controller, printer controller, tape-drive
controller and memory controller.
All these devices’ controllers are connected with each other
through a system bus.
The device controllers are actually the hardware
components that contains some buffers registers to store the
data temporarily.
The transfer of data between a running process and the
various devices of the computer system is accomplished
only through these devices controllers.
Sli
de
7
Sli
de
8
Character-stream devices
◦ printers, keyboards, mice, rats, network interfaces, serial
ports, parallel ports, sounds cards
◦ Commands include get, put
Block devices: handles many characters at once
◦ Raw I/O or file-system access
◦ Memory-mapped file access possible
Hard disks, USB cameras
Commands include read, write, seek
Sli
de
◦ 9
Port
◦ One way of communicating with devices is through registers
associated with each port.
◦ Host connection point for I/O devices
◦ a serial or parallel port.
Bus
◦ Shared set of wires and a protocol that allows several devices
to be simultaneously connected to the host
◦ set of wires connecting multiple devices.
Controller
◦ Controls the operation of ports, buses and devices
◦ From simple electronics to complex processors
◦ Interacts with host through registers
◦ Control the status, data in/out
Sli
de
10
Input/output are performed by the following ways:
1. Programmed I/O- (or “polling” or “busy waiting”) the
CPU must repeatedly poll the device to check if the I/O
request completed.
The host repeatedly checks the busy bit on the device until it
becomes clear.
2. Interrupt-driven I/O- the CPU can switch to other tasks
and is (frequently) interrupted by the I/O device.
Interrupts allow devices to notify the CPU when they have
data to transfer or when an operation is complete, allowing the
CPU to perform other duties when no I/O transfers need its
immediate attention.
◦ It wastes CPU time
Sli
de
11
3. Direct Memory Access (DMA)- the CPU is
involved only at the start and the end of the whole
transfer; it delegates control to the I/O controller that
accesses memory directly without bothering the CPU.
For devices that transfer large quantities of data (
such as disk controllers ), it is wasteful to tie up the
CPU transferring data in and out of registers one byte
at a time. Instead this work can be off-loaded to a
special processor, known as the Direct Memory
Access, DMA.
Sli
de
12
Another technique for communicating with devices is
memory-mapped I/O.
Portions of the memory address space are assigned to
I/O device.
Sli
de
13
Sli
de
14
Goals of I/O Software
Structure of I/O Software
Sli
de
15
Device independence
◦ programs can access any I/O device with different standards
◦ without specifying device in advance
Uniform naming
◦ name of a file or device a string or an integer
◦ not depending on which machine
Error handling
◦ handle as close to the hardware as possible
Sli
de
16
Synchronous vs. asynchronous transfers
◦ blocked transfers vs. interrupt-driven
Buffering
◦ data coming off a device cannot be stored in final destination
Sharable vs. dedicated devices
◦ disks are sharable
◦ printer and tape drives would not be
Sli
de
17
Interrupt handlers
◦ Should be hidden by the operating system
◦ Every process starting an I/O operation should block until I/O has completed and
interrupt occurs
◦ Interrupt handler transfers data from device (controller) and un-blocks process
Device drivers
Contains all device-dependent code
• Handles one type (class) of devices
• Translates abstract requests into device commands
– Writes controller registers
– Accesses mapped memory
– Queues requests
• Driver may block after issuing a request:
– Interrupt will un-block driver (returning status information)
Sli
de
18
Device-independent OS software
◦ Functions of device-independent I/O software:
Uniform interfacing for the device drivers
Device naming AND protection
Storage allocation on block devices
Allocating and releasing dedicated devices
Error reporting
User-level software
◦ System call libraries(read, write,...)
◦ Spooling
–Managing dedicated I/O devices in a multiprogramming system
– Daemon process, spooling directory
Sli
de
19
Sli
de
20
Sli
de
21
kernel provides many services related to I/O.
1. Scheduling
Scheduling I/O requests can greatly improve overall efficiency, fairness, response ,waiting
time, etc.
Some I/O request ordering via per-device queue
- Some OSs try fairness
- E.g. scheduling of disk accesses,
2. Buffering - store data in memory while transferring between devices
• A buffer is a memory area that stores data being transferred between
two devices or between a device and an application.
- To cope with device speed mismatch
- To cope with device transfer size mismatch
3. Caching - fast memory holding copy of data
Always just a copy
Key to performance
Sli
de
22
4. Spooling - hold output for a device
◦ If device can serve only one request at a time
◦ i.e. Printing
5. Error Handling –
Sli
de
23