INPUT/OUTPUT DEVICE MANAGEMENT
One of the functions of the operating system is to control all the computer I/O devices. It must issue
commands to the devices, handle interrupt and handle errors.
OBJECTIVES OF I/O MANAGEMENT
[Link] code independence
The I/O system take responsibility for recognizing different character codes and for representing
data to user graph is standard form.
[Link] independence
A program should be dependent of a particular device over a given time which it happens to be
allocated.
It should not matter in which CD drive a particular disk is inserted or which printer is used for a
programs output.
Service independence of this kind ensures that a program does not fail because a particular
device is broken or located elsewhere.
[Link]
The aims are to have the CPU idling, waiting for a device as little as possible and to a lesser
extent to have all devices working as close to their maximum capacity as possible.
[Link] treatment of device
In the interest of simplicity and freedom from errors its advisable to handle all devices in a
uniform manner.
Categories of I/O Devices
i. Human readable
Used to communicate with the user these include:
Printers, Video display terminals, Display, Keyboard, Mouse
ii. Machine readable
Used to communicate with electronic equipment these include:
Disk and tape drives, Sensors, Controllers, Actuators
[Link]
Used to communicate with remote devices these include:
Digital line drivers, Modems
Page 1 of 11
There are great difference’s across classes and even substantial differences within each class. The
following are among the key differences
i. Data rate
May be differences of several orders of magnitude between the data transfer rates
ii. Application
The use to which a device is put has an influence on the software and policies in the O/S and
supporting utility. Disk used to store files requires file management software. A disk used to
store virtual memory pages needs special hardware and software to support it. Terminal used
by system administrator may have a higher priority than that of a ordinary user.
iii. Complexity of control
A printer requires a relatively simple control interface. A disk is much more complex. The effect
of these differences on the O/S is filtered to some extent by the complexity of the I/O module
the control the devices
iv. Unit of transfer
Data may be transferred as a stream of bytes for a terminal or in larger blocks for a disk
v. Data representation
Different encoding schemes are used by different devices including differences in character code
and parity conversions.
vi. Error conditions
Devices respond to errors differently
Page 2 of 11
Device Controllers
This is a hardware unit attached to the I/O bus and provides a hardware interface between the
computer and the I/O devices itself.
Since it connects to the computer bus, the controller is designed for the purpose of a particular
computer system while at the same time it conforms in interface terms with the requirements
of the actual I/O device.
Device Handlers
Is a process responsible for servicing the request on a device request queue and for notifying
the originating process which the service has been completed. There is a separate handler for
each device but since all handlers operate in a similar way they can make use of sharable
programs
A device handler operates in a continuous cycle during which it removes a request block (RB)
from the request queues initiates the corresponding I/O operations waits for the operation to
be completed and notifies the originating process.
This input complete cycle for an input operation is:
REPEAT
Indefinitely
Wait (request pending);
BEGIN
Pick an RB from request queue;
Extract details of request;
Initiate I/O operation;
Wait (operation complete);
If Error then
Plant error operation:
Translate characters if necessary;
Transfer data to destination;
Signal (request serviced);
Delete RB.
END;
Evolution in I/O organisation
i. Processor controls device directly
ii. A controller or I/O module is used separating the processor from the details of the I/O device
iii. As in 2 but using interrupts, the burden of supervising the device continuously disappears
Page 3 of 11
iv. I/O module gains access to main memory through DMA moving data in and out memory without
processor attention
v. I/O module is enhanced to becomes a separate processor with a specialised instruction set
tailored for I/O. the CPU direct the I/O processor to execute an I/O program in main memory.
The I/O processor fetches these instructions without processor intervention. This allows the
processor to specify a sequence of I/O activities and to be interrupted only when the entire
sequence has been performed
vi. I/O module becomes a computer in its own right. With this architecture a large set of I/O
devices can be controlled with minimal processor involvement
ORGANIZATION OF THE I/O FUNCTION
There are three techniques of Performing I/O
i. Programmed I/O
The processor issues on I/O command, on behalf of the process, to an I/O module; then busy
waits for the operation to be completed before proceeding.
Page 4 of 11
ii. Interrupt-driven I/O
The processor issues an I/O command on behalf of a process, it continues to execute
subsequent instructions, and is interrupted by an I/O module when the latter has completed its
work.
iii. Direct Memory Access (DMA)
A DMA module controls the exchange of data between main memory and a module. The
processor sends a request for the transfer of a block of data to the DMA module and is
interrupted only after the entire block has been transferred.
Page 5 of 11
The DMA technique works as follows:-
When the processor wishes to read or write a block of data it issues a command to the DMA
module by sending to the DMA module the following;
i. Whether a read or write is requested using the R/W control line between the processor
and the DMA module.
ii. The address of the I/O involved communicates on the data line.
iii. The starting location in memory to read from or write to communicated on the data
lines and stored by the DMA module it as address register.
iv. The number of words to be read or written again communicates via the data lines and
stored in the data count register.
The processor then continues with other work. Processor delegates I/O operation to the DMA module.
The DMA module transfers data directly to or form memory without going through the processor. When
the transfer is complete the DMA module sends an interrupt signal to the processor thus the processor
is involved only at the beginning and end of the transfer.
DMA mechanism can be configured in a variety of way fig 11.3
a) All modules share the same system bus. The DMA module, acting as a deputy processor, uses
programmed I/O to exchange data between memory and I/O module through the DMA module.
This configuration is inexpensive but very inefficient:
b) As with processor controlled programmed I/O, each transfer of a word consumes two bus cycles
(transfer request followed by transfer). The number of required bus cycles can be cut
substantially by integrating the DMA and I/O functions. This means that there is a path between
the DMA module and one or more I/O modules that does not include the system bus. The DMA
logic may actually be a part of an I/O module, or it may be a separate module that controls one
or more I/O modules.
c) The above mechanism can be taken one step further by connecting I/O modules to the DMA
module using an I/O bus. This reduces the number of I/O interfaces in the DMA module to one
and provides for an easily expandable configuration.
Page 6 of 11
NB: In mechanism b and c above and in figure b and c below, the system bus that the DMA module
shares with the processor and main memory is used by the DMA module only to exchange data with
memory and to exchange control signals with the processor. The exchange of data between the DMA
and I/O modules takes place off the system bus.
Figure 11.3
Direct Memory Access procedure:
a. Processor sends message to DMA (R/W, where, how much)
b. Processor continues while I/O proceeds
c. At the end, I/O module sends interrupt signal to the processor
OPERATING SYSTEM DESIGN ISSUES
Design Objectives
i. Efficiency
Most I/O devices extremely slow compared to main memory. The use of multiprogramming
allows for some processes to be waiting on I/O while another process executes. I/O cannot keep
up with processor speed thus swapping is used to bring in additional Ready processes which is
an I/O operation
ii. Generality
It’s desirable to handle all I/O devices in a uniform manner. This statement applies both to the way in
which processes view I/O devices and the way in which the operating system manages I/O devices and
operations. It’s important to hide most of the details of device I/O in lower-level routines so that
processes and upper levels see devices in general terms such as read, write, open, close, lock, unlock etc
Page 7 of 11
Interrupt Handler
The best way to handle interrupts is to have entry process starting I/O operation blocked until
the I/O completed then interrupt occurs. The process can block itself by a down semaphore a
wait on a condition variable or recur on a message e.g. when the interrupt happens the
procedure does whatever it has to do in order to unblock the process that started it.
Device Drivers
This is an operating system module (usually in the kernel) that deals directly with a device or I/O
module
Device independence I/O software
Its basic function is to perform the I/O functions that are common to all devices to provide a
uniform interface to user level software.
Functions of device independence I/O software
i. Uniform interfacing device drive
ii. Device naming
iii. Device protection
iv. Buffering
v. Storage allocating on block devices
vi. Errors reporting
vii. Providing a device independent block size
User Specific I/O Software
This is a small portion which consists of libraries linked together with users, programs and even
whole programs running outside OS Kernel.
DISK AND DISK OPERATIONS
Physical disk organization
Page 8 of 11
Disk Performance Parameters
To read or write, the disk head must be positioned at the desired track and at the beginning of the
desired sector
Seek time
Time it takes to position the head at the desired track
Rotational delay or rotational latency
Time its takes for the beginning of the sector to reach the head
Timing of a Disk I/O Transfer
Page 9 of 11
Access time
Access time is = seek time: time needed to move the arm to the cylinder (dominant)
+ Rotational delay: time before the sector appears under the head
+ Transfer time: time to transfer the data
Seek time is the reason for differences in performance. For a single disk there will be a number of I/O
requests. If requests are selected randomly, we will poor performance
Disk Scheduling Policies
i. First-in, first-out (FIFO)
Process request sequentially. Fair to all processes. Approaches random scheduling in performance if
there are many processes
Priority
Goal is not to optimize disk use but to meet other objectives. Short batch jobs may have higher priority.
Provide good interactive response time
Page 10 of 11
ii. Last-in, first-out
Good for transaction processing systems
The device is given to the most recent user so there should be little arm movement
Possibility of starvation since a job may never regain the head of the line
iii. Last-in, first-out
Good for transaction processing systems
The device is given to the most recent user so there should be little arm movement
Possibility of starvation since a job may never regain the head of the line
iv. Shortest Service Time First
Select the disk I/O request that requires the least movement of the disk arm from its current position
Always choose the minimum Seek time
v. PRI
PRIority given to requests, based on process class (interactive, batch, etc.), This scheduling largely
outside of disk management control. Its goal is not to optimize disk use but to meet other objectives
Short batch jobs may have higher priority. This provides good interactive response time
Page 11 of 11