You are on page 1of 10

Chapter Four: Device management

Chapter Four

4. Device management
Os manages device communication via their respective drivers. device management
implies the management of I/O devices. There are four main functions of the device
manager
 Monitor the status of all devices. The program responsible for this task is I/O controller.
 Decides which process gets the device when and for how much time/for how long.
 Deal with the allocation of devices to processes
 Deal with the de-allocation of devices to processes

Examples of devices

• Keyboard

• Mouse

• Monitor

• Scanner

• CD-ROM

• USB ports

• Disk

• Printer

• microphone

• Analog-to-Digital converter (ADC)

• Digital-to-Analog converter (DAC) etc.

4.1 Types of devices

Dedicated devices
 These are devices that are assigned to one process at a time and the process only releases
the device once it is completed. This makes sense for devices like plotters, and tape
drivers. The problem with this is that it means only one user is using it at a time, and it
maight be inefficient if the device isn’t being used 100% of the time that it is being
locked by the user.

Operating System Page 1


Chapter Four: Device management

Shared devices
 These are devices that can be shared between several processes. Considering an example
like a hard disk, it is shared but interleaving between different processes requests.

All conflicts for device need to be resolved but pre-determined polices to decide which request is
handled first.

Virtual devices
 These are devices are combination of dedicated and shared devices. So a printer is d
dedicated device but using spooling(queues) means it can be shared.

Spooling: Suppose we have a printer connected to a machine. Many users may seek to
use the printer. To avoid print clashes, it is important to be able to queue up all the print
requests. This is achieved by spooling.

A print job isn’t sent straight to the printer ,instead it goes to the disk (spool) until it is fully
prepared with all the necessary printer sequences and formatting then it goes to the printer
,ensuring that the printers (and all I/O devices) are used efficiently.

4.2 I/O Devices

I/O is important for communication between the user and computer. The following are functions
of the operating system as I/O manager:

Control all the computer I/O devices


Issue commands to I/O devices catch interrupts and handle errors
Provide an interface between the device and the rest of the system
4.2.1 Principles of I/O hardware
I/O devices: - concerns with the way data are handled by the I/O device. There are two types of
I/O devices – Blocked devices (such as disks) and character devices (such as printers, mouse
and NIC)
 Block devices: work on data of fixed size blocks with each block having a unique
address, hence, are randomly accessible. can be defined as one that stores information in
fixed-size blocks, each one with its own address. It transfers blocks of data at a time.

Example: disks
 Character devices: process stream of characters without any block structure. Delivers or
accepts a stream of characters, without regard to any block structure. It transfer single
character at a time.
Example: printers, network interfaces, mice, keyboards.
I/O Unit: indicates the hardware components. There are two major components – Electronic
Component (Adapter/device controller) and the Mechanical Component (the moving parts)

A controller has an interface into which a cable that connects its device is plugged in. Each
controller has a few registers for communication with the operating system. Besides registers,

Operating System Page 2


Chapter Four: Device management

some devices have data buffer on which programs and the operating system can read/write data.
For the CPU to communicate with device controllers, each device must have a unique ID.

4.2.2 Principles of I/O software


 Layered technique is used
 Goals and issues of I/O software are :
Device Independence: It should be possible to write programs that can read files on a floppy
disk, on hard disk, or on a CD-ROM, without having to modify the program for each different
device types. It is up to the operating system to take care of the problems caused by the fact
that these devices are really different.
Uniform Naming: the name of a file or a device should simply be a string or an integer and
not dependent on the device in any way.
Error handling: In general, errors should be handled as close to the hardware as possible (at
the device controller level). Many errors are transient, such as read errors caused by specks of
dust on the read head, and will go away if the operations are repeated.
Transfer: There are two types of transfer modes – Synchronous (Blocking) and
Asynchronous (interrupt –driven). In the case of synchronous transfer the program
requesting I/O transfer will be suspended until the transfer is completed. In the case of
Asynchronous transfer the CPU starts the transfer and goes off to do something until the
interrupt that shows the completion of the transfer arrives.

