0% found this document useful (0 votes)
26 views49 pages

IO Slides

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views49 pages

IO Slides

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Input/Output

1
I/O Hardwares

Some typical device, network, and data base rates 2


Device Controllers
• I/O devices have components:
– mechanical component
– electronic component
• The electronic component is the device
controller
– may be able to handle multiple devices
• Controller's tasks
– convert serial bit stream to block of bytes
– perform error correction as necessary

3
Device Driver Interface

Device Interface

Printer Disk
Driver Driver

Printer Disk
Controller Controller

•Device interface is standard for all the I/O devices and in POSIX compliant systems it consists of
Open(), Close(), Read(), Write(), Seek(), and Control() functions.
•Drivers implement the device interface functions specific to a device

4
I/O Strategies
• I/O with polling
• I/O with interrupts
• DMA I/O

5
I/O With Polling
• CPU is responsible for
– determining if the I/O operation has completed
– Transferring the data between the main memory and the device
controller data registers
• Steps for performing direct I/O with polling (for read operation)
1. Application process requests a read operation
2. The device driver queries the status register to determine if the device is
idle. If the device is busy, the driver waits for it to become idle.
3. The driver stores an input command into the controllers command
register, starting the device
4. The driver repeatedly reads the status register while waiting for the
device to complete the operation
5. The driver copies the contents of the controller’s data registers into the
user’s process space.

6
I/O With Interrupts
• Polling wastes CPU cycles. Interrupts eliminate the need for the
device driver to constantly poll the controller status register
• Instead of polling, the device controller automatically notifies the
device manager when the operation is complete.
• Device manager should have the following parts
– The driver part that initiates the operation
– Device status table
– Interrupt handler
– Device handler

7
Interrupts Revisited

How interrupts happen. Connections between devices and interrupt controller


actually use interrupt lines on the bus rather than dedicated wires

8
I/O With Interrupts
An input operation using interrupts
1. The application process requests a read operation
2. The device driver queries the status register to determine if the
device is idle. If the device is busy, the driver waits for the device to
become idle
3. The device driver stores an input command into the controllers
command register starting the device
4. The device driver saves information regarding the operation that it
began in the device status table. This table contains an entry for each
device in the system. The information saved is the return address of
the original call, and any special parameters for the I/O operation.
5. The device manager invokes the scheduler (so that some other
process can use the CPU) and terminates

9
I/O With Interrupts
5. When the device completes the operation, it interrupts the CPU, and
causes the interrupt handler to run
6. The interrupt handler determines which device caused the interrupt,
and branches to the device handler for that device
7. The device handler retrieves the pending I/O status information from
the device status table
8. The device handler copies the contents of the controller’s data
registers into the user process’s space
9. The device handler returns control to the application process

10
I/O with DMA drregtamgoy

• Used when the hardware has a DMA controller


• DMA controller has access to the system bus independent of the CPU.
• 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 transfer,
and the unit of transfer
– Memory address register specifies where to write or read
– Byte count register specifies the amount read or written

11
Memory-Mapped I/O (1)

• Separate I/O and memory space


• Memory-mapped I/O
• Hybrid
12
Disk Hardware (2)

• Physical geometry of a disk with two zones


• A possible virtual geometry for this disk 13
Disk Formatting (1)

A disk sector

14
Disk Formatting (2)

An illustration of cylinder skew


15
Disk Formatting (3)

• No interleaving
• Single interleaving
• Double interleaving

16
Disk Arm Scheduling Algorithms (1)
• Time required to read or write a disk
block determined by 3 factors
1. Seek time
2. Rotational delay
3. Actual transfer time
• Seek time dominates
• Error checking is done by controllers

17
Disk Arm Scheduling Algorithms

• FCFS: First Come First Served


– Assume that the initial disk arm position is on cylinder 11
(cylinders are numbered starting from 0)
– If the new requests are 1, 36, 16, 34, 9, 12 (these are cylinder
numbers)
– Then total of 10 + 35 + 20 + 18 + 25 +3 = 111 cylinders will be
traversed
• SSF : Shortest Seek First
– What is the total number of cylinders traversed for the same
requests, 1, 36, 16, 34, 9, 12 ?
• The arm motions of SSF is depicted in the next slide

18
Disk Arm Scheduling Algorithms (2)
Initial Pending
position requests

Shortest Seek First (SSF) disk scheduling algorithm

19
SSF
• What could be the disadvantage of SSF?
• Elevator algorithm is proposed to overcome the
disadvantages:
– The direction of the disk arm is important for scheduling decisions
– Disk arm direction going towards higher cylinder numbers is called
UP, and the reverse is called DOWN
– After the current request was processed the next request that is
closest in the direction of the disk arm is processed
– Assuming the disk arm direction is UP, and the requests are :
1,36,16, 34, 9, 12 then what would be the total number of cylinders
traversed?

20
Disk Arm Scheduling Algorithms (3)

The elevator algorithm for scheduling disk requests


21
Error Handling

• Metal oxide coating


• The linear recording density has limits (ex
5000bits/mm)
• High recording density means higher
manufacturing errors

22
Error Handling

• Bad sectors result from manufacturing


defects
• ECC can be used to handle a few defected
bits
• Bigger errors can be handled by
– Controller
– OS

23
Error Handling

• A disk track with a bad sector


• Substituting a spare for the bad sector
• Shifting all the sectors to bypass the bad one
24
Error Handling

• Errors may occur during the normal operation of


the disk which may be
– Transient (dust etc)
– Can be fixed by the ECC
– Repeated errors: spare sectors should be used before the
sector dies completely

25
Error Handling

• OS can handle bad sectors by re-mapping tables


