OpSy-03-ch-51
OpSy-03-ch-51
OpSy-03-ch-51
1
I/O Hardware
I/O Hardware
2
Classification of I/O Devices
Classification of I/O Devices
• Block devices
– Information is stored in fixed size blocks
– Block sizes range from 128-1024 bytes
– I/O is done by reading/writing blocks
– Hard disks, floppies, CD ROMS, tapes are in this
category
• Character devices
– I/O is done as characters (ie., no blocking)
– Terminals, printers, mouse, joysticks are in this
category
Ceng 334 - Operating Systems 5-3
3
Device Controllers
Device Controllers
Disk
System bus
Motherboard
4
I/O Techniques
I/O Techniques
• Programmed I/O
• Interrupt-driven I/O
• Direct memory access (DMA)
5
Programmed I/O
Programmed I/O
6
Interrupt-driven I/O
Interrupt-driven I/O
7
DMA
Direct Memory Access (DMA)
• A DMA module controls the exchange of
data between main memory and an I/O
device
• The processor sends a request for the
transfer of a block of data to the DMA
module (block address, memory address
and number of bytes to transfer) and
continues with other work
• DMA module interrupts the processor when
the entire block has been transferred
Ceng 334 - Operating Systems 5-8
8
DMA
DMA (Cont.)
9
Structuring I/O Software
Structuring I/O Software
I/O request I/O reply
10
User-sapece; I/O Software
User-Space I/O Software
11
Device-Independents I/O Software
Device-Independent I/O Software
12
Device-Independents I/O Software
Device-Independent I/O Software
(Cont.)
• Provide device independent block size
– Physical block sizes for different devices may
differ, so we have to provide the same logical
block sizes
• Buffering
• Storage allocation on block devices such as
disks
• Allocating and releasing dedicated devices
such as tapes
Ceng 334 - Operating Systems 5-13
13
Device-Independents I/O Software
Device-Independent I/O Software
(Cont.)
• Error reporting
– When a bad block is encountered, the driver
repeats the I/O request several times and issues
an error message if data can not be recovered
14
Device Drivers
Device Drivers
15
Interrupt Handlers
Interrupt Handlers
16
Disks
Disks
Sector
Track Cylinder
Heads
17
Disk Performance
Disk Performance Parameters
Access time
18
Formulas for Disk Performance
Approximate Formulas for Disk
Performance Parameters
• Seek time (Ts) = m * n + s
where m = a constant depending on the disk drive
n = number of tracks traversed
s = startup time
• Rotational delay (Tr) = 1 / (2*r)
where r is the rotation speed in revolutions per
second
• Transfer time (Tt) = b / (r*N)
where b = number of bytes to be transferred
N = number of bytes on a track
• Average access time (Ta ) = Ts + Tr + Tt
Ceng 334 - Operating Systems 5-19
19
File Stored Contigiously
20
Randomly Stored Files
Randomly Stored
21
Disk Scheduling
Disk Scheduling Policies
• The order in which sectors are read from the
disk has a tremendous effect on I/O
performance)
• Scheduling Algorithms
– FIFO
– SSF (Shortest seek first)
– SCAN (Elevator algorithm)
– C-SCAN (One-way elevator)
– FSCAN
22
FIFO
First in, First out (FIFO)
• Disk driver accepts request one at a time and
carries them in that order
• No starvation
• Example: Requests for 1, 36, 16, 34, 9, 12 when
positioned on cylinder 11 (mean movement = 18.5
cylinders)
0 10 20 30 40
1 9 11 12 16 34 36
23
SSF
Shortest Seek First (SSF)
0 10 20 30 40
1 9 11 12 16 34 36
24
Scan
SCAN (Elevator Algorithm)
• Disk arm moves in one direction, performing all
requests until no more are needed in that direction,
then turns around and comes back
• Same example : mean movement = 10.0 cylinders
0 10 20 30 40
1 9 11 12 16 34 36
25
Scan
SCAN (Cont.)
• Favours
–Tracks nearest to both innermost
and outermost cylinders
–Latest-arriving requests
26
C-Scan
C-SCAN (One-way Elevator)
27
F-Scan
FSCAN
• SSTF, SCAN and C-SCAN may
suffer from "arm stickiness”
(starvation for some requests)
• If multiple new requests keep
arriving for the same track the arm
gets "stuck"
• The solution is to maintain
multiple queues
Ceng 334 - Operating Systems 5-29
28
F-Scan
FSCAN (Cont.)
• Two queues, one being used for the
scan and the other for new requests
during the scan
• When a scan begins, all new requests
are in one of the queues, with the other
being empty
• During the scan, all new requests are
put into the queue that was initially
empty
• Thus, service of new requests is
deferred until all the old requests have
been processed
Ceng 334 - Operating Systems 5-30
29
Common Disk Errors
Common Disk Errors
• Programming error (e.g., request for
nonexistant sector)
– This type of error should not occur if
programming (software development) is
done carefully
– If such an error is encountered, probably
the only thing to do is to terminate the
request and notify the user or
programmer
Ceng 334 - Operating Systems 5-31
30
Common Disk Errors
Common Disk Errors (Cont.)
• Transient checksum error (e.g., usually
caused by dust on the head. Mostly for
floppies)
– The read or write operation is repeated
for a couple of times
– If the operation is not successful the
block is marked as bad (Bad CRC)
– Re-formating may cure the error
Ceng 334 - Operating Systems 5-32
31
Common Disk Errors
Common Disk Errors (Cont.)
32
Common Disk Errors
Common Disk Errors (Cont.)
• Seek error (e.g., the arm is directed to
cylinder 6 but it goes to 7)
– The disk arm is positioned on cylinders
by pulses (one pulse per cylinder). When
the arm reaches its destination the
cylinder number is checked (written
when the drive was formatted). If the arm
is in a wrong position then a seek error
occurs
Ceng 334 - Operating Systems 5-34
33
Common Disk Errors
Common Disk Errors (Cont.)
– Some controllers can correct the seek
error by issuing a RECALIBRATE
command
– This command moves the arm as far out
as it will go to reset the arm on cylinder
0. If this does not solve the problem then
the drive has to be repaired (replaced
with a new one?)
Ceng 334 - Operating Systems 5-35
34
RAID
RAID (Redundant Array of
Inexpensive Disks)
35
RAID 0
RAID 0 Level
36
RAID 1
RAID 1 (Mirroring)
• A file is written on at least two drives
• The other drive becomes a mirror image of
the first drive
• Reading is improved because of two paths
• Writing is slower as the same data has to be
written twice
• Fault tolerance is improved as the failure of
two disks at the same time is low
37
RAID 3
RAID 3
• A file is distributed on several disks as in RAID 0
• An additional drive contains the parity information
which may be used to reconstruct the file if a drive
fails (See “Hamming Codes” for error correction)
• Reading is fast as all drives can transfer data
(portions of the file) independently
• Good for CAD/CAM & signal processing
• Writing is slower since only one disk is used for
parity information (to write parity all requests
must access this drive)
Ceng 334 - Operating Systems 5-39
38
RAID 5
RAID 5
• Similar to RAID 3 but parity is distributed
to all disks
• Fast read and writes
• Suitable for transaction oriented processing
such as on-line banking, hotel reservations
etc.
• Total capacity for a RAID 5 system with N
disks = capacity of one disk * (N-1)
39