4.2.2.1 Layers of I/O software


The following are the I/O software layers
 Interrupt handler (bottom)
 Device driver
 Device independent OS software
 User-level software (top)
1. Interrupt Handler
– Interrupts should be hidden
– The best way to hide them is to have every process starting an I/O operation block until
the I/O has completed and the interrupt occurs.
– When the interrupt happens, the interrupt procedure does whatever it has to in order to
unblock the process that started it.
2. Device Driver
– All device – dependent code goes in the device driver
– Each device driver handles one device type, or at most, one class of closely relate
devices.
– The device drivers issue the commands and check that they are carried out properly.
– Thus, the disk driver is the only part of the OS that knows how many registers that disk
controller has and what they are used for.
– In general terms, the job of a device driver is to accept requests from the device
independent software above it and sees to it that the request is executed.
3. Device Independent I/O Software
– It is large fraction of I/O software
– Functions of the device-independent I/O software
 Uniform interfacing for device drivers – perform I/O function common to all drives

Operating System Page 3


Chapter Four: Device management

 Device Naming – responsible for mapping symbolic devices names onto the proper
driver
 Device protection – prevent users from accessing devices that they are not entitled to
access
 Buffering: if a user process write half a block, the OS will normally keep the data in
buffer until the rest of the data are written. Keyboard inputs that arrive before it is needed
also require buffering.
 Storage allocation on block devices: when a file is created and filled with data, new
disk blocks have to be allocated to the file. To perform this allocation, the OS needs a list
of free blocks and used some algorithms for allocation
 Allocating and releasing dedicated devices: It is up to the OS to examine requests for
devices usage and accept or reject them.
 Error reporting: Errors handling, by and large, is done by drivers. Most errors are
device dependent. After the driver tries to read the block a certain number of times, it
gives up and informs the device-independent software. It then reports to the caller.
4. User Space I/O Software
 A small portion of the I/O software is outside the OS
 System calls, including the I/O system calls, are normally made by library procedures
 Formatting of input and output is done by library procedures

• A small portion of I/O software that is consists of libraries linked together with user
programs, and even whole programs running outside the kernel.

The following figure shows the I/O system layers and the main functions of each layer

4.3 Disk Arm Scheduling


 All real disks are organized into cylinders, each one containing as many tracks as there are
heads stacked vertically
 Each of the tracks then will be divided into sectors (equal number of sectors or different
number of sectors)
 In the case of equal number of sectors
 The data density as closer to the center (hub) is high
 The speed increases as the read/write moves to the outer tracks
 Modern large hard drives have more sectors per track on outer tracks e.g. IDE drives
 Many controllers can read or write on one drive while seeking on one or more other drives,
but floppy disk controller cannot do that.

Operating System Page 4


Chapter Four: Device management

Disk Access Time


The time required to read or write a disk block is determined mainly by the following three
parameters:
 Seek time (the time to move the arm to the proper cylinder)
 Rotational delay (the time to rotate the disk and position the required sector under the
read/write head)
 Actual data transfer time
For most disks seek time is the most dominant time. Reducing the seek time can improve system
performance. Many disk controller drivers maintain a table of requests indexed by cylinder
number.
Under these circumstances, some possible disk scheduling algorithms to reduce the average seek
time are:
 First-Come, First-Served (FCFS): the disk requests are served in the order they arrive.
The response time is poor.
We illustrate this with a request queue (0-199):
98, 183, 37, 122, 14, 124, 65, 67
Consider now the Head pointer is in cylinder 53.

 Shortest Seek First (SSF): the next cylinder to be accessed is the nearest to the current
one. This algorithm minimizes average seek time but cylinders at the extreme locations
suffers long waits since most requests tend to cylinders near the middle. Thus, minimal
response time compromises fairness. Figure 4.8 illustrates shortest seek first disk
scheduling algorithm.

Figure: Shortest seek first (SSF) disk scheduling algorithm

Operating System Page 5


Chapter Four: Device management

We illustrate this with a request queue (0-199):


