Sei sulla pagina 1di 40

Device Management

Device Management

Sateesh IITR EC-353 2011 1


So far
We have covered
Device Management

Process management,
Memory management, and
file management
Computing is not interesting without I/Os
Device management: the OS component that
manages hardware devices
Provides a uniform interface to access devices
with different physical characteristics
Optimize the performance of individual devices
Sateesh IITR EC-353 2011 2
Device Management Device Management

Hardware Organization
Device Scheduling Policies
Device Drivers

Output Device

Input Device Processor

Sateesh IITR EC-353 2011 3


Device Management Device Manager Must

Know which components are


busy and which are free.
Solved by structuring
interaction between
units Be able to accommodate
requests that come in during
heavy I/O traffic.

Accommodate disparity of
speeds between CPU and I/O
Handled by buffering devices.
records & queueing
requests
Sateesh IITR EC-353 2011 4
Hardware Organization
Categories of I/O Devices
Human readable
Device Management

Used to communicate with the user


Printers
Video display terminals
Display
Keyboard
Mouse
Machine readable
Used to communicate with electronic equipment
Disk and tap drives
Sensors
Controllers
Actuators
Communication
Used to communicate with remote devices
Digital line drivers
Modems
Sateesh IITR EC-353 2011 5
Hardware Organization
A Typical PC Bus Structure
Device Management

Sateesh IITR EC-353 2011 6


Hardware Organization
Differences in I/O Devices
Data rate
Device Management

May be differences of several orders of magnitude between the data


transfer rates
Application
Disk used to store files requires file-management software
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
Complexity of control
Unit of transfer
Data may be transferred as a stream of bytes for a terminal or in larger
blocks for a disk
Data representation
Encoding schemes
Error conditions
Devices respond to errors differently

Sateesh IITR EC-353 2011 7


Hardware Organization
Evolution of the I/O Function
Processor directly controls a peripheral device
Device Management

Controller or I/O module is added


Processor uses programmed I/O without interrupts
Processor does not need to handle details of external devices
Controller or I/O module with interrupts
Processor does not spend time waiting for an I/O operation to
be performed
Direct Memory Access
Blocks of data are moved into memory without involving the
processor
Processor involved at beginning and end only
I/O module is a separate processor
I/O processor
I/O module has its own local memory
Its a computer in its own right
Sateesh IITR EC-353 2011 8
Hardware Organization
Device I/O Ports
Device Management

Sateesh IITR EC-353 2011 9


Hardware Organization
Device Addressing Illustrated
Dedicated range of device addresses in the physical memory
Device Management

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

Primary Primary
memory memory Memory
addresses
Device Device 1
addresses Device 2
Separate device Sateesh IITR EC-353 2011 Memory-mapped I/Os 10
addresses
Hardware Organization
Techniques for Performing I/O
Programmed I/O (Polling)
Device Management

Process is busy-waiting for the operation to complete


Interrupt-driven I/O
I/O command is issued
Processor continues executing instructions
I/O module sends an interrupt when done
Direct Memory Access (DMA)
DMA module controls exchange of data between main
memory and the I/O device
Processor interrupted only after entire block has been
transferred

Sateesh IITR EC-353 2011 11


Device Driver
Concept
software driver is a computer program allowing higher-level computer
programs to interact with a hardware device.
Device Management

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
Device driver provides interface for the following categories of devices
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
Other OS components see block devices and character devices, but not the details
of the devices.
How to effectively utilize the device is the responsibility of the device driver

User level User applications


Various OS components
OS level
Device drivers
Device controllers
Hardware level Sateesh IITR EC-353 2011 12
I/O devices
Device Driver
Disk as An Example Device Hardware Level
Cylinders are further divided into zones
Device Management

Zone-bit recording: zones near the edge of a disk store more information
(higher bandwidth)
Track skew: starting position of each track is slightly skewed
Minimize rotational delay when sequentially transferring bytes across
tracks
Thermo-calibrations: periodically performed to account for changes of disk
radius due to temperature changes
Typically 100 to 1,000 bits are inserted between sectors to account for minor
inaccuracies Disk heads
Disk
platters
Sector
Disk arm
Cylinder

Track
Sateesh IITR EC-353 2011 13
Zones
Device Driver
Disk Controller
Few popular standards (Exercise : Read in More detail)
Device Management

IDE (integrated device electronics)


ATA (AT attachment interface)
SCSI (small computer systems interface)
Differences (Exercise : Read in More detail)

Performance
Parallelism

Sateesh IITR EC-353 2011 14


Device Driver
Disk Device Driver
allowing higher-level computer programs to
Device Management

interact with a disk drive

Major goal: reduce seek time for disk accesses


Schedule disk request to minimize disk arm
movements
Algorithms are written to schedule

Sateesh IITR EC-353 2011 15


Disk Arm Scheduling Policies
First Come First Served (FCFS)
requests are served in the order of arrival
Device Management

