Understanding Operating Systems
Sixth Edition
Chapter 7
Device Management
Device Manager
• manages every peripheral device of the system
• maintain a delicate balance of supply and demand –
balancing the system’s finite supply of devices with
users’ almost infinite demand for them.
Understanding Operating Systems, Sixth Edition
2
Device Manager
• involves four basic functions:
– Monitoring the status of each device, such as
storage drives, printers, and other peripheral devices;
– Enforcing preset policies to determine which
process will get a device and for how long;
– Allocating the devices;
– Deallocating them at two levels:
• At the process (or task) level when an I/O command has
been executed and the device is temporarily released;
• At the job level when the job is finished and the device is
permanently released.
Understanding Operating Systems, Sixth Edition
3
Types of Devices
• The system’s peripheral devices generally fall into
one of three categories:
– Dedicated
– Shared
– Virtual
Understanding Operating Systems, Sixth Edition 4
Types of Devices (cont’d)
• Dedicated Devices
– Are assigned to only one job at a time.
– They serve the job for the entire time the job is active or until it
releases them.
– Some devices demand this kind of allocation scheme, because it
would be awkward to let several users share them.
• Example: tape drives, printers, and plotters
– Disadvantages
• They must be allocated to a single user for the duration of a
job’s execution, which can be quite inefficient, even though
the device is not used 100% of the time.
Understanding Operating Systems, Sixth Edition
5
Types of Devices (cont'd.)
• Shared Devices
– Can be assigned to several processes.
– For example – a disk can be shared by several
processes at the same time by interleaving their
requests;
• This interleaving must be carefully controlled by the
Device Manager
– All conflicts must be resolved based on
predetermined policies.
Understanding Operating Systems, Sixth Edition
6
Types of Devices (cont'd.)
• Virtual Devices
– A combination of the first two types;
– They’re dedicated devices that have been transformed into
shared devices.
• Example: printer, universal serial bus (USB)
– Because disks are shareable devices, this technique can convert
one printer into several virtual printers, thus improving both its
performance and use.
– One USB host (assisted by USB hubs) can accommodate up to 127
different devices.
Understanding Operating Systems, Sixth Edition
7
Types of Devices (cont'd.)
• Virtual Devices
– The USB controller assigns bandwidth to each device
depending on its priority:
» Highest priority is assigned to real-time exchanges
where no interruption in the data flow is allowed such
as video or sound data.
» Medium priority is assigned to devices that can allow
occasional interrupts without jeopardizing the use of
the device, such as a keyboard or joystick.
» Lowest priority is assigned to bulk transfers or
exchanges that can accommodate slower data flow,
such as printers or scanners.
Understanding Operating Systems, Sixth Edition
8
Types of Devices (cont'd.)
• Regardless of the specific attributes of the device, the most
important differences among them are speed and degree of
shareability.
• Storage media are divided into two groups:
– Sequential Access Media
• Store records sequentially, one after the other.
– Direct Access Storage Devices (DASD)
• Can store either sequential or direct access files.
• There are vast differences in their speed and sharability.
Understanding Operating Systems, Sixth Edition 9
Components of the I/O Subsystem
• I/O Channel
– Programmable units placed between the CPU and the control
units.
– Synchronize the fast speed of the CPU with the slow speed of
the I/O devices.
– Make it possible to overlap I/O operations with processor
operations.
• Allows the CPU and the I/O to process concurrently.
– use I/O Channel Programs which controls the transmission of
data between main memory and the control units.
Understanding Operating Systems, Sixth Edition
10
Components of the I/O Subsystem
(cont'd.)
• Disk controller (disk drive interface)
– A special-purpose device used to link the disk drives with the
system bus.
• Disk drive interfaces control the transfer of information between the
disk drives and the rest of the computer system.
• The OS normally deals with the controller, not the device.
Understanding Operating Systems, Sixth Edition
11
Components of the I/O Subsystem
(cont'd.)
• At the start of an I/O command, the information
passed from the CPU to the channel is:
– I/O command (READ, WRITE, REWIND, etc.)
– Channel number
– Address of the physical record to be transferred
(from or to secondary storage).
– Starting address of a memory buffer which or into
which the record is to be transferred.
• Because the channels are as fast as the CPU, each channel can
direct several control units by interleaving commands.
Understanding Operating Systems, Sixth Edition
12
Components of the I/O Subsystem
(cont'd.)
Understanding Operating Systems, Sixth Edition
13
Components of the I/O Subsystem
(cont'd.)
Understanding Operating Systems, Sixth Edition
14
Communication Among Devices
• The Device Manager relies on several auxiliary features to keep
running efficiently under the demanding conditions of a busy
computer system, and there are three problems that must be
resolved:
– It needs to know which components are busy and which are
free.
• Solved by structuring the interaction between units.
– It must be able to accommodate the requests that come in during
heavy I/O traffic.
• Handled by buffering records and queuing requests.
– It must accommodate the disparity of speeds between the CPU
and the I/O devices.
• Handled by buffering records and queuing requests
Understanding Operating Systems, Sixth Edition
15
Communication Among Devices
(cont'd.)
• Each unit in the I/O subsystem can finish its operation independently
from the others.
– After a device has begun writing a record, and before it has
completed the task, the connection between the device and its
control unit can be cut off so the control unit can initiate another
I/O task with another device.
– The CPU is free to process data while I/O is being performed.
• Allows for concurrent processing and I/O.
Understanding Operating Systems, Sixth Edition
16
Communication Among Devices
(cont'd.)
• The success of the operation depends on the system’s ability to
know when a device has completed an operation.
– This is done with a hardware flag that must be tested by the CPU.
• This flag is made up of three bits and resides in the Channel status
word (CSW) which is in a predefined location in main memory and
contains information indicating the status of the channel.
Understanding Operating Systems, Sixth Edition
17
Communication Among Devices
Channel status word (CSW) (cont'd.)
• Channel status word (CSW)
– Each bit represents one of the components of the I/O subsystem:
• Channel
• Control unit
• Device
– Each bit is changed from 0 to 1 to indicate that the unit has
changed from free to busy.
– Each component has access to the flag, which can be tested
before proceeding with the next I/O operation to ensure that the
entire path is free and vice versa.
Understanding Operating Systems, Sixth Edition
18
Communication Among Devices
Channel status word (CSW) (cont’d)
• Channel status word (CSW)
– There are two common ways to perform this flag test:
• Polling
• Interrupts
– Polling uses a special machine instruction to test the flag.
• The CPU periodically tests the channel status bit in the CSW.
• If the channel is still busy, the CPU performs some other
processing task until the test shows that the channel is free;
• Then the channel performs the I/O operation
• Disadvantage:
– If done too frequently, the CPU wastes time testing the flag just
to find out that the channel is still busy.
– If done too seldom, the channel could sit idle for long periods of
time.
Understanding Operating Systems, Sixth Edition
19
Communication Among Devices
(cont'd.)
• The use of Interrupts is a more efficient way to test the flag in the
CSW.
• Instead of having the CPU test the flag, a hardware mechanism
does the test as part of every machine instruction executed by the
CPU.
– If the channel is busy, the flag is set so that execution of the
current sequence of instructions is automatically interrupted and
control is transferred to the interrupt handler.
– Part of the OS and resides in a predefined location in memory.
Understanding Operating Systems, Sixth Edition
20
Communication Among Devices
Interrupts (cont'd.)
• Interrupts
– The interrupt handler’s job is to determine the best course of
action based on the current situation because it’s not unusual for
more than one unit to have caused the I/O interrupt.
– The interrupt handler must:
• Find out which unit sent the signal;
• Analyze its status;
• Restart it when appropriate with the next operation;
• Return control to the interrupted process.
Understanding Operating Systems, Sixth Edition
21
Communication Among Devices
Interrupts (cont'd.)
• Interrupts
– If the CPU is executing the interrupt-handler routine associated
with a given priority, the hardware will automatically intercept all
interrupts at the same or at lower priorities.
– This multiple-priority interrupt system helps improve resource
utilization because each interrupt is handled according to its
relative importance.
Understanding Operating Systems, Sixth Edition
22
Communication Among Devices
(cont'd.)
• Direct memory access (DMA) is an I/O technique that allows a
control unit to directly access main memory.
– Once reading and writing has begun, the remainder of the data
can be transferred to and from memory without CPU
intervention.
• To activate this process, the CPU sends enough information:
– Type of operation (read or write)
– The unit number of the I/O device needed
– The location in memory where data is to be read from or written
to
– The amount of data (bytes or words) to be transferred
Understanding Operating Systems, Sixth Edition
23
Communication Among Devices
(cont'd.)
• The DMA controller sends an interrupt to the CPU to indicate that
the operation is completed.
The DMA controller sends an interrupt o the CPU to indicate that
– This mode theof datais transfer
operation completed. is used for high-speed devices such
as disks. – This mode of data transfer is used for high-speed devices such
as disks.
– Without DMA, the CPU is responsible for the physical movement
– Without DMA, the CPU is responsible for the physical movement
of data between main memory and the relatively slow I/O
devices.
of data between main memory and the relatively slow I/O
• A time-consuming task that results in significant overhead
devices. and decreased CPU utilization.
• A time-consuming task that results in significant overhead
and decreased CPU utilization.
Understanding Operating Systems, Sixth Edition
24
Communication Among Devices
(cont'd.)
• Buffers are used extensively to better synchronize the movement of
data between the relatively slow I/O devices and the very fast CPU.
• Buffers are temporary storage areas residing in three convenient
locations throughout the system:
– Main memory
– Channels
– Control units
• Used to store data read from an input device before it’s needed by
the processor and to store data that will be written to an output
device.
• A typical use of buffers occurs when blocked records are either read
from, or written to, an I/O device.
Understanding Operating Systems, Sixth Edition
25
Communication Among Devices
(cont'd.)
• To minimize the idle time for devices and to maximize their
throughput, the technique of double buffering is used.
– Two buffers are present in main memory, channels, and control
units.
– The objective is to have a record ready to be transferred to or
from memory at any time to avoid any possible delay that might
be caused by waiting for a buffer to fill up with data.
– While one record is being processed by the CPU, another can
be read or written by the channel.
Understanding Operating Systems, Sixth Edition
26
Communication Among Devices
(cont'd.)
Understanding Operating Systems, Sixth Edition
27
Management of I/O Requests
• The Device Manager divides an I/O request into three parts with
each one handled by a specific software component of the I/O
subsystem.
– The I/O traffic controller watches the status of all devices,
control units, and channels.
– The I/O scheduler implements the policies that determine the
allocation of, and access to, the devices, control units, and
channels.
– The I/O device Handler performs the actual transfer of data and
processes the device interrupts.
Understanding Operating Systems, Sixth Edition
28
Management of I/O Requests (cont’d)
• I/O traffic controller
– Monitors the status of every device, control unit, and channel.
– three main tasks:
• It must determine if there’s at least one path available;
• If there’s more than one path available, it must determine
which one to select;
• If the paths are all busy, it must determine when one will
become available.
Understanding Operating Systems, Sixth Edition
29
Management of I/O Requests (cont’d)
• I/O traffic controller
– To do all this, the traffic controller maintains a database
containing the status and connections for each unit in the I/O
subsystem, grouped into:
• Channel Control Blocks
• Control Unit Control Blocks
• Device Control Blocks
– To choose a free path to satisfy an I/O request, the traffic
controller traces backward from the control block of the
requested device through the control units to the channels.
Understanding Operating Systems, Sixth Edition
30
Management of I/O Requests (cont'd.)
Understanding Operating Systems, Sixth Edition
31
Management of I/O Requests (cont'd.)
• I/O scheduler
– Performs the same job as the Process Scheduler.
• Allocates the devices, control units, and channels.
– When the number of requests is greater than the
number of available paths, the I/O scheduler must decide which
request to satisfy first.
– major difference between I/O scheduling and process scheduling
is that I/O requests are not pre-empted
– The I/O scheduler must synchronize its work with the traffic
controller to make sure that a path is available to satisfy the
selected I/O requests.
Understanding Operating Systems, Sixth Edition
32
Management of I/O Requests (cont'd.)
• I/O device handler
– Processes the I/O interrupts;
– Handles error conditions;
– Provides detailed scheduling algorithms which are
extremely device dependent.
– Each type of I/O device has its own device handler
algorithm.
Understanding Operating Systems, Sixth Edition
33
Device Handler
Seek strategy
– It determines the order in which the processes get the device;
– Keeps seek time to a minimum.
Commonly used seek strategies;
– First-come, first-served (FCFS);
– Shortest seek time first (SSTF);
– SCAN (including LOOK, N-Step SCAN, C-SCAN, and C-LOOK).
Every scheduling algorithm should do the following:
– Minimize arm movement;
– Minimize mean response time;
– Minimize the variance in response time.
Understanding Operating Systems, Sixth Edition
34
Device Handler Seek Strategies
(cont'd.)
• First-Come, First-Served (FCFS)
– The simplest device-scheduling algorithm.
– Easy to program and essentially fair to users.
– However, it doesn’t meet any of the three goals of a
seek strategy.
Understanding Operating Systems, Sixth Edition
35
Device Handler
Understanding Operating Systems, Sixth Edition
36
Device Handler
• Shortest Seek Time First (SSTF)
– Uses the same philosophy as Shortest Job Next
– The shortest jobs are processed first and longer jobs are made
to wait.
– The request with the track closest to the one being served is the
next to be satisfied, minimizing overall seek time.
– This algorithm meets the first goal of seek strategies but fails to
meet the other two.
Understanding Operating Systems, Sixth Edition
37
Device Handler
During periods of heavy loads, the
Disadvantage:
arm stays in the center of the disk,
SSTF favors easy-to-reach requests and
where it can satisfy the majority of
postpones traveling to those that are out of
requests easily and it ignores those
the way.
on the outer edges of the disk.
Understanding Operating Systems, Sixth Edition
38
Device Handler
• SCAN
– Uses a directional bit to indicate whether the arm is moving
toward the center of the disk or away from it.
– The algorithm moves the arm methodically from the outer to the
inner track, servicing every request in its path.
– When it reaches the innermost track, it reverses direction and
moves toward the outer tracks, servicing every request in its
path.
Understanding Operating Systems, Sixth Edition
39
Device Handler
• LOOK
– A variation of SCAN.
– The elevator algorithm.
– The arm doesn’t necessarily go all the way to either edge unless
there are requests there.
– It “looks” ahead for a request before going to service it.
Understanding Operating Systems, Sixth Edition
40
Device Handler
Understanding Operating Systems, Sixth Edition
41
Device Handler
• Some broad generalities can be made:
– FCFS works well with light loads;
• As soon as the load grows, service time becomes
unacceptably long.
– SSTF is quite popular and intuitively appealing.
• Works well with moderate loads.
• Has the problem of localization under heavy loads.
– SCAN works well with light to moderate loads.
• Eliminates the problem of indefinite postponement.
• Similar to SSTF in throughput and mean service times.
Understanding Operating Systems, Sixth Edition
42