98, 183, 37, 122, 14, 124, 65, 67
Consider now the Head pointer is in cylinder 53.

 Elevator Algorithm: the next cylinder to be accessed is determined by the direction of


search. If the current direction is toward the outer cylinders, the next cylinder is one with
the next higher number. If the direction is downward, the next cylinder is one with the
next smaller number. The search direction is reversed when there are no more requests in
the current direction. In general, the average seek time of the elevator algorithm is higher
than that of SSF, but has better fairness. Figure 4.9 shows the elevator disk scheduling
algorithm assuming that the search direction is toward the outer cylinders.

Figure: The elevator algorithm disk scheduling algorithm

Operating System Page 6


Chapter Four: Device management

4.4 Abstracting Device differences

• Many devices have common characteristics; e.g., different brands of disk or printer

• Makes sense to abstract common parts

• Resulting structure is uniform driver sitting above specific one

4.5 Buffering and buffering strategies

 Buffers are temporary storage areas residing in convenient locations throughout system:
main memory, channels, and control units. Used extensively to better synchronize
movement of data between relatively slow I/O devices & very fast CPU.
 A buffer is a memory area that stores data while they are transferred between two
devices or between a device and an application. It overlaps the input/output of one job with
the execution of the same job.
 Buffering is done for three reasons:

• To cope with a speed mismatch between the producer and consumer and
consumer of a data stream.

• To adapt between devices that have different data-transfer sizes.

Operating System Page 7


Chapter Four: Device management

• To support copy semantics for application I/O.

4.5.1 Buffering Strategies

Double buffering – two buffers taking turns: while one is being copied to user space, the
other is accumulating new input.
Double Buffer
 Use two system buffers instead of one
 A process can transfer data to or from one buffer while the operating system
empties or fills the other buffer

Circular buffering – has a region of memory and two pointers. One pointer points to the
next free word, where new data can be placed. The other pointer points to the first word
of data in the buffer that has not been removed yet.

Circular Buffer
• More than two buffers are used
• Each individual buffer is one unit in a circular buffer
• Used when I/O operation must keep up with Process

4.6 Direct Memory Access

The direct memory access (DMA) I/O technique provides direct access to the memory while the
microprocessor is temporarily disabled.
I/O devices are connected to system bus via a special interference circuit known as DMA
controller.
In DMA, both CPU and DMA controller have access to main memory via a shared system bus
having data, address and control lines.
It is sometimes referred to as a channel. In an alternative configuration, the DMA controller may
be incorporated directly into the I/O device.

Operating System Page 8


Chapter Four: Device management

• CPU needs to address the device controllers to exchange data with them.

• DMA controller has access to the system bus independent of the CPU.

• It contains several registers that can be written and read by the CPU.

• The control registers specify the I/O port to use, the direction of the transfer (read or
write to I/O), transfer unit (byte or word), and the number of bytes to transfer in one
burst.

Why DMA

 An important aspect of governing the computer system performance of data b/n memory
and I/O devices. The operation involves loading programs or data files from disk into
memory, saving file on disk, and accessing virtual memory pages on any secondary
storage medium.
 The process would be much quicker if we could bypass the CPU and transfer data
directly from the I/O device to memory. Direct memory access does exactly that
 During DMA transfer, the CPU is idle and no control of the memory buses.

DMA mode

• Cycle stealing – the device controller sneaks in and steals an occasional bus cycle from
the CPU once in a while, delaying it slightly (word-at-a-time).

Operating System Page 9


Chapter Four: Device management

• Burst mode – DMA controller tells the device to acquire the bus, issues a series of
transfers, then release the bus (block).

• Fly-by mode – DMA controller tells the device controller to transfer the data directly to
main memory.

Advantages of DMA

 DMA allows a peripheral device to read from/write to memory without going through the
CPU.
 DMA allows for faster processing since the processor can be working on something else
while the peripheral can be population memory.

Disadvantages of DMA

 DMA transfer requires a DMA controller to carry out the operation, hence cost of the
system increases.
 Leads to Cache coherence problems.

Operating System Page 10

You might also like