+ Fair among requesters


- Poor for accesses to random disk blocks
Request queue: 3, 6, 1, 0, 7
Head start position: 2
Total seek distance: 1 + 3 + 5 + 1 + 7 = 17
7
6
5
4
Tracks
3
2
1
Time
0
Sateesh IITR EC-353 2011 16
Disk Arm Scheduling Policies
Shortest Seek Time First (SSTF)
picks the request that is closest to the current disk arm
Device Management

position
+ Good at reducing seeks
- May result in starvation
Request queue: 3, 6, 1, 0, 7
Head start position: 2
Total seek distance: 1 + 2 + 1 + 6 + 1 = 10
7
6
5
4
Tracks
3
2
1
Sateesh IITR EC-353 2011 Time 17
0
Disk Arm Scheduling Policies
SCAN
takes the closest request in the direction of travel (an example
Device Management

of elevator algorithm)
+ no starvation
- a new request can wait for almost two full scans of the disk
Request queue: 3, 6, 1, 0, 7
Head start position: 2
Total seek distance: 1 + 1 + 3 + 3 + 1 = 9
7
6
5
4
Tracks
3
2
1
Sateesh IITR EC-353 2011 Time 18
0
Disk Arm Scheduling Policies
Circular SCAN (C-SCAN)
disk arm always serves requests by scanning in one direction.
Device Management

Once the arm finishes scanning for one direction


Returns to the 0th track for the next round of scanning
Request queue: 3, 6, 1, 0, 7
Head start position: 2
Total seek distance: 1 + 3 + 1 + 7 + 1 = 13
7
6
5
4
Tracks
3
2
1
Time
0 Sateesh IITR EC-353 2011 19
Look and C-Look
Similar to SCAN and C-SCAN
Device Management

the arm goes only as far as the final request in


each direction, then turns around
Look for a request before continuing to move in a given
direction.

Sateesh IITR EC-353 2011 20


Selecting a Disk-Scheduling Algorithm
SSTF is common and has a natural appeal
Device Management

SCAN and C-SCAN perform better for systems that place a


heavy load on the disk.
Performance depends on the number and types of requests.
Requests for disk service can be influenced by the file-
allocation method.
The disk-scheduling algorithm should be written as a separate
module of the operating system, allowing it to be replaced
with a different algorithm if necessary.
Either SSTF or LOOK is a reasonable choice for the default
algorithm.

Sateesh IITR EC-353 2011 21


Disk Management
Disk Formatting
Low-level formatting (or Physical formatting)
Device Management

Special data structures for sectors


Header, trailer, sector number, error-correction code etc.
Logical formatting
Creation of a file system
Boot Block
Bad blocks
format, chkdsk (windows), sector sparing, sector slipping
Swap-space Management
Virtual Memory (swapping / Paging)
Stable-Storage Implementation
Logs
Tertiary-Storage Structures
Removable Disks
Tapes
Solid State Disks
Holographic Storage
MEMS
RAID Structures
Sateesh IITR EC-353 2011 22
Device Management RAID

Redundant Array of Inexpensive Disks


Techniques
Mirroring
Reliability but expensive
Striping (bit level striping, block level striping, sector level..)
High data transfer rates but not reliable
Levels (combinations)

Sateesh IITR EC-353 2011 23


RAID Levels
RAID Level 0: only striping + no
redundancy
Device Management

RAID Level 1: only mirroring


RAID Level 2: memory-style-error-
correcting codes. Each byte parity bit
(bit striping)
RAID Level 3: Bit-interleaved parity. To
detect sector has been read correctly.
One disk with a particular sector error
parity detects
RAID Level 4: block-interleaved parity.
RAID Level 5: block-interleaved
distributed parity. Ex: 5 disks: (n mod 5) +
1 parity
RAID Level 6: P+Q redundancy scheme.
Stores extra redundant information to
guard against multiple disk failures.
Sateesh IITR EC-353 2011 24
Operating System Issues
Major OS jobs are to manage physical devices
Device Management

and to present a virtual machine abstraction


to applications

For hard disks, the OS provides two


abstraction:
Raw device an array of data blocks.
File system the OS queues and schedules the
interleaved requests from several applications.

Sateesh IITR EC-353 2011 25


Application Interface
Most OSs handle removable disks almost exactly like fixed
Device Management

disks a new cartridge is formatted and an empty file system


is generated on the disk.
Tapes are presented as a raw storage medium, i.e., and
application does not not open a file on the tape, it opens the
whole tape drive as a raw device.
Usually the tape drive is reserved for the exclusive use of that
application.
Since the OS does not provide file system services, the
application must decide how to use the array of blocks.
Since every application makes up its own rules for how to
organize a tape, a tape full of data can generally only be used
by the program that created it.
Sateesh IITR EC-353 2011 26
OS I/O Subsystem Services