– Read the entire disk to construct a list of bad sectors
– Both allocated and free blocks need to be tested
– Backup system should also consider bad sectors
• Seek errors may also occur if the disk head can not
be positioned in the right track
• The disk head needs to be recalibrated when such
an error occurs

26
RAID
•OSLED : Single Large Expensive Disk
-

• The speed of Mechanic v.s. Electronic components


• Parallelism in CPU proved to be effective
• Why not parallelism in I/O? (by Patterson et.al. 1988)
– RAID (Redundant Array of Inexpensive Disks)
• Adopted by the industry as Redundant Array of
Independent Disks

27
RAID
• G-
RAID is a set of disks with a single RAID controller
• Its aim is to improve the fault tolerance and performance
with a reasonable cost
• The disks in RAID appear as a single disk to the
-
O OS
• There are six different RAID organizations (0…5)
F- – RAID level 0 : Data striping is employed, i.e., the whole disk
consists of strips of size “k-sectors” partitioned into individual disks
in round robin fashion
–-There is no redundant data storage in this approach
– Is this better for requests of larger or smaller chunks of read
requests?
– No performance gain if the requests are one sector at a time!
" – What about reliability?

a
.is

28
O
O -

b b b
by disks

29
RAID
• There are six different RAID organizations (0…5)
&
– RAID level 1: Data striping is used. It also duplicates all the disks.
-

erase

30
back disk
primary disk up
-

÷
•In the above case we have 4 primary disks and 4 backup disks
•Every strip is written twice!
•Either of the two copies could be read!

31
–How do you think the read and write performance is in RAID level 1?
–Is it fault tolerant?

32
–How do you think the read and write performance is in RAID level 1?
–Is it fault tolerant?

•Write performance is the same


•Read performance can be twice as good
•Fault tolerance is excellent
•Recovery is easy, buy a new drive, and replace it with the one that crashed

33
RAID
• There are six different RAID organizations (0…5)
#
– RAID level 2: Works in very small granularity striping with
hamming code for error detection and correction. For example a
byte is divided into 4bit chunks, and 3 parity bits are added to form
a 7 bit word which is partitioned bit by bit to 7 disks. Disk drives
must be synchronized for read and write.

34
"
"
level
bit striping

E –RAID level 2: Works in very small granularity striping with


hamming code for error detection and correction.
–For example a byte is divided into 4bit chunks, and 3 parity bits
are added to form a 7 bit word which is partitioned bit by bit to 7 disks.
-Disk drives must be synchronized for read and write.

O 600

EE Eri
35
RAID

• RAID organizations cont’d (0…5)

8-
– RAID level 3 : simplified version of level 2, where only D checksum
is stored. It can do error detection but not error correction in case
there are random bit errors. What would be the effect of a single
disk crash?
– RAID level 4: use data striping. With a strip of k bytes, an extra
disk drive stores k-byte long parities constructed by performing an
exclusive or on the strips in each disk.
– RAID level 5: It is like RAID level 4, but parity bits are distributed
over the RAID disks to reduce the risk induced by parity disk crash.

36
RAID
• RAID organizations cont’d (0…5)
– RAID level 3 : simplified version of level 2, where only checksum
is stored. It can do error detection but not error correction in case
there are random bit errors. What would be the effect of a single
disk crash?

•Assume that one of the drives crashes, can we do


•Error detection
•Error correction!

37
Disk Hardware (4)

¥
• Raid levels 3 through 5
• Backup and parity drives are shaded 38
o
Stable Storage

• RAID deals with correct reads and fault tolerance


against crashes
• How about writes?
•&Desired Property: atomic write
– When a write is issued, the disk either correctly writes
the data or it does nothing at all (Called Stable Storage)
-

39
Stable Storage

• Following can be handled:


– A written sector can suddenly become unreadable
F-– CPU can fail leading to incorrect data
• Following can not be handled:

*
– Student drops the computer out of the window of a
skyscraper
– Student sets the computer room on fire
– Natural disasters

40
Stable Storage
• Stable storage uses a pair of identical disks with the
corresponding blocks form an error-free block

a-
• Stable write:
– Write the block on drive 1
– Read it back and verify it, if not correct repeat the operation

e
– After n consecutive failures the block is remapped to a spare one
and the operation continues
-

– After the write to drive 1 succeeds, the corresponding block on


drive 2 is written and re-read until it succeeds


– After the stable write completes, the block is successfully written to
both drives
-

41
Stable Storage
• Stable storage uses a pair of identical disks with the
corresponding blocks form an error-free block
• Stable read:
– First read from drive 1
– If the ECC indicates and error, then reread
– If after n iterations, the error occurs, then the corresponding block is
read from drive 2
• Assumption: probability that the same block in both drives
will go bad is practically 0

t ¥/ ÷ e~a* 42
Stable Storage
• Crash recovery
– Scan both disks and compare the corresponding blocks
– If one of them has ECC error, then the good one is written over the
bad one
– If both have ECC good, but they are different, then the block in
drive 1 is written to drive 2.

43
Stable Storage

I :* .
&
Analysis of the influence of crashes on stable writes

44
Clock Hardware

A programmable clock
– Generates a CPU interrupt when the counter is 0
– These are called clock ticks
– Can be programmed to occur very 2 nsecs to 8.6 secs

45
Clock Software
• Clock drivers job:
– Maintain time of day
– Prevent processes from running longer than they
are allowed to
– Accounting CPU usage
– Providing watchdog timers
– etc

46
Clock Software (1)

Three ways to maintain the time of day


47
Simulating multiple virtual clocks
• Maintain a table
• The signal times for all pending timers stored in
the table
• Whenever the time of day is updated, the driver
checks to see if the closest signal has occured

48
Clock Software (2)
Simulating multiple timers with a single clock

Pending signals are for 4203, 4207, 4213, 4215, 4216

49

You might also like