IO Slides
IO Slides
1
I/O Hardwares
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
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
→
11
Memory-Mapped I/O (1)
A disk sector
14
Disk Formatting (2)
• 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
18
Disk Arm Scheduling Algorithms (2)
Initial Pending
position requests
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)
22
Error Handling
23
Error Handling
25
Error Handling
26
RAID
•OSLED : Single Large Expensive Disk
-
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?
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
O 600
EE Eri
35
RAID
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?
37
Disk Hardware (4)
¥
• Raid levels 3 through 5
• Backup and parity drives are shaded 38
o
Stable Storage
39
Stable Storage
*
– 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 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)
48
Clock Software (2)
Simulating multiple timers with a single clock
49