Device Management in Operating Systems
Device Management in Operating Systems
System
Tim Pengampu MK Sistem Operasi
Universitas Dian Nuswantoro
Device (I/O) Management
Device Management : the OS component that manages hardware
devices with 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.
Device (I/O) Management
• Characteristics
Device (I/O) Management
• Device Categories
• Dedicated
• Are assigned to only one job at a time.
• They serve that 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.
• Shared
• Can be assigned to several processes.
• For example – a disk (DASD – Direct Access Storage Device) 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.
• Virtual
• A combination of the first two types.
• They’re dedicated devices that have been transformed into shared devices.
• Example : printer
• Converted into a shareable device through a spooling program that reroutes all print
requests to a disk.
• Only when all of a job’s output is complete, and the printer is ready to print out the entire
document, is the output sent to the printer for printing.
• Because disks are shareable devices, this technique can convert one printer into several virtual
printers, thus improving both its performance and use.
Device Addressing
• How the CPU addresses the device registers?
• Two approaches
• Dedicated range of device addresses in the physical
memory
• Requires special hardware instructions associated
with individual devices
• Memory-mapped I/O: makes no distinction
between device addresses and memory addresses
• Devices can be accessed the same way as normal
memory, with the same set of hardware
instructions
Device Addressing Illustrated
Primary Primary
memory memory Memory
addresses
Device Device 1
addresses Device 2
Separate device Memory-mapped I/Os
addresses
Device (I/O) Management
• Approaches (Way to Access a Device)
• Direct I/O – CPU software explicitly transfer data to and from the controller’s data registers
• Direct I/O with polling – the device management software polls the device controller
status register to detect completion of the operation; device management is
implemented wholly in the device driver, if interrupts are not used
• Memory mapped I/O – device addressing simplifies the interface (device seen as a range of
memory locations)
• Memory mapped I/O with polling – the device management software polls the device
controller status register to detect completion of the operation; device management is
implemented wholly in the device driver.
• Interrupt driven direct I/O – interrupts simplify the software’s responsibility for detecting
operation completion; device management is implemented through the interaction of a
device driver and interrupt routine
• Direct memory access – involves designing of hardware to avoid the CPU perform the
transfer of information between the device (controller’s data registers) and the memory
Device (I/O) Management
• Direct I/O versus Memory Mapped I/O
data
1. Application process requests a read operation
2. The device driver queries the CSR to determine
whether de device is idle; if device is busy, the
driver waits for it to become idle
System Interface
3. The driver stores an input command into the
controller’s command register, thus starting the read function
2
Data transfer
device 3
4. The driver repeatedly reads the content of CSR 4 5
to detect the completion of the read operation write function
5. The driver copies the content of the controller's
data register(s) into the main memory user’s
process’s space.
Hardware interface
Data transfer
controller’s data register(s) 3
4. The driver stores an output command write function
into the command register, thus 4
2
starting the device 5
5. The driver repeatedly reads the CSR
to determine when the device Hardware interface
completed its operation
command status data
Device controller
Ways to Access a Device
• How to input and output data to and from an
I/O device?
data
9
8b
System Interface
Data transfer
3 4
7 Device
handler
write function
…
6
Interrupt
5
handler
Hardware interface
8a
1298a,
76354 -– the
8b
the
when –driver
application
device
interrupt
device
the
thisdevice
stores
part
driver
completes
driver
handler
handler
of
process
driver
an
queries
retrieves
the
returns
input
determines
device
the
copies
requests
the
command
operation
thedriver
CSR
the
control
pending
awhich
content
read
tocompletes
and
into
find
tooperation
I/O
device
interrupts
the
the
out
ofstatus
controller’s
the
application
ifits
caused
the
controller’s
work,
information
the
device
CPU,
the
it is
idle; savesregister(s)
therefore
command
interrupt;
from
data
processifthe
information
busy,
(knowing
device
causing
itregister,
then
then
into
status
branches
it
an
the
regarding
thus
waits
the
interrupt
return
table
user
starting
until
to process’s
address
the
the
handler
the
the
operation
device
device
device
from
space
tohandler
run
becomes
the
it began
device
forinidle
that
status
thedevice
device
table)
status table; this table contains an entry for each device in system
Ways to Access a Device
• Interrupt-driven I/Os: A device controller
notifies the corresponding device driver
when the device is available
+ More efficient use of CPU cycles
- Data copying and movements
- Slow for character devices (i.e., one
interrupt per keyboard input)
Ways to Access a Device
Primary • Direct Memory Access (DMA)
memory • Traditional I/O
• Polling approach:
• CPU transfer data between the controller
data registers and the primary memory
• Output operations - device driver copies data
from the application process data area to the
CPU controller; vice versa for input operations
• Interrupt driven I/O approach - the interrupt
handler is responsible for the transfer task
Controller
Device
Ways to Access a Device
• DMA controllers are able to read and write
Primary
information directly from /to primary memory, with memory
no software intervention
Device
Ways to Access a Device
• Direct memory access (DMA): uses an
additional controller to perform data
movements
+ CPU is not involved in copying data
- I/O device is much more complicated
(need to have the ability to access
memory).
- A process cannot access in-transit data
Ways to Access a Device
• Double buffering: uses two buffers.
While one is being used, the other is
being filled.
• Analogy: pipelining
• Extensively used for graphics and
animation
• So a viewer does not see the line-by-
line scanning
Device (I/O) Management
• Device Driver
• An OS component that is responsible for hiding the complexity of an I/O device
• So that the OS can access various devices in a uniform manner
• Two categories
• A block device stores information in fixed-size blocks, each one with its own
address
• e.g., disks
• A character device delivers or accepts a stream of characters, and individual
characters are not addressable
• e.g., keyboards, printers, network cards
7
6
5
4
Tracks
3
2
1
Time
0
Shortest Seek Time First (SSTF) Device
Scheduling Algorithm
• Uses same underlying philosophy as shortest job next where
shortest jobs are processed first & longer jobs wait.
• Request with track closest to one being served (that is, one with
shortest distance to travel) is next to be satisfied.
7
6
5
4
Tracks
3
2
1
Time
0
SCAN Device Scheduling Algorithm
• SCAN uses a directional bit to indicate whether the arm
is moving toward the center of the disk or away from it.
7
6
5
4
Tracks
3
2
1
Time
0
Other Variations of SCAN
• N-Step SCAN -- holds all requests until arm starts on way back.
New requests are grouped together for next sweep.
• C-SCAN (Circular SCAN) -- arm picks up requests on its path during
inward sweep.
• When innermost track has been reached returns to outermost
track and starts servicing requests that arrived during last
inward sweep.
• Provides a more uniform wait time.
• C-LOOK (optimization of C-SCAN) --sweep inward stops at last high-
numbered track request, so arm doesn’t move all the way to last
track unless it’s required to do so.
• Arm doesn’t necessarily return to the lowest-numbered track;
it returns only to the lowest-numbered track that’s requested.
LOOK (Elevator Algorithm) : A Variation of SCAN
7
6
5
4
Tracks
3
2
1
Time
0
Look and C-Look
Disk
platters
Disk Characteristics
• Disk arm: moves a comb of disk heads
• Only one disk head is active for reading/writing
Disk heads
Disk
platters
Disk arm
Hard Disk Trivia…
• Aerodynamically designed to fly
• As close to the surface as possible
• No room for air molecules
• Therefore, hard drives are filled with special
inert gas
• If head touches the surface
• Head crash
• Scrapes off magnetic information
Disk Characteristics
Each disk platter is divided into concentric tracks
Disk heads
Disk
platters
Disk arm
Track
Disk Characteristics
A track is further divided into sectors. A sector is the smallest unit of disk
storage
Disk heads
Disk
platters
Sector
Disk arm
Track
Disk Characteristics
A cylinder consists of all tracks with a given disk arm position
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
Disk Characteristics
Cylinders are further divided into zones
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
Zones
Disk Characteristics
Zone-bit recording: zones near the edge of a disk store more information
(higher bandwidth)
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
Zones
More About Hard Drives Than You Ever Want
to Know
• Latency
• Seek time + rotational delay
• Bandwidth
• Bytes transferred / disk access time
Examples of Disk Access Times
• If disk blocks are randomly accessed
• Average disk access time = ~12 msec
• Assume 4-Kbyte blocks
• 4 Kbyte / 12 msec = ~340 Kbyte/sec
• Differences
• Performance (Speed unit : IOPS – Input Output Per
Second)
• Parallelism
Redundant Array of Inexpensive / Independent
Disks (RAID)
• RAID is a set of physical disk drives that is viewed as a single logical
unit by OS.
• RAID assumes several smaller-capacity disk drives preferable to few
large-capacity disk drives because, by distributing data among
several smaller disks, system can simultaneously access requested
data from multiple drives.
• System shows improved I/O performance and improved data
recovery in event of disk failure.
• RAID introduces much-needed concept of redundancy to help
systems recover from hardware failure.
• Also requires more disk drives which increase hardware costs.
Six standard levels of RAID fall into 4
categories. Each offers a unique
combination of advantages.
Anything to discuss ?