Management of the name space for files and devices


Device Management

Access Control to files and devices


Operation Control (ex: modem can not seek() )
File-system space allocation
Device allocation
Buffering, caching, and spooling
I/O scheduling
Device-status monitoring, error handling, and failure
recovery
Device-driver configuration and initialization

Sateesh IITR EC-353 2011 27


I/O Sub-system
Purpose: Abstract, Encapsulate, and Layer
Device-drivers: Encapsulate (hides) controller differences from kernel
Device Management

Device Categories I/O Subsystem Structure


Note: Some specialized Sateesh
devices have
IITR EC-353 unique interfaces and drivers28
2011
Device Management Kernel Data Structures

Kernel maintains system-wide I/O components table


Kernel maintains free and used buffers in complex data structures
Sateesh IITR EC-353 2011 29
Device Management Device-status Table

Sateesh IITR EC-353 2011 30


OS I/O Subsystem Services
Scheduling
Device Management

Buffering (time lag between producer and consumer)


Caching (locality of reference)
Spooling (buffer with no interleaving)
Device Reservation (exclusive allocation and de-allocation)
Error Handling (minor error complete system failure)
I/O protection (accidentally or purposefully)

Sateesh IITR EC-353 2011 31


Abstraction
I/O Subsystem Encapsulation
Layering
Device Management

Interface

Interface

Hardware Abstraction Layer (HAL)

Sateesh IITR EC-353 2011 32


Application Interface
Block devices (include disk drives)
Interface: read, write, seek (random access)
Device Management

Raw I/O or file-system access


DBMS Raw I/O array of blocks access to block devices
Redundancy: double buffering, double locking
If the application performs its own buffering, locking
Compromise either OS or an application (disabling so called feature !)
Memory-mapped byte streams
using virtual memory facilities
Character devices (keyboards, mice, serial ports)
Interface: get, put
Libraries layered on top allow line editing (backspace etc.)

Sateesh IITR EC-353 2011 33


Application Interface
Network devices (Ethernet card)
Interface : socket select() (to manage a set of sockets)
Device Management

Incorporates protocol, flow control, and pipelining


Separates network protocol from network operation
Clocks and Timers (hardware clocks)
Clocks and Timers for
Current Time
Elapsed Time (Programmable Interval Timer)
Trigger an operation X at time T (Programmable Interval Timer)
Example:
Scheduler Preemption (ex: time slice)
Network subsystem cancel all operation during congestion
Disk I/O flushing dirty pages on to disk
Fine tune regular interval interrupts (trigger operations)
Once or repeat
Virtual Clocks for more requests than currently available clocks

Sateesh IITR EC-353 2011 34


System Call Interface
No direct access instructions are Privileged
Device Management

Hence, Protected

Interface:
Functions available to application
programs
Abstract all devices (and files) to a few
interfaces
Make interfaces as similar as possible
Block vs character
Sequential vs direct access
Device driver implements functions
(one entry point per API function)

Kernel can NOT


Accept all user requests
Deny all user requests
Locking
Programmed
Sateesh IITR EC-353 2011 35
Other OS I/O Subsystem Services
Scheduling - Ordering the I/O requests in the per-device queue
Can improve overall performance
Device Management

Fair access to shared devices


Reduce the average waiting time
Caching - fast memory access to recently accessed data
Always just a copy
Significant performance impact
Spooling - hold output for a device
If device can serve only one request at a time
i.e., Printing
Buffering - store data in OS buffers during transfers
To cope with device speed or transfer size mismatches
To maintain copy semantics, and dirty buffers.
Fault processing: Recovery through retry operations, error logs
Miscellaneous: Pipes, FIFOs, packet handling, streams, queues,
mailboxes Sateesh IITR EC-353 2011 36
Blocked read()

Flow of an
Buffer?
I/O Request
Device Management

1. File Open () Unblock

How data transfer


take place

Sateesh IITR EC-353 2011 37


Performance
Potential bottlenecks:
CPU device processing
Device Management

Execute Device Driver code


Schedule Processes
Context switches after
processing interrupts
Copying between OS and
user buffers (load memory
bus)
Routing network traffic

Performance improvements
Reduce context switches
Minimize data copying
Minimize interrupts by using
large transfers, smart
controllers, DMA
Balance CPU, memory, bus,
and I/O contention for highest
throughput

I/O System flow illustrating bottlenecks


Sateesh IITR EC-353 2011 38
Incorporate of new Devices ++ efficient ++ flexible
-- improvements, -- inefficient (overhead of context
debugging, dev. Time, switch, no threading and locking)
Device Management

Where should the device very less flexible


handling code go? ++ efficient
Hardware -- complexity,
Kernel / Device Driver debugging, dev. Time
Application software

Sateesh IITR EC-353 2011 39


Device Management

THANK YOU

Sateesh IITR EC-353 2011 40

Potrebbero piacerti anche