Professional Documents
Culture Documents
Device
Management
By: Sinodos G.
Introduction
The role of the operating system in computer I/O is to manage and
control I/O operations and I/O devices.
The control of devices connected to the computer is a major
concern of operating-system designers.
Because I/O devices vary so widely in their function and speed
(consider a mouse, a hard disk, and a CD-ROM), varied methods
are needed to control them.
These methods form the I/O subsystem of the kernel, which
separates the rest of the kernel from the complexities of managing
I/O devices.
2
I/O Devices
Devices that engage in I/O with computer systems can be
roughly grouped into three categories:
1. Human readable:
• Suitable for communicating with the computer user.
Ex: Printer, video display, keyboard, mouse, etc.
2. Machine readable:
• Suitable for communicating with electronic equipment.
Ex: Disk drive, controller, etc.
3. Communication:
• Suitable for communicating with remote devices.
Ex: Modem
3
I/O Device Differences
Among the key differences of I/O devices are the following:
• Data rate: There may be differences of several orders of magnitude
between the data transfer rates.
• Application: The use to which a device is put has an influence on
the software and policies in the OS and supporting utilities.
• Complexity of control: A printer requires a relatively simple
control interface whereas a disk is much more complex.
• Unit of transfer: Data may be transferred as a stream of bytes or
characters (e.g., terminal I/O) or in larger blocks (e.g., disk I/O).
• Data representation: Different data encoding schemes are used by
different devices.
• Error conditions: The nature of errors differs widely from one
device to another.
4
Cont’d …
Functions of device manager
• Monitor status of all devices
• Enforce pre-set polices in all devices
• Deals with allocation of devices to process
• Deals with deallocation
• Example: of devices (all input and output devices)
5
Organization of the I/O Function
There are three fundamentally different techniques of I/O performed
to exchange information between user and process.
• Programmed I/O
• Interrupt-driven I/O
• Direct memory access (DMA)
6
Programmed I/O
A technique or approach that we use to transfer data between the
processor and the I/O module.
Used to send and write data from I/O and to store [write] on the
memory using the CPU instruction.
The processor issues an I/O command, on behalf of a process, to an
I/O module; that process then busy waits for the operation to be
completed before proceeding.
8
Cont’d . . .
Objective
• To write data from I/O to memory
• The processor fully dedicates itself in transferring the data
between I/O and memory.
Advantage
• Simple
• It transfers data at a high rate
Disadvantage
• CPU has to wait for I/O module
• it can’t get involved in any other activity during data
transfer.
9
Interrupt-Driven I/O
If the I/O instruction is blocking, then the next instruction that the
processor executes is from the OS, which will put the current process in a
blocked state and schedule another process.
10
Cont’d . . .
11
Direct Memory Access (DMA)
Controls the exchange of data between main memory and an I/O.
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.
The DMA unit is capable of simulating the processor and, indeed, of
taking over control of the system bus just like a processor.
It needs to do this to transfer data to and from memory over the
system bus.
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.
12
Cont’d . . .
13
Device Drivers
There are two types of device drivers. These are:-
Block device:
• Stores information in fixed-size blocks, each one with its own
address.
• Common block sizes range from 512 to 65,536 bytes.
• All transfers are in units of one or more entire (consecutive) blocks.
Ex: Disks
Character device:
• Delivers or accepts a stream of characters, without regard to any
block structure.
• It is not addressable.
Ex: Printer, mouse
14
Buffering
• A buffer is a memory area that stores data being transferred between
two devices or between a device and an application.
15
Disk Structure
16
Disk Structure …
Advantages:-
It is simple, easy to understand and implement.
It does not cause starvation to any request.
Disadvantages:-
It results in increased total seek time.
It is inefficient.
20
Example:-
Example: Assume a disk with 200 cylinders (0-199), and disk queue
with request for I/O to blocks on cylinders 98, 183, 41, 122, 14, 124,
65, 67 in that order.
21
Solution - FCFS
22
Example 2:
Example: Assume a disk with 200 cylinders (0-199), and disk queue with request
for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, 67 in that order.
23
SSTF Scheduling
SSTF stands for Shortest Seek Time First.
services that request next which requires least number of head
movements from its current position regardless of the direction.
It breaks the tie in the direction of head movement.
Advantages-
• It reduces the total seek time as compared to FCFS.
• It provides increased throughput.
• It provides less average response time and waiting time.
Disadvantages-
• There is an overhead of finding out the closest request.
• The requests which are far from the head might starve for the CPU.
• It provides high variance in response time and waiting time.
24
Example:
Consider a disk queue with
requests for I/O to blocks on
cylinders 98, 183, 41, 122,
14, 124, 65, 67.
26
SCAN Scheduling
As the name suggests, this algorithm scans all the cylinders of the
disk back and forth.
Head starts from one end of the disk and move towards the other
end servicing all the requests in between.
After reaching the other end, head reverses its direction and move
towards the starting end servicing all the requests in between.
The same process repeats.
SCAN Algorithm is also called as Elevator Algorithm.
This is because its working resembles the working of an elevator.
27
Advantages-
It is simple, easy to understand and implement.
It does not lead to starvation.
It provides low variance in response time and waiting time.
Disadvantages-
It causes long waiting time for the cylinders just visited by the head.
It causes the head to move till the end of the disk even if there are no
requests to be serviced.
28
Example:
Consider a disk
queue with requests
for I/O to blocks on
cylinders 98, 183,
41, 122, 14, 124, 65,
67. The head is
initially at cylinder Total head movements
number 53 and The = (65 – 53) + (67 – 65) + (98 – 67) +
cylinders are (122 – 98) + (124 – 122) + (183 –
numbered from 0 to 124) + (199 – 183) + (199 – 41) + (41
– 14)
199. Or
= 12 + 2 + 31 + 24 + 2 + 59 + 16 +
find The total head 158 + 27 = (199 – 53) + (199 – 14)
= 331 = 146 + 185
movement SCAN = 331
Algorithm
29
Example 2:
Example: Assume a disk with 200
cylinders (0-199), and disk queue
with request for I/O to blocks on
cylinders 98, 183, 37, 122, 14, 124,
65, 67 in that order.
30
C-SCAN Algorithm
Circular-SCAN Algorithm is an improved version of the SCAN Algorithm.
Head starts from one end of the disk and move towards the other end
servicing all the requests in between.
After reaching the other end, head reverses its direction.
It then returns to the starting end without servicing any request in
between.
The same process repeats.
31
Advantages-
reduce waiting time for the cylinders
It provides uniform waiting time.
It provides better response time.
Disadvantages-
It causes more seek movements as compared to SCAN Algorithm.
It causes the head to move till the end of the disk even if there are no
requests to be serviced.
32
Example
Consider a disk queue with requests for I/O
to blocks on cylinders 98, 183, 41, 122, 14,
124, 65, 67.
The head is initially at cylinder number 53.
The cylinders are numbered from 0 to 199.
33
Question
End of Chapter 4,
Next Chapter